Last active
December 15, 2023 14:08
-
-
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
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: 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