Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Merge pull request #536 from janbrasna/python-bump #15

Merge pull request #536 from janbrasna/python-bump

Merge pull request #536 from janbrasna/python-bump #15

name: Build and push a Docker image
on:
push:
branches:
- main
tags:
- '*'
workflow_dispatch:
inputs:
ref:
description: 'ref to be deployed (e.g. "refs/heads/main", "v1.0.0", "2c0472cf")'
type: string
required: true
default: refs/heads/main
env:
APP: moderator
APPLICATION_REPOSITORY: mozilla/mozmoderator
IMAGE_NAME: moderator
GAR_LOCATION: us
GCP_PROJECT_ID: moz-fx-moderator-prod
GAR_REPOSITORY: moderator-prod
REF_ID: ${{ github.ref }}
jobs:
build:
permissions:
contents: read
deployments: write
id-token: write
runs-on: ubuntu-latest
outputs:
image_tag: ${{ env.TAG }}
steps:
- uses: actions/checkout@v4
- name: Create version.json
run: |
# create a version.json per
# https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md
printf '{"commit":"%s","version":"%s","source":"%s","build":"%s"}\n' \
"$GITHUB_SHA" \
"$GITHUB_REF_NAME" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > version.json
- id: checkout_application_repo
name: checkout application repo
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ env.REF_ID }}
- id: stage_image_tag
name: Set Docker Stage image tag for updates of the main branch
if: github.ref == 'refs/heads/main'
run: |
echo TAG="$(git describe --tags --abbrev=7)" >> "$GITHUB_ENV"
# Updates to the main branch are deployed to stage.
- id: prod_image_tag
name: Set Docker image tag to the git tag for tagged builds
if: startsWith(github.ref, 'refs/tags/')
run: |
echo TAG="$(git describe --tags --abbrev=7)" >> "$GITHUB_ENV"
# Version tags are deployed to prod.
- uses: docker/setup-buildx-action@v3
- id: gcp_auth
name: GCP authentication
uses: google-github-actions/auth@v2
with:
token_format: access_token
service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com
workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }}
- id: docker_login
name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.gcp_auth.outputs.access_token }}
- id: build_and_push
name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
tags: |
${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max