Improve run modes #39
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: Application CI/CD | |
on: | |
push: | |
branches: [ "master" ] | |
jobs: | |
tests-n-cs: | |
uses: ./.github/workflows/tests-n-cs.yml | |
docker-image-ar: | |
runs-on: ubuntu-latest | |
needs: tests-n-cs | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
- name: Set up Google Cloud authentication | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
- name: Set up gcloud CLI | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ vars.GCP_PROJECT_ID }} | |
- name: Configure Docker to use Artifact Registry | |
run: gcloud auth configure-docker ${{ vars.GCP_REGION }}-docker.pkg.dev | |
- name: Build Docker image | |
run: docker build . --file Dockerfile --tag app:latest | |
- name: Tag Docker image | |
run: docker tag app:latest ${{ vars.GCP_AR_REPOSITORY }}/app:latest | |
- name: Push Docker image to Artifact Registry | |
run: docker push ${{ vars.GCP_AR_REPOSITORY }}/app:latest | |
cr-service-deploy: | |
runs-on: ubuntu-latest | |
needs: docker-image-ar | |
steps: | |
- name: Check out the repository | |
uses: actions/checkout@v4 | |
- name: Update Cloud Run Service definition | |
run: | | |
sed -i 's|<GCP_PROJECT_NUMBER>|${{ vars.GCP_PROJECT_NUMBER }}|' ./gcp/cloud-run/service.yaml | |
sed -i 's|<GCP_SERVICE_ACCOUNT>|${{ vars.GCP_SERVICE_ACCOUNT }}|' ./gcp/cloud-run/service.yaml | |
sed -i 's|<GCP_CLOUD_RUN_SERVICE>|${{ vars.GCP_CLOUD_RUN_SERVICE }}|' ./gcp/cloud-run/service.yaml | |
sed -i 's|<GCP_REGION>|${{ vars.GCP_REGION }}|' ./gcp/cloud-run/service.yaml | |
sed -i 's|<GCP_VPC>|${{ vars.GCP_VPC }}|' ./gcp/cloud-run/service.yaml | |
sed -i 's|<GCP_VPC_SUBNET>|${{ vars.GCP_VPC_SUBNET }}|' ./gcp/cloud-run/service.yaml | |
sed -i 's|<DOCKER_IMAGE>|${{ vars.GCP_AR_REPOSITORY }}/app:latest|' ./gcp/cloud-run/service.yaml | |
- name: Set up Google Cloud authentication | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
- name: Set up gcloud CLI | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ vars.GCP_PROJECT_ID }} | |
- name: Deploy to Cloud Run | |
run: gcloud run services replace ./gcp/cloud-run/service.yaml --project ${{ vars.GCP_PROJECT_ID }} --region ${{ vars.GCP_REGION }} |