|
| 1 | +name: build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +# Environment variables available to all jobs and steps in this workflow |
| 10 | +# NOTE: these aren't really secret, but there aren't non-secret settings |
| 11 | +env: |
| 12 | + RUN_PROJECT: ${{ secrets.RUN_PROJECT }} |
| 13 | + RUN_REGION: ${{ secrets.RUN_REGION }} |
| 14 | + RUN_SERVICE: ${{ secrets.RUN_SERVICE }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + setup-build-deploy: |
| 18 | + name: Setup, Build, and Deploy |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v1 |
| 24 | + |
| 25 | + # Setup gcloud CLI |
| 26 | + - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master |
| 27 | + with: |
| 28 | + version: '275.0.0' |
| 29 | + service_account_email: ${{ secrets.GCP_SA_EMAIL }} |
| 30 | + service_account_key: ${{ secrets.GCP_SA_KEY }} |
| 31 | + |
| 32 | + # Configure gcloud CLI |
| 33 | + - name: gcloud Set up |
| 34 | + run: | |
| 35 | + gcloud config set project ${RUN_PROJECT} |
| 36 | +
|
| 37 | + # Build and push image to Google Container Registry |
| 38 | + - name: Build |
| 39 | + run: | |
| 40 | + docker build \ |
| 41 | + --build-arg COMMIT=${GITHUB_SHA:0:7} \ |
| 42 | + --build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \ |
| 43 | + --tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA . |
| 44 | +
|
| 45 | + - name: GCloud auth to docker |
| 46 | + run: | |
| 47 | + gcloud auth configure-docker |
| 48 | +
|
| 49 | + - name: Push to registry |
| 50 | + run: | |
| 51 | + docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA |
| 52 | +
|
| 53 | + # Deploy image to Cloud Run |
| 54 | + - name: Deploy |
| 55 | + run: | |
| 56 | + gcloud run deploy ${RUN_SERVICE} \ |
| 57 | + --allow-unauthenticated \ |
| 58 | + --image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \ |
| 59 | + --platform managed \ |
| 60 | + --project ${RUN_PROJECT} \ |
| 61 | + --region ${RUN_REGION} |
0 commit comments