Merge pull request #707 from sue445/dependabot/bundler/activesupport-… #296
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: docker-gcp | |
on: | |
push: | |
tags: | |
- "*" | |
branches: | |
- main | |
# Run builds for any PRs. | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
paths-ignore: | |
- "img/**" | |
env: | |
# e.g. projects/123456789/locations/global/workloadIdentityPools/github-actions/providers/github-actions | |
WORKLOAD_IDENTITY_PROVIDER: "projects/410561849225/locations/global/workloadIdentityPools/dockerhub-slack-webhook/providers/github-actions" | |
# e.g. terraform@GCP_PROJECT_ID.iam.gserviceaccount.com | |
SERVICE_ACCOUNT_EMAIL: "[email protected]" | |
permissions: | |
contents: read | |
id-token: write | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
us-docker.pkg.dev/dockerhub-slack-webhook/dockerhub-slack-webhook/app | |
tags: | | |
type=sha,format=long | |
type=edge,branch=main | |
type=ref,event=tag | |
- id: auth | |
name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ env.SERVICE_ACCOUNT_EMAIL }} | |
token_format: access_token | |
- uses: docker/login-action@v3 | |
with: | |
registry: us-docker.pkg.dev | |
username: oauth2accesstoken | |
password: ${{ steps.auth.outputs.access_token }} | |
- name: Login to Artifact Registry | |
run: echo '${{ steps.auth.outputs.access_token }}' | docker login -u oauth2accesstoken --password-stdin https://us-docker.pkg.dev | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Slack Notification | |
uses: act10ns/slack@v2 | |
if: always() | |
continue-on-error: true | |
with: | |
status: ${{ job.status }} | |
webhook-url: ${{ secrets.SLACK_WEBHOOK }} | |
deploy_to_cloud_run: | |
needs: | |
- build_and_push | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
runs-on: ubuntu-latest | |
environment: production | |
concurrency: production | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- id: auth | |
name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ env.SERVICE_ACCOUNT_EMAIL }} | |
- name: Replace __GITHUB_SHA__ in .github/cloud_run-service.yml | |
run: | | |
sed -i "s/__GITHUB_SHA__/${GITHUB_SHA}/g" .github/cloud_run-service.yml | |
grep "docker.pkg.dev" .github/cloud_run-service.yml | |
- id: deploy | |
uses: google-github-actions/deploy-cloudrun@v2 | |
with: | |
region: us-central1 | |
metadata: .github/cloud_run-service.yml | |
- name: Slack Notification | |
uses: act10ns/slack@v2 | |
if: always() | |
continue-on-error: true | |
with: | |
status: ${{ job.status }} | |
webhook-url: ${{ secrets.SLACK_WEBHOOK }} |