Skip to content

added env for api

added env for api #46

Workflow file for this run

name: Deploy .NET API to Google Cloud Run
on:
push:
branches:
- main
workflow_dispatch: # Allows manual triggering
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: "8.0.x"
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Build the .NET project
run: |
dotnet publish ./API/TVR.Bundesliga.API -c Release -o ./out
- name: Configure Docker to use gcloud as a credential helper
run: |
gcloud auth configure-docker
- name: Build Docker image
run: |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/api:latest -f ./API/TVR.Bundesliga.API/Dockerfile ./API
- name: Push Docker image to Google Container Registry
run: |
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/api:latest
- name: Deploy to Google Cloud Run
run: |
gcloud run deploy api \
--image gcr.io/${{ secrets.GCP_PROJECT_ID }}/api:latest \
--platform managed \
--region europe-west1 \
--allow-unauthenticated \
--set-env-vars ASPNETCORE_ENVIRONMENT=${{ secrets.ASPNETCORE_ENVIRONMENT }},\
MONGO_DB_CONNECTION_STRING="${{ secrets.MONGO_DB_CONNECTION_STRING }}",\
MONGO_DB_DATABASE_NAME="${{ secrets.MONGO_DB_DATABASE_NAME }}",\
GOOGLE_PROJECT_NAME=${{ secrets.GOOGLE_PROJECT_NAME }}