Skip to content

Build base on its own #30

Build base on its own

Build base on its own #30

name: DockerPublish
on:
workflow_dispatch:
push:
env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
jobs:
build-base:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: linux/amd64
- os: ubuntu-latest # change this to the native arm runner when Github makes it public
arch: linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.arch }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "COMMIT_TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build base by digest for cache
id: build
uses: docker/build-push-action@v6
env:
SOURCE_DATE_EPOCH: ${{ env.COMMIT_TIMESTAMP }}
with:
platforms: ${{ matrix.platform }}
file: docker/Dockerfile
target: base
cache-from: type=gha
cache-to: type=gha,mode=max
build:
runs-on: ubuntu-latest
needs:
- build-base
strategy:
fail-fast: false
matrix:
flavor:
- minrobot
- gui
steps:
- name: Prepare
run: |
platform=${{ matrix.arch }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "COMMIT_TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
env:
SOURCE_DATE_EPOCH: ${{ env.COMMIT_TIMESTAMP }}
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
# branch event
type=ref,enable=true,prefix=${{ matrix.flavor }}-,event=branch
# tag event
type=ref,enable=true,prefix=${{ matrix.flavor }}-,event=tag
# pull request event
type=ref,enable=true,prefix=${{ matrix.flavor }}-pr-,suffix=,event=pr
# commit sha
type=sha,prefix=${{ matrix.flavor }}-,suffix=,format=short
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
env:
SOURCE_DATE_EPOCH: ${{ env.COMMIT_TIMESTAMP }}
with:
platforms: linux/amd64,linux/arm64
annotations: ${{ steps.meta.outputs.annotations }}
file: docker/Dockerfile
target: ${{ matrix.flavor }}
cache-from: type=gha
tags: ${{ steps.meta.outputs.tags }}