Skip to content

Publish

Publish #19

name: Publish
on:
# schedule:
# - cron: '44 0 * * *'
workflow_run:
workflows: [ Tests ]
types: [ completed ]
env:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
DEPLOY_OS_LIST: linux darwin
BUILD_GOAMD64_LIST: 1 2 3 4
DEPLOY_ARCH_LIST: amd64 arm64 arm
BUILD_GOARM_LIST: 6 7
DEPLOY_COMMIT_NUMBER: ${{ github.sha }}
DEPLOY_TAG_VALUE: ${{ github.event.workflow_run.head_branch }}
APP_BUILD_TAGS: all
jobs:
build:
if: startsWith(github.event.workflow_run.head_branch, 'v')
runs-on: ubuntu-latest
environment: "docker hub"
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.22
- name: Setup Golang caches
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
- name: Build app
run: make build
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image of the service
id: build-and-push-service
uses: docker/build-push-action@v4
with:
context: .
file: deploy/production/Dockerfile
platforms: linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/amd64/v4,linux/arm64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.IMAGE_NAME }}:${{ github.event.workflow_run.head_branch }},${{ env.IMAGE_NAME }}:latest