Skip to content

Instantly share code, notes, and snippets.

@kaareloun
Last active December 15, 2023 14:08
Show Gist options
  • Save kaareloun/52139840525b9bfdae3fb1794f2e5346 to your computer and use it in GitHub Desktop.
Save kaareloun/52139840525b9bfdae3fb1794f2e5346 to your computer and use it in GitHub Desktop.
Deploy a node app to Google Cloud Run using Github Actions with github secrets as environment variables
name: Deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
GCP_APP_NAME: my-app-name
GCP_PROJECT_ID: my-project-id-123456
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
env:
IMAGE_NAME: gcr.io/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_APP_NAME }}
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login
uses: 'google-github-actions/auth@v1'
with:
token_format: 'access_token'
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Configure Docker
run: gcloud auth configure-docker --quiet
- name: Build Docker image
run: docker build . -t $IMAGE_NAME
- name: Test Docker image
run: docker run $IMAGE_NAME sh -c "npm run test"
- name: Push Docker image
run: docker push $IMAGE_NAME
- name: Deploy Docker image
run: |
gcloud run deploy ${{ env.GCP_APP_NAME }} \
--image="$IMAGE_NAME" \
--region="europe-west6" \
--platform="managed" \
--allow-unauthenticated \
--set-env-vars="REGULAR_ENV_VALUE=myValue" \
--set-env-vars="SECRET=${{ secrets.SECRET }}" \
--set-env-vars="ANOTHER_SECRET=${{ secrets.ANOTHER_SECRET }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment