Update docker-gcp.yml #12
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: Build and Deploy to Cloud Run | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'R/*' | |
- 'inst/*' | |
- 'Dockerfile' | |
- 'DESCRIPTION' | |
- 'NAMESPACE' | |
- '.github/workflows/docker-gcp.yml' | |
workflow_dispatch: | |
env: | |
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
GCP_REGION: ${{ secrets.GCP_REGION }} | |
GCP_SERVICE_ACCOUNT_CREDENTIALS: ${{ secrets.GCP_SERVICE_ACCOUNT_CREDENTIALS }} | |
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} | |
GCP_GAR_NAME: "demo-rshiny-cloudrun" | |
APP_NAME: "rshinycloudrun" | |
REPOSITORY_NAME: ${{ github.repository }} | |
jobs: | |
deploy: | |
permissions: | |
contents: read | |
packages: write | |
deployments: write | |
id-token: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Google Auth | |
id: auth | |
uses: google-github-actions/auth@v2 | |
with: | |
token_format: 'access_token' | |
credentials_json: ${{ env.GCP_SA_KEY }} | |
- name: Set up Cloud SDK | |
id: setup-cloud-sdk | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ env.GCP_PROJECT_ID }} | |
- name: Verify gcloud CLI | |
run: gcloud info | |
- name: Docker Auth | |
id: docker-auth | |
run: |- | |
gcloud auth configure-docker ${{ env.GCP_REGION }}-docker.pkg.dev | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and Push Container | |
id: build | |
run: |- | |
docker build --build-arg R_CONFIG_ACTIVE=production . --tag $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_GAR_NAME/$APP_NAME:$GITHUB_SHA | |
docker push ${{ env.IMAGE_TAG }} | |
- name: Deploy to Cloud Run | |
id: deploy | |
uses: google-github-actions/deploy-cloudrun@v1 | |
with: | |
service: ${{ env.APP_NAME }} | |
image: $GCP_REGION-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_GAR_NAME/$APP_NAME:$GITHUB_SHA | |
region: ${{ env.GCP_REGION }} | |
platform: managed | |
allow-unauthenticated: true | |
env_vars: | | |
R_CONFIG_ACTIVE=production | |
- name: Output Service URL | |
run: echo ${{ steps.deploy.outputs.url }} |