|
| 1 | +name: 'Continuous Deployment' |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + - release/* |
| 9 | + |
| 10 | +jobs: |
| 11 | + deployment: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + environment: dev |
| 14 | + env: |
| 15 | + branch: main |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Get the branch name |
| 21 | + id: get_branch_name |
| 22 | + run: | |
| 23 | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT |
| 24 | +
|
| 25 | + - name: Set up Python |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: '3.9' |
| 29 | + |
| 30 | + - name: Authenticate to GCP |
| 31 | + uses: 'google-github-actions/auth@v2' |
| 32 | + with: |
| 33 | + credentials_json: '${{ secrets.CD_SA_KEYS }}' |
| 34 | + |
| 35 | + - name: Install dependencies |
| 36 | + run: | |
| 37 | + pip install -r requirements.txt -r requirements-dev.txt |
| 38 | +
|
| 39 | + - name: Run training script |
| 40 | + run: | |
| 41 | + python train.py |
| 42 | +
|
| 43 | + - name: Authenticate Docker to GAR |
| 44 | + uses: docker/login-action@v3 |
| 45 | + with: |
| 46 | + registry: '${{ vars.GCP_REGION }}-docker.pkg.dev' |
| 47 | + username: _json_key |
| 48 | + password: ${{ secrets.CD_SA_KEYS }} |
| 49 | + |
| 50 | + - name: Build and push Docker image |
| 51 | + uses: docker/build-push-action@v6 |
| 52 | + with: |
| 53 | + push: true |
| 54 | + tags: '${{ vars.GAR_REPOSITORY }}/${{ vars.GAR_IMAGE_NAME }}-${{ steps.get_branch_name.outputs.branch }}' |
| 55 | + |
| 56 | + - name: Deploy the service to Cloud Run |
| 57 | + id: 'deploy' |
| 58 | + uses: 'google-github-actions/deploy-cloudrun@v2' |
| 59 | + with: |
| 60 | + service: '${{ vars.GCR_SERVICE_NAME }}-${{ steps.get_branch_name.outputs.branch }}' |
| 61 | + image: '${{ vars.GAR_REPOSITORY }}/${{ vars.GAR_IMAGE_NAME }}-${{ steps.get_branch_name.outputs.branch }}' |
| 62 | + region: '${{ vars.GCP_REGION }}' |
| 63 | + flags: '--allow-unauthenticated' |
| 64 | + |
| 65 | + outputs: |
| 66 | + service_url: ${{ steps.deploy.outputs.url }} |
| 67 | + |
| 68 | + stress_test: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: deployment |
| 71 | + |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: Set up Python |
| 76 | + uses: actions/setup-python@v5 |
| 77 | + with: |
| 78 | + python-version: '3.9' |
| 79 | + |
| 80 | + - name: Install dependencies |
| 81 | + run: | |
| 82 | + pip install -r requirements-test.txt |
| 83 | +
|
| 84 | + - name: Run stress test |
| 85 | + run: | |
| 86 | + make stress-test API_URL=${{ needs.deployment.outputs.service_url }} |
0 commit comments