gcloudignore didn't work when deploying API to Cloud Run using GitHub Actions

This issue has been tracked since 2022-01-04.

TL;DR

Google Cloud Run cannot read .env. staging file when deployed using GitHub Actions, whereas I've included the .env.staging file in .gcloudignore.

This is my .gcloudignore:

.gcloudignore
.git

!.env.staging
!service-account.json

Expected behavior

The .env.staging file should be exist in Cloud Run container and my API should be able to read it.

Observed behavior

My API cannot read the .env.staging file and caused deployment error when using Github Actions
Screenshot from 2022-01-04 14-29-25
Screenshot from 2022-01-04 14-28-39

Action YAML

name: CI/CD to Google Cloud Run

on:
  release:
    types:
      - published

jobs:
  main:
    name: Continous Deployment to Google Cloud Run
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write

    steps:
      - uses: actions/[email protected]

      - id: auth
        name: Authenticate service account
        uses: google-github-actions/[email protected]
        with:
          credentials_json: ${{secrets.SERVICE_ACCOUNT_JSON}}

      - id: gcloud
        name: Setup Google Cloud SDK
        uses: google-github-actions/[email protected]
        with:
          project_id: ${{secrets.GCP_PROJECT_ID}}

      - id: deploy
        name: Deploy API to Google Cloud Run
        run: gcloud builds submit --config deployments/cloudbuild.staging.yaml

Additional information

I don't know it's a bug or not, but when I deployed my API using gcloud command line locally, it worked fine. The error only happen when using Github Actions.

Any solutions?

Thanks.

sethvargo wrote this answer on 2022-01-04

Is .env.staging checked into the source repository?

ajipandean wrote this answer on 2022-01-04

Do you mean "is .env.staging pushed into the source repository?"? No, it isn't.

It ignored by git.

sethvargo wrote this answer on 2022-01-04

Then it wouldn't work with GitHub Actions. GitHub Actions clones the repo from GitHub.

ajipandean wrote this answer on 2022-01-04

Ahh I see. How can I didn't notice that thing :D thanks for that.

Is there any possible solution that I can use so I can implement automatic deployment for my API?

sethvargo wrote this answer on 2022-01-04

You would need to either check that value into source control or, if they values are sensitive, set them in GitHub Secrets.

More Details About Repo
Owner Name google-github-actions
Repo Name setup-gcloud
Full Name google-github-actions/setup-gcloud
Language TypeScript
Created Date 2019-11-05
Updated Date 2023-03-23
Star Count 1505
Watcher Count 65
Fork Count 548
Issue Count 11

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date