|
| 1 | +name: AutoGPT Platform - Build, Push, and Deploy Prod Environment |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: 'read' |
| 9 | + id-token: 'write' |
| 10 | + |
| 11 | +env: |
| 12 | + PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} |
| 13 | + GKE_CLUSTER: prod-gke-cluster |
| 14 | + GKE_ZONE: us-central1-a |
| 15 | + NAMESPACE: prod-agpt |
| 16 | + |
| 17 | +jobs: |
| 18 | + migrate: |
| 19 | + environment: production |
| 20 | + name: Run migrations for AutoGPT Platform |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v2 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v4 |
| 29 | + with: |
| 30 | + python-version: '3.11' |
| 31 | + |
| 32 | + - name: Install Python dependencies |
| 33 | + run: | |
| 34 | + python -m pip install --upgrade pip |
| 35 | + pip install prisma |
| 36 | +
|
| 37 | + - name: Run Backend Migrations |
| 38 | + working-directory: ./autogpt_platform/backend |
| 39 | + run: | |
| 40 | + python -m prisma migrate deploy |
| 41 | + env: |
| 42 | + DATABASE_URL: ${{ secrets.BACKEND_DATABASE_URL }} |
| 43 | + |
| 44 | + - name: Run Market Migrations |
| 45 | + working-directory: ./autogpt_platform/market |
| 46 | + run: | |
| 47 | + python -m prisma migrate deploy |
| 48 | + env: |
| 49 | + DATABASE_URL: ${{ secrets.MARKET_DATABASE_URL }} |
| 50 | + |
| 51 | + build-push-deploy: |
| 52 | + environment: production |
| 53 | + name: Build, Push, and Deploy |
| 54 | + runs-on: ubuntu-latest |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v2 |
| 59 | + with: |
| 60 | + fetch-depth: 0 |
| 61 | + |
| 62 | + - id: 'auth' |
| 63 | + uses: 'google-github-actions/auth@v1' |
| 64 | + with: |
| 65 | + workload_identity_provider: 'projects/638488734936/locations/global/workloadIdentityPools/prod-pool/providers/github' |
| 66 | + service_account: 'prod-github-actions-sa@agpt-prod.iam.gserviceaccount.com' |
| 67 | + token_format: 'access_token' |
| 68 | + create_credentials_file: true |
| 69 | + |
| 70 | + - name: 'Set up Cloud SDK' |
| 71 | + uses: 'google-github-actions/setup-gcloud@v1' |
| 72 | + |
| 73 | + - name: 'Configure Docker' |
| 74 | + run: | |
| 75 | + gcloud auth configure-docker us-east1-docker.pkg.dev |
| 76 | +
|
| 77 | + - name: Set up Docker Buildx |
| 78 | + uses: docker/setup-buildx-action@v1 |
| 79 | + |
| 80 | + - name: Cache Docker layers |
| 81 | + uses: actions/cache@v2 |
| 82 | + with: |
| 83 | + path: /tmp/.buildx-cache |
| 84 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 85 | + restore-keys: | |
| 86 | + ${{ runner.os }}-buildx- |
| 87 | +
|
| 88 | + - name: Check for changes |
| 89 | + id: check_changes |
| 90 | + run: | |
| 91 | + git fetch origin master |
| 92 | + BACKEND_CHANGED=$(git diff --name-only origin/master HEAD | grep "^autogpt_platform/backend/" && echo "true" || echo "false") |
| 93 | + FRONTEND_CHANGED=$(git diff --name-only origin/master HEAD | grep "^autogpt_platform/frontend/" && echo "true" || echo "false") |
| 94 | + MARKET_CHANGED=$(git diff --name-only origin/master HEAD | grep "^autogpt_platform/market/" && echo "true" || echo "false") |
| 95 | + echo "backend_changed=$BACKEND_CHANGED" >> $GITHUB_OUTPUT |
| 96 | + echo "frontend_changed=$FRONTEND_CHANGED" >> $GITHUB_OUTPUT |
| 97 | + echo "market_changed=$MARKET_CHANGED" >> $GITHUB_OUTPUT |
| 98 | +
|
| 99 | + - name: Get GKE credentials |
| 100 | + uses: 'google-github-actions/get-gke-credentials@v1' |
| 101 | + with: |
| 102 | + cluster_name: ${{ env.GKE_CLUSTER }} |
| 103 | + location: ${{ env.GKE_ZONE }} |
| 104 | + |
| 105 | + - name: Build and Push Backend |
| 106 | + if: steps.check_changes.outputs.backend_changed == 'true' |
| 107 | + uses: docker/build-push-action@v2 |
| 108 | + with: |
| 109 | + context: . |
| 110 | + file: ./autogpt_platform/backend/Dockerfile |
| 111 | + push: true |
| 112 | + tags: us-east1-docker.pkg.dev/agpt-prod/agpt-backend-prod/agpt-backend-prod:${{ github.sha }} |
| 113 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 114 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 115 | + |
| 116 | + - name: Build and Push Frontend |
| 117 | + if: steps.check_changes.outputs.frontend_changed == 'true' |
| 118 | + uses: docker/build-push-action@v2 |
| 119 | + with: |
| 120 | + context: . |
| 121 | + file: ./autogpt_platform/frontend/Dockerfile |
| 122 | + push: true |
| 123 | + tags: us-east1-docker.pkg.dev/agpt-prod/agpt-frontend-prod/agpt-frontend-prod:${{ github.sha }} |
| 124 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 125 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 126 | + |
| 127 | + - name: Build and Push Market |
| 128 | + if: steps.check_changes.outputs.market_changed == 'true' |
| 129 | + uses: docker/build-push-action@v2 |
| 130 | + with: |
| 131 | + context: . |
| 132 | + file: ./autogpt_platform/market/Dockerfile |
| 133 | + push: true |
| 134 | + tags: us-east1-docker.pkg.dev/agpt-prod/agpt-market-prod/agpt-market-prod:${{ github.sha }} |
| 135 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 136 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 137 | + |
| 138 | + - name: Move cache |
| 139 | + run: | |
| 140 | + rm -rf /tmp/.buildx-cache |
| 141 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 142 | +
|
| 143 | + - name: Set up Helm |
| 144 | + uses: azure/setup-helm@v1 |
| 145 | + with: |
| 146 | + version: v3.4.0 |
| 147 | + |
| 148 | + - name: Deploy Backend |
| 149 | + if: steps.check_changes.outputs.backend_changed == 'true' |
| 150 | + run: | |
| 151 | + helm upgrade autogpt-server ./autogpt-server \ |
| 152 | + --namespace ${{ env.NAMESPACE }} \ |
| 153 | + -f autogpt-server/values.yaml \ |
| 154 | + -f autogpt-server/values.prod.yaml \ |
| 155 | + --set image.tag=${{ github.sha }} |
| 156 | +
|
| 157 | + - name: Deploy Websocket |
| 158 | + if: steps.check_changes.outputs.backend_changed == 'true' |
| 159 | + run: | |
| 160 | + helm upgrade autogpt-websocket-server ./autogpt-websocket-server \ |
| 161 | + --namespace ${{ env.NAMESPACE }} \ |
| 162 | + -f autogpt-websocket-server/values.yaml \ |
| 163 | + -f autogpt-websocket-server/values.prod.yaml \ |
| 164 | + --set image.tag=${{ github.sha }} |
| 165 | +
|
| 166 | + - name: Deploy Market |
| 167 | + if: steps.check_changes.outputs.market_changed == 'true' |
| 168 | + run: | |
| 169 | + helm upgrade autogpt-market ./autogpt-market \ |
| 170 | + --namespace ${{ env.NAMESPACE }} \ |
| 171 | + -f autogpt-market/values.yaml \ |
| 172 | + -f autogpt-market/values.prod.yaml \ |
| 173 | + --set image.tag=${{ github.sha }} |
| 174 | +
|
| 175 | + - name: Deploy Frontend |
| 176 | + if: steps.check_changes.outputs.frontend_changed == 'true' |
| 177 | + run: | |
| 178 | + helm upgrade autogpt-builder ./autogpt-builder \ |
| 179 | + --namespace ${{ env.NAMESPACE }} \ |
| 180 | + -f autogpt-builder/values.yaml \ |
| 181 | + -f autogpt-builder/values.prod.yaml \ |
| 182 | + --set image.tag=${{ github.sha }} |
0 commit comments