83 lines
2.2 KiB
YAML
83 lines
2.2 KiB
YAML
name: Build Docker
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
version:
|
|
required: true
|
|
type: string
|
|
dry_run:
|
|
required: true
|
|
type: boolean
|
|
target:
|
|
required: true
|
|
type: string
|
|
|
|
env:
|
|
DOCKER_IMG: artalk/artalk-go
|
|
|
|
jobs:
|
|
build_publish:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
# https://github.com/docker/metadata-action
|
|
- name: Gen docker meta
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
context: git
|
|
images: |
|
|
${{ env.DOCKER_IMG }}
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=sha
|
|
|
|
# https://github.com/docker/login-action
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
# https://github.com/docker/setup-qemu-action
|
|
- name: Setup QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: ${{ inputs.target }}
|
|
|
|
# https://github.com/docker/setup-buildx-action
|
|
- name: Setup Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ inputs.target }}-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-${{ inputs.target }}-
|
|
|
|
# https://github.com/docker/build-push-action
|
|
- name: Build and Push
|
|
id: build
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
push: ${{ !inputs.dry_run }}
|
|
context: .
|
|
file: ./Dockerfile
|
|
platforms: ${{ inputs.target }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
cache-to: type=local,dest=/tmp/.buildx-cache
|
|
|
|
- name: Print image digest
|
|
run: echo ${{ steps.build.outputs.digest }}
|