Update deploy workflow to use env_int.env for int branch

This commit is contained in:
Stephan Schellworth 2026-01-13 15:49:14 +01:00
parent f3b83a73f8
commit 500442a40a

View file

@ -11,7 +11,12 @@
# 2. Create secret "CONFIG_KEY" in Secret Manager with your master key # 2. Create secret "CONFIG_KEY" in Secret Manager with your master key
# 3. Grant the service account access to Secret Manager secrets # 3. Grant the service account access to Secret Manager secrets
# 4. Create Cloud SQL instance (if not exists) # 4. Create Cloud SQL instance (if not exists)
# 5. Create env_gcp.env file with your configuration # 5. Create env_prod.env and env_int.env files with your configuration
#
# Environment Selection:
# - Push to 'main' branch → uses env_prod.env (production)
# - Push to 'int' branch → uses env_int.env (integration)
# - Manual dispatch → select environment (prod/int) to use corresponding env file
name: Deploy Gateway to Google Cloud Run name: Deploy Gateway to Google Cloud Run
@ -19,6 +24,7 @@ on:
push: push:
branches: branches:
- main - main
- int
paths: paths:
- 'gateway/**' - 'gateway/**'
workflow_dispatch: workflow_dispatch:
@ -34,9 +40,7 @@ on:
env: env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SERVICE_NAME: gateway-prod
REGION: europe-west6 # Zurich region REGION: europe-west6 # Zurich region
ENV_FILE: env_gcp.env
jobs: jobs:
deploy: deploy:
@ -49,6 +53,23 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Determine environment
id: env
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
ENV_TYPE="${{ github.event.inputs.environment }}"
elif [ "${{ github.ref }}" == "refs/heads/int" ]; then
ENV_TYPE="int"
else
ENV_TYPE="prod"
fi
echo "env_type=$ENV_TYPE" >> $GITHUB_OUTPUT
echo "service_name=gateway-$ENV_TYPE" >> $GITHUB_OUTPUT
echo "env_file=env_${ENV_TYPE}.env" >> $GITHUB_OUTPUT
echo "Determined environment: $ENV_TYPE"
echo "Service name: gateway-$ENV_TYPE"
echo "Env file: env_${ENV_TYPE}.env"
- name: Authenticate to Google Cloud - name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2 uses: google-github-actions/auth@v2
with: with:
@ -64,13 +85,15 @@ jobs:
run: | run: |
gcloud auth configure-docker gcloud auth configure-docker
- name: Set productive environment - name: Set environment file
run: | run: |
cd gateway cd gateway
if [ -f "${{ env.ENV_FILE }}" ]; then ENV_FILE="${{ steps.env.outputs.env_file }}"
cp ${{ env.ENV_FILE }} .env if [ -f "$ENV_FILE" ]; then
echo "Using $ENV_FILE"
cp "$ENV_FILE" .env
else else
echo "Warning: ${{ env.ENV_FILE }} not found, using env_prod.env as fallback" echo "Warning: $ENV_FILE not found, using env_prod.env as fallback"
cp env_prod.env .env cp env_prod.env .env
fi fi
# Clean up other env files (optional, for security) # Clean up other env files (optional, for security)
@ -81,20 +104,23 @@ jobs:
run: | run: |
# Build container image using Cloud Build # Build container image using Cloud Build
# If Dockerfile exists, it will be used; otherwise Cloud Buildpacks will be used # If Dockerfile exists, it will be used; otherwise Cloud Buildpacks will be used
SERVICE_NAME="${{ steps.env.outputs.service_name }}"
gcloud builds submit \ gcloud builds submit \
--tag gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }} \ --tag gcr.io/${{ env.PROJECT_ID }}/$SERVICE_NAME:${{ github.sha }} \
--tag gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:latest \ --tag gcr.io/${{ env.PROJECT_ID }}/$SERVICE_NAME:latest \
--project ${{ env.PROJECT_ID }} --project ${{ env.PROJECT_ID }}
- name: Deploy to Cloud Run - name: Deploy to Cloud Run
run: | run: |
gcloud run deploy ${{ env.SERVICE_NAME }} \ SERVICE_NAME="${{ steps.env.outputs.service_name }}"
--image gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ github.sha }} \ ENV_TYPE="${{ steps.env.outputs.env_type }}"
gcloud run deploy $SERVICE_NAME \
--image gcr.io/${{ env.PROJECT_ID }}/$SERVICE_NAME:${{ github.sha }} \
--region ${{ env.REGION }} \ --region ${{ env.REGION }} \
--platform managed \ --platform managed \
--allow-unauthenticated \ --allow-unauthenticated \
--project ${{ env.PROJECT_ID }} \ --project ${{ env.PROJECT_ID }} \
--set-env-vars "APP_ENV_TYPE=prod" \ --set-env-vars "APP_ENV_TYPE=$ENV_TYPE" \
--set-secrets "CONFIG_KEY=CONFIG_KEY:latest" \ --set-secrets "CONFIG_KEY=CONFIG_KEY:latest" \
--memory 2Gi \ --memory 2Gi \
--cpu 2 \ --cpu 2 \
@ -107,7 +133,8 @@ jobs:
- name: Get service URL - name: Get service URL
id: service-url id: service-url
run: | run: |
SERVICE_URL=$(gcloud run services describe ${{ env.SERVICE_NAME }} \ SERVICE_NAME="${{ steps.env.outputs.service_name }}"
SERVICE_URL=$(gcloud run services describe $SERVICE_NAME \
--region ${{ env.REGION }} \ --region ${{ env.REGION }} \
--project ${{ env.PROJECT_ID }} \ --project ${{ env.PROJECT_ID }} \
--format 'value(status.url)') --format 'value(status.url)')