-
-
Save CodeLeom/adc26c1ebd881c46af19f41337005cb6 to your computer and use it in GitHub Desktop.
This action builds, authenticate and deploy an app to two seperate instances depending on the branch a push is made to.
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
runtime: nodejs16 | |
env_variables: | |
JWT_COOKIE_EXPIRE: | |
JWT_EXPIRE: | |
JWT_SECRET: | |
MONGO_URI: | |
NODE_ENV: 'production' #or 'staging' depending on the branch its kept on. |
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: api-deployment | |
on: | |
push: | |
branches: | |
- master | |
- stagging | |
jobs: | |
build-staging: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/stagging' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
cache: 'npm' | |
- name: Install Dependency and Build | |
shell: bash | |
run: | | |
npm ci | |
npm run build | |
- name: Upload artifact for deployment job | |
uses: actions/upload-artifact@v3 | |
with: | |
name: avatar-app-staging | |
path: dist/* | |
build-production: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/master' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 16 | |
cache: 'npm' | |
- name: Install Dependency and Build | |
shell: bash | |
run: | | |
npm ci | |
npm run build | |
- name: Upload artifact for deployment job | |
uses: actions/upload-artifact@v3 | |
with: | |
name: avatar-app-prod | |
path: dist/* | |
deploy-to-staging: | |
runs-on: ubuntu-latest | |
needs: build-staging | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
if: github.ref == 'refs/heads/stagging' | |
steps: | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: avatar-app-staging | |
- uses: 'actions/checkout@v3' | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/auth@v1' | |
with: | |
workload_identity_provider: ${{ secrets.STAGING_WIP }} | |
service_account: ${{ secrets.STAGING_SERVICE_ACCOUNT }} | |
audience: ${{ secrets.STAGING_AUDIENCE }} | |
- id: 'deploy' | |
uses: google-github-actions/deploy-appengine@v1 | |
with: | |
project_id: ${{ secrets.STAGING_PROJECT_ID }} | |
deploy-to-production: | |
runs-on: ubuntu-latest | |
needs: build-production | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
if: github.ref == 'refs/heads/master' | |
steps: | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: avatar-app-prod | |
- uses: 'actions/checkout@v3' | |
- id: 'auth' | |
name: 'Authenticate to Google Cloud' | |
uses: 'google-github-actions/auth@v1' | |
with: | |
workload_identity_provider: ${{ secrets.PROD_WIP }} | |
service_account: ${{ secrets.PROD_SERVICE_ACCOUNT }} | |
audience: ${{ secrets.PROD_AUDIENCE }} | |
- id: 'deploy' | |
uses: google-github-actions/deploy-appengine@v1 | |
with: | |
project_id: ${{ secrets.PROD_PROJECT_ID }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment