added route #41
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 .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 }},\ | |
POSTGRESQL_CONNECTION_STRING="Server=/cloudsql/${{ secrets.CLOUD_SQL_CONNECTION_NAME }};Database=${{ secrets.DB_NAME }};User Id=${{ secrets.DB_USER }};Password=${{ secrets.DB_PASSWORD }};",\ | |
GOOGLE_PROJECT_NAME=${{ secrets.GOOGLE_PROJECT_NAME }} \ | |
--add-cloudsql-instances ${{ secrets.CLOUD_SQL_CONNECTION_NAME }} |