Skip to content

Commit

Permalink
Update docker builder
Browse files Browse the repository at this point in the history
* Update to supported qemu/buildx actions
* Remove cache lines - upstream action should (?) do it for us
* Remove arm arch temporarily (DO NOT MERGE)
  • Loading branch information
mik3y committed Jul 21, 2022
1 parent 9f6b259 commit 46a9463
Showing 1 changed file with 66 additions and 46 deletions.
112 changes: 66 additions & 46 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Docker Build

env:
IMAGE_NAME: kegbot/server

on:
push:
branches:
Expand All @@ -11,10 +14,22 @@ on:
jobs:
build:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000

steps:
-
name: Checkout
uses: actions/checkout@v2

- uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ hashFiles('Dockerfile') }}

-
name: Prepare
id: prepare
Expand All @@ -26,6 +41,7 @@ jobs:
else
echo ::set-output name=version::snapshot
fi
echo ::set-output name=build_archs::linux/amd64
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
# Work around an armv7 -> qemu bug caused during rust compilation. Yeah.. See repo.
Expand All @@ -36,56 +52,60 @@ jobs:
swap_size: 4
swap_location: '/mnt/swapfile'

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host

-
name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
name: Set up docker tag names (local registry)
id: meta_local
uses: docker/metadata-action@v4
with:
version: latest
images: localhost:5000/${{ env.IMAGE_NAME }}

-
name: Available platforms
run: echo ${{ steps.build.outputs.platforms }}
name: Set up public docker tag names (public registry)
id: meta_public
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE_NAME }}

- name: Build and push to local registry
uses: docker/build-push-action@v3
with:
context: .
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
push: true
tags: ${{ steps.meta_local.outputs.tags }}
build-args: |
BUILD_DATE=${{ steps.prepare.outputs.build_date }}
GIT_SHORT_SHA=${GITHUB_SHA::8}
VERSION=${{ steps.prepare.outputs.version }}
platforms: |
linux/amd64
-
name: Login to DockerHub Registry
if: ${{ '${{ secrets.DOCKER_HUB_PASSWORD }}' != '' && '${{ secrets.DOCKER_HUB_USERNAME }}' != '' }}
run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
-
name: Build
if: ${{ '${{ secrets.DOCKER_HUB_PASSWORD }}' != '' && '${{ secrets.DOCKER_HUB_USERNAME }}' != '' }}
run: |
docker buildx build \
--output "type=image,push=false" \
--platform linux/amd64,linux/arm/v7 \
--cache-from=type=registry,ref=kegbot/server \
--cache-to=type=registry,ref=kegbot/server \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "GIT_SHORT_SHA=${GITHUB_SHA::8}" \
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
--tag "kegbot/server:${{ steps.prepare.outputs.version }}" \
--tag "kegbot/server:latest" \
.
-
name: Build (no cache)
if: ${{ '${{ secrets.DOCKER_HUB_PASSWORD }}' == '' || '${{ secrets.DOCKER_HUB_USERNAME }}' != '' }}
run: |
docker buildx build \
--output "type=image,push=false" \
--platform linux/amd64,linux/arm/v7 \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "GIT_SHORT_SHA=${GITHUB_SHA::8}" \
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
.
-
name: Publish
if: ${{ '${{ secrets.DOCKER_HUB_PASSWORD }}' != '' && '${{ secrets.DOCKER_HUB_USERNAME }}' != '' }}
run: |
docker buildx build \
--output "type=image,push=true" \
--platform linux/amd64,linux/arm/v7 \
--cache-from=type=registry,ref=kegbot/server \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "GIT_SHORT_SHA=${GITHUB_SHA::8}" \
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
--tag "kegbot/server:${{ steps.prepare.outputs.version }}" \
--tag "kegbot/server:latest" \
.

# - name: Build and push to public registry
# if: ${{ '${{ secrets.DOCKER_HUB_PASSWORD }}' != '' && '${{ secrets.DOCKER_HUB_USERNAME }}' != '' }}
# uses: docker/build-push-action@v3
# with:
# context: .
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
# push: true
# tags: ${{ steps.meta_public.outputs.tags }}
# build-args: |
# BUILD_DATE=${{ steps.prepare.outputs.build_date }}
# GIT_SHORT_SHA=${GITHUB_SHA::8}
# VERSION=${{ steps.prepare.outputs.version }}
# platforms: |
# linux/amd64

0 comments on commit 46a9463

Please sign in to comment.