change with flask framework code #3
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 app | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
checks: 'write' | |
env: | |
PROJECT_ID: profound-coyote-418718 | |
jobs: | |
# <------------------- BUILD IMAGE --------------------> | |
build-image: | |
name: Build Image | |
runs-on: self-hosted | |
outputs: | |
image-name: ${{ steps.build-image.outputs.imageFullName }} | |
image-tag: ${{ steps.build-image.outputs.tags }} | |
branch: ${{ env.GITHUB_REF_SLUG_URL }} | |
steps: | |
# PREP STEPS | |
- name: Checkout the code | |
uses: actions/checkout@v2 | |
- name: Slugify github variables | |
uses: rlespinasse/github-slug-action@v4 | |
- name: Authenticate to GCP (SA Key) | |
id: auth | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.APPLICATION_SA }} | |
export_default_credentials: true | |
# BUILD AND PUSH THE IMAGE | |
- name: Build & Push Image | |
id: build-image | |
uses: mr-smithers-excellent/docker-build-push@v6 | |
with: | |
image: ${{ env.PROJECT_ID }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }} | |
registry: "eu.gcr.io" | |
username: _json_key | |
password: ${{ secrets.APPLICATION_SA }} | |
# - name: Build Docker Image and Push Docker Image to Container Registry GCR | |
# id: build-image | |
# env: | |
# IMAGE_NAME: ${{ env.PROJECT_ID }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }} #create env called IMAGE_NAME consisted of actual name of Docker Image after we build | |
# PROJECT_ID: ${{ env.PROJECT_ID }} | |
# run: |- | |
# docker build -t $IMAGE_NAME:latest . #build the docker image | |
# gcloud auth configure-docker --quiet #authenticate to gcr | |
# docker tag $IMAGE_NAME:latest gcr.io/$IMAGE_NAME:latest | |
# docker push gcr.io/$IMAGE_NAME:latest | |
#echo "image_name=gcr.io/$IMAGE_NAME:latest" >> $GITHUB_OUTPUT | |
# <------------------ DEPLOY APP to GCP -------------------> | |
deploy-app: | |
name: Deploy app | |
needs: build-image | |
runs-on: self-hosted | |
outputs: | |
env_url: ${{ steps.deploy.outputs.url }} | |
environment: | |
name: ${{ needs.build-image.outputs.branch }} | |
url: ${{ steps.deploy.outputs.url }} | |
steps: | |
- name: Slugify github variables | |
uses: rlespinasse/github-slug-action@v4 | |
- name: Authenticate to GCP (SA Key) | |
id: auth | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.APPLICATION_SA }} | |
- name: Deploy to Cloud Run | |
id: deploy | |
run: |- | |
gcloud auth login --brief --cred-file="${{ steps.auth.outputs.credentials_file_path }}" --quiet | |
gcloud run deploy ${{ env.GITHUB_REF_SLUG_URL }}-${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }} \ | |
--port 8080 \ | |
--project ${{ env.PROJECT_ID }}\ | |
--region "europe-west1" \ | |
--image "${{ needs.build-image.outputs.image-name }}:${{ needs.build-image.outputs.image-tag }}" \ | |
--memory "2048Mi" \ | |
--cpu "1" \ | |
--timeout "5m" \ | |
--concurrency "45" \ | |
--min-instances "0" \ | |
--max-instances "1" \ | |
--service-account [email protected] \ | |
--platform managed \ | |
--no-allow-unauthenticated |