Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for credentials #198

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions .github/workflows/cloud-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
CLOUDSDK_CORE_PROJECT: ${{ vars.CLOUDSDK_CORE_PROJECT }}
CLOUDSDK_COMPUTE_REGION: ${{ vars.CLOUDSDK_COMPUTE_REGION }}
IMAGE: ${{ vars.IMAGE }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}

steps:
# Checkout the repository to the GitHub Actions runner
Expand All @@ -54,16 +55,6 @@ jobs:
with:
fetch-depth: 2

- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} # this is the output provider_name from the TF module
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} # this is a SA email configured
export_environment_variables: 'true'

- name: 'Set up Cloud SDK'
uses: google-github-actions/setup-gcloud@v2

- name: Setup env
shell: bash
id: env
Expand Down Expand Up @@ -127,15 +118,31 @@ jobs:
# AUTH_SECRET=AUTH_SECRET:latest
# EINSATZMAPPE_SHEET_ID=EINSATZMAPPE_SHEET_ID:latest,EINSATZMAPPE_SHEET_RANGE=EINSATZMAPPE_SHEET_RANGE:latest

- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
if: ${{ env.workload_identity_provider != '' }}
with:
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }} # this is the output provider_name from the TF module
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} # this is a SA email configured
export_environment_variables: 'true'

- name: 'Set up Cloud SDK'
uses: google-github-actions/setup-gcloud@v2

- id: image
name: Build image
run: |
set -eo pipefail
gcloud auth configure-docker ${RUN_REGION}-docker.pkg.dev --quiet
docker build . --tag ${IMAGE_TAG}
docker push ${IMAGE_TAG}
if [[ -n "${workload_identity_provider}" ]]; then
gcloud auth configure-docker ${RUN_REGION}-docker.pkg.dev --quiet
docker push ${IMAGE_TAG}
else
echo "Skipping push to Cloud run as there are no credentials"
fi
- id: deploy
name: deploy to Cloud Run
if: ${{ env.workload_identity_provider != '' }}
run: |
set -eo pipefail

Expand Down