Deploy Google Cloud Run #1460
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
on: | |
push: | |
branches: | |
- main | |
- master | |
schedule: | |
- cron: '0 1 * * *' | |
name: Deploy Google Cloud Run | |
jobs: | |
update-data: | |
name: Update dashboard data | |
runs-on: ubuntu-latest | |
container: rocker/verse:4.1.0 | |
env: | |
R_CONFIG_ACTIVE: production | |
GCP_SA_KEY: ${{ secrets.PESKAS_DATAINGESTION_GCS_KEY }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- run: git config --global --add safe.directory /__w/peskas.timor.portal/peskas.timor.portal | |
- name: Update data | |
run: | | |
Rscript -e 'install.packages(c("remotes"))' | |
Rscript -e 'remotes::install_cran(c("config", "googleCloudStorageR", "data.table"), quick = TRUE)' | |
Rscript -e 'source("update_data.R")' | |
Rscript -e 'source("data-raw/generate_translation_pars.R")' | |
- name: Commit changes package data | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
file_pattern: data/* | |
deploy: | |
name: Deploy shiny app | |
needs: update-data | |
runs-on: ubuntu-latest | |
env: | |
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
SERVICE: peskas-timor-shiny | |
REGION: asia-east1 | |
CONTAINER_REGISTRY: asia.gcr.io | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup Cloud SDK | |
uses: google-github-actions/[email protected] | |
with: | |
project_id: ${{ env.PROJECT_ID }} | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
export_default_credentials: true # Set to true to authenticate the Cloud Run action | |
- name: Authorize Docker push | |
run: gcloud auth configure-docker | |
- name: Build and push app container | |
run: |- | |
docker build -t ${{ env.CONTAINER_REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} -f prod.Dockerfile . | |
docker push ${{ env.CONTAINER_REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} | |
- name: Deploy to Cloud Run | |
id: deploy | |
uses: google-github-actions/[email protected] | |
with: | |
service: ${{ env.SERVICE }} | |
image: ${{ env.CONTAINER_REGISTRY }}/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} | |
region: ${{ env.REGION }} | |
flags: >- | |
--cpu=4 | |
--memory=4Gi | |
--concurrency=10 | |
--max-instances=20 | |
--min-instances=2 | |
--timeout=300 | |
--cpu-boost | |
--no-cpu-throttling | |
--session-affinity | |
- name: Show Output | |
run: echo ${{ steps.deploy.outputs.url }} |