Skip to content

Commit

Permalink
Update start.sh
Browse files Browse the repository at this point in the history
added workflows
  • Loading branch information
bufanoc authored Dec 23, 2024
1 parent ad9eb4d commit e03a9ba
Showing 1 changed file with 230 additions and 0 deletions.
230 changes: 230 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,236 @@ main() {
setup_ovn_network
verify_ovn_config

# Create GitHub workflows directory
mkdir -p .github/workflows

# Create frontend workflow
cat > .github/workflows/frontend.yml << 'EOL'
name: Frontend CI
on:
push:
branches: [ main ]
paths:
- 'frontend/**'
- '.github/workflows/frontend.yml'
pull_request:
branches: [ main ]
paths:
- 'frontend/**'
- '.github/workflows/frontend.yml'
jobs:
build:
runs-on: ubuntu-22.04
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint || true
- name: Build
run: npm run build
- name: Run tests
run: npm test || true
EOL

# Create backend workflow
cat > .github/workflows/backend.yml << 'EOL'
name: Backend CI
on:
push:
branches: [ main ]
paths:
- 'backend/**'
- 'requirements.txt'
- '.github/workflows/backend.yml'
pull_request:
branches: [ main ]
paths:
- 'backend/**'
- 'requirements.txt'
- '.github/workflows/backend.yml'
jobs:
test:
runs-on: ubuntu-22.04
services:
ovn:
image: ovn/ovn-controller-vtep
ports:
- 6641:6641
- 6642:6642
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install -r requirements.txt
- name: Run linter
run: |
flake8 backend --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 backend --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
run: |
pytest backend/tests/ || true
EOL

# Create deployment workflow
cat > .github/workflows/deploy.yml << 'EOL'
name: Deploy
on:
push:
branches: [ main ]
tags:
- 'v*'
jobs:
build-and-push:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Frontend
uses: docker/build-push-action@v4
with:
context: frontend
push: true
tags: |
ghcr.io/${{ github.repository }}/frontend:latest
ghcr.io/${{ github.repository }}/frontend:${{ github.sha }}
- name: Build and push Backend
uses: docker/build-push-action@v4
with:
context: .
file: backend/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}/backend:latest
ghcr.io/${{ github.repository }}/backend:${{ github.sha }}
deploy:
needs: build-and-push
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Deploy to production
run: |
echo "Deploying version ${{ github.ref_name }} to production"
# Add your deployment commands here
EOL

# Create Dockerfiles
# Frontend Dockerfile
cat > frontend/Dockerfile << 'EOL'
FROM node:18-alpine as builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
EOL

# Backend Dockerfile
cat > backend/Dockerfile << 'EOL'
FROM python:3.10-slim
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openvswitch-switch \
openvswitch-common \
ovn-central \
ovn-host && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY backend/ ./backend/
EXPOSE 5000
CMD ["python", "backend/app.py", "--host", "0.0.0.0", "--port", "5000"]
EOL

# Create nginx configuration for frontend
cat > frontend/nginx.conf << 'EOL'
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://backend:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
EOL

echo "Installation completed successfully!"

# Ask user if they want to start the application
Expand Down

0 comments on commit e03a9ba

Please sign in to comment.