Skip to content

Merge pull request #1339 from sue445/dependabot/go_modules/github.com… #719

Merge pull request #1339 from sue445/dependabot/go_modules/github.com…

Merge pull request #1339 from sue445/dependabot/go_modules/github.com… #719

Workflow file for this run

name: docker-gcp
on:
push:
tags:
- "*"
branches:
- main
# Run builds for any PRs.
pull_request:
types:
- opened
- synchronize
- reopened
paths-ignore:
- "examples/**"
- "img/**"
workflow_dispatch:
env:
# e.g. projects/123456789/locations/global/workloadIdentityPools/github-actions/providers/github-actions
WORKLOAD_IDENTITY_PROVIDER: "projects/270340932667/locations/global/workloadIdentityPools/gitpanda/providers/github-actions"
# e.g. terraform@GCP_PROJECT_ID.iam.gserviceaccount.com
SERVICE_ACCOUNT_EMAIL: "deployer@gitpanda.iam.gserviceaccount.com"
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/gitpanda/gitpanda/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@v1
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: asia-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
id: build
uses: docker/build-push-action@v5
with:
context: .
push: ${{ (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')) || github.event_name == 'workflow_dispatch' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Test image
run: docker run --rm ${IMAGE_ID} -version
env:
IMAGE_ID: ${{ steps.build.outputs.imageid }}
- name: Slack Notification
uses: lazy-actions/slatify@master
if: always()
continue-on-error: true
with:
job_name: '*build_and_push*'
type: ${{ job.status }}
icon_emoji: ":octocat:"
url: ${{ secrets.SLACK_WEBHOOK }}
token: ${{ secrets.GITHUB_TOKEN }}
deploy_to_cloud_run:
needs:
- build_and_push
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' }}
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@v1
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@v1
with:
region: us-central1
metadata: .github/cloud_run-service.yml
- name: Slack Notification
uses: lazy-actions/slatify@master
if: always()
continue-on-error: true
with:
job_name: '*deploy_to_cloud_run*'
type: ${{ job.status }}
icon_emoji: ":octocat:"
url: ${{ secrets.SLACK_WEBHOOK }}
token: ${{ secrets.GITHUB_TOKEN }}