Made changes to python backend. Fixing tests. #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy WatchParty Stack | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| # ---------------------------------------------------------------- | |
| # JOB 1: TEST GO BACKEND | |
| # ---------------------------------------------------------------- | |
| test-go: | |
| runs-on: ubuntu-latest | |
| services: | |
| redis: | |
| image: redis | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| cache-dependency-path: backend-go/go.sum | |
| - name: Start Pub/Sub Emulator | |
| run: | | |
| docker run -d -p 8085:8085 gcr.io/google.com/cloudsdktool/cloud-sdk:emulators gcloud beta emulators pubsub start --host-port=0.0.0.0:8085 | |
| sleep 5 # Give it a few seconds to boot up | |
| - name: Run Go Tests | |
| env: | |
| PUBSUB_EMULATOR_HOST: localhost:8085 | |
| GCP_PROJECT_ID: test-project | |
| run: | | |
| cd backend-go | |
| go mod tidy | |
| go test -v -tags=integration ./... | |
| # ---------------------------------------------------------------- | |
| # JOB 2: TEST PYTHON BACKEND | |
| # ---------------------------------------------------------------- | |
| test-python: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres | |
| env: | |
| POSTGRES_DB: watchparty | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| cache-dependency-path: backend-python/requirements.txt | |
| - name: Start Pub/Sub Emulator | |
| run: | | |
| docker run -d -p 8085:8085 gcr.io/google.com/cloudsdktool/cloud-sdk:emulators gcloud beta emulators pubsub start --host-port=0.0.0.0:8085 | |
| sleep 5 | |
| - name: Install dependencies | |
| run: | | |
| cd backend-python | |
| pip install -r requirements.txt | |
| pip install pytest pytest-mock responses | |
| - name: Run Python Tests | |
| env: | |
| DATABASE_URL: postgresql://postgres:postgres@localhost:5432/watchparty | |
| PYTHONPATH: . | |
| PUBSUB_EMULATOR_HOST: localhost:8085 | |
| GCP_PROJECT_ID: test-project | |
| run: | | |
| cd backend-python | |
| pytest tests -v | |
| # ---------------------------------------------------------------- | |
| # JOB 3: DOCKER IMAGES BUILD | |
| # ---------------------------------------------------------------- | |
| docker-build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build Python image | |
| run: docker build -t watchparty-api:ci ./backend-python | |
| - name: Build Go image | |
| run: docker build -t watchparty-ws:ci ./backend-go | |
| # ---------------------------------------------------------------- | |
| # JOB 4: INFRASTRUCTURE SANITY CHECK | |
| # ---------------------------------------------------------------- | |
| infrastructure-check: | |
| needs: [test-go, test-python, docker-build] | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Verify Pub/Sub Configuration | |
| run: | | |
| echo "π Checking Pub/Sub Topic..." | |
| if ! gcloud pubsub topics describe watchparty-events --project=${{ secrets.GCP_PROJECT_ID }} > /dev/null 2>&1; then | |
| echo "β ERROR: Topic 'watchparty-events' not found!" | |
| exit 1 | |
| fi | |
| echo "π Checking Pub/Sub Subscription..." | |
| if ! gcloud pubsub subscriptions describe python-backend-sub --project=${{ secrets.GCP_PROJECT_ID }} > /dev/null 2>&1; then | |
| echo "β ERROR: Subscription 'python-backend-sub' not found!" | |
| exit 1 | |
| fi | |
| echo "β Infrastructure verified." | |
| # ---------------------------------------------------------------- | |
| # JOB 5: DEPLOY BACKENDS (Requires Tests & Infra Check) | |
| # ---------------------------------------------------------------- | |
| deploy-backends: | |
| needs: infrastructure-check | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| outputs: | |
| python_url: ${{ steps.deploy-python.outputs.url }} | |
| go_url: ${{ steps.deploy-go.outputs.url }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Set up Cloud SDK | |
| uses: google-github-actions/setup-gcloud@v2 | |
| # Authenticate Docker to push to Google Artifact Registry | |
| - name: Configure Docker for Artifact Registry | |
| run: | | |
| gcloud auth configure-docker us-central1-docker.pkg.dev | |
| # --------------------------------------------------- | |
| # π FAST DEPLOY: PYTHON API | |
| # --------------------------------------------------- | |
| - name: Build and Push Python Image | |
| run: | | |
| cd backend-python | |
| docker build -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/watchparty-repo/watchparty-api:latest . | |
| docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/watchparty-repo/watchparty-api:latest | |
| - name: Deploy Python to Cloud Run | |
| id: deploy-python | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: watchparty-api | |
| region: us-central1 | |
| image: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/watchparty-repo/watchparty-api:latest | |
| flags: | | |
| --port=8080 | |
| env_vars: | | |
| DATABASE_URL=${{ secrets.DATABASE_URL }} | |
| JWT_SECRET=${{ secrets.JWT_SECRET }} | |
| GCP_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }} | |
| GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} | |
| # --------------------------------------------------- | |
| # π FAST DEPLOY: GO WEBSOCKET | |
| # --------------------------------------------------- | |
| - name: Build and Push Go Image | |
| run: | | |
| cd backend-go | |
| docker build -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/watchparty-repo/watchparty-ws:latest . | |
| docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/watchparty-repo/watchparty-ws:latest | |
| - name: Deploy Go to Cloud Run | |
| id: deploy-go | |
| uses: google-github-actions/deploy-cloudrun@v2 | |
| with: | |
| service: watchparty-ws | |
| region: us-central1 | |
| image: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/watchparty-repo/watchparty-ws:latest | |
| flags: | | |
| --timeout=3600 | |
| env_vars: | | |
| REDIS_ADDR=${{ secrets.REDIS_ADDR }} | |
| JWT_SECRET=${{ secrets.JWT_SECRET }} | |
| GCP_PROJECT_ID=${{ secrets.GCP_PROJECT_ID }} | |
| # ---------------------------------------------------------------- | |
| # JOB 6: DEPLOY FRONTEND | |
| # ---------------------------------------------------------------- | |
| deploy-frontend: | |
| needs: deploy-backends | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build React | |
| run: | | |
| cd frontend/wpfe | |
| echo "VITE_API_URL=${{ needs.deploy-backends.outputs.python_url }}" > .env | |
| echo "VITE_WS_URL=${{ needs.deploy-backends.outputs.go_url }}" | sed 's/https/wss/' >> .env | |
| npm install && npm run build | |
| - name: Firebase Deploy | |
| env: | |
| FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} | |
| run: | | |
| npm install -g firebase-tools | |
| cd frontend/wpfe | |
| firebase deploy --only hosting --project ${{ secrets.GCP_PROJECT_ID }} --token "$FIREBASE_TOKEN" |