Publish #66
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: 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 | |
DEPLOY_COMMIT_NUMBER: ${{ github.sha }} | |
DOCKER_DEFAULT_BUILD_GOARM_LIST: 6 7 | |
DEPLOY_TAG_VALUE: ${{ github.event.workflow_run.head_branch }} | |
APP_BUILD_TAGS: pgx,mysql,allstreams,clickhouse | |
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 | |
id: build-and-push | |
uses: docker/build-push-action@v3 | |
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,darwin/amd64,darwin/amd64/v2,darwin/amd64/v3,darwin/amd64/v4,darwin/arm64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ env.IMAGE_NAME }}:${{ github.event.workflow_run.head_branch }},${{ env.IMAGE_NAME }}:latest |