Continuous Deployment #39
This file contains 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: Continuous Deployment | |
on: | |
workflow_run: | |
workflows: "Continuous Integration" | |
types: | |
- completed | |
env: | |
PROJECT_ID: tax-worker | |
GAR_LOCATION: us-west1 | |
SERVICE: tax-worker | |
REGION: us-west1 | |
jobs: | |
on-success: | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Google Auth | |
id: auth | |
uses: 'google-github-actions/auth@v1' | |
with: | |
token_format: 'access_token' | |
workload_identity_provider: '${{secrets._WIF_PROVIDER}}' | |
service_account: '${{secrets._WIF_SERVICE_ACCOUNT}}' | |
- name: Docker Auth | |
id: docker-auth | |
uses: 'docker/login-action@v1' | |
with: | |
username: 'oauth2accesstoken' | |
password: '${{ steps.auth.outputs.access_token }}' | |
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev' | |
- name: Gcloud Configuration | |
run: gcloud config get project | |
- name: Build and Push Container | |
run: |- | |
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ github.sha }}" ./ | |
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ github.sha }}" | |
- name: Deploy to Cloud Run | |
id: deploy | |
uses: google-github-actions/deploy-cloudrun@v0 | |
with: | |
service: ${{ env.SERVICE }} | |
region: ${{ env.REGION }} | |
image: "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ github.sha }}" | |
flags: '--allow-unauthenticated' | |
env: | | |
_PORT=${{vars._PORT}} | |
_NODE_ENV=${{ vars._NODE_ENV }} | |
_JWT_SECRET=${{ secrets._JWT_SECRET }} | |
_MONGO_URI=${{ secrets._MONGO_URI }} | |
_AUTH_TOKEN=${{secrets._AUTH_TOKEN}} | |
- name: Show Output | |
run: echo ${{ steps.deploy.outputs.url }} | |
on-failure: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
steps: | |
- name: Try to fail | |
run: exit 1 |