Skip to content

Commit

Permalink
Enable multi arch builds
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Oct 15, 2023
1 parent 473ea45 commit 5b64a79
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
name: Build and test the docker image
name: Build docker image

permissions:
contents: read

on: [push]
on:
push:
branches:
- "*"
tags-ignore:
- "*"

jobs:
build-docker-image:
name: Build and test image
build-image:
name: Build the image
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 4
matrix:
platform: ["linux/386", "linux/amd64", "linux/arm/v6", "linux/arm/v7", "linux/arm64/v8", "linux/ppc64le", "linux/s390x"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build docker image
run: make build-alpine
env:
DOCKER_BUILDKIT: 1
PLATFORM: ${{ matrix.platform }}

- name: Test docker image
if: ${{ matrix.platform == 'linux/amd64' }}
run: make test-alpine
33 changes: 22 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ on:
types: [published]

jobs:
publish-docker-image:
environment:
name: "docker-hub"
url: https://hub.docker.com/r/hickorydns/hickory-dns
name: Build and test image and publish the image
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build docker image
run: make build-alpine
- name: Test docker image
run: make test-alpine
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Push docker image
run: make push

- name: Build and push image
run: make docker-build
env:
DOCKER_BUILDKIT: 1
PLATFORM: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
IMAGE_TAG: docker.io/hickorydns/hickory-dns:latest
ACTION: push

- name: Test docker image
run: make docker-test
env:
IMAGE_TAG: docker.io/hickorydns/hickory-dns:latest
28 changes: 19 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
IMAGE_TAG ?= hickorydns/hickory-dns:latest
BUILD_ARGS ?=
# All: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
# Supported by alpine: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
PLATFORM ?= linux/amd64
ACTION ?= load
PROGRESS_MODE ?= plain

## -- helpers for ENVs possibly used in BUILD_ARGS (manual builds), see README
VERSION ?=
Expand All @@ -25,16 +30,21 @@ endif

## -- end

.PHONY: build-alpine test-alpine push
.PHONY: build-alpine test-alpine

build-alpine:
@echo "Build arguments: ${BUILD_ARGS}"
docker build --pull -f ./alpine/Dockerfile ./alpine -t "${IMAGE_TAG}" ${BUILD_ARGS} --build-arg BUILD_DATE="$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")"
# https://github.com/docker/buildx#building
docker buildx build \
--build-arg VCS_REF="$(shell git rev-parse HEAD)" \
--build-arg BUILD_DATE="$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--tag $(IMAGE_TAG) \
--progress $(PROGRESS_MODE) \
--platform $(PLATFORM) \
--pull \
${BUILD_ARGS} \
--$(ACTION) \
./alpine

test-alpine:
IMAGE_TAG="${IMAGE_TAG}" docker-compose -f ./docker-compose.test.yml up --exit-code-from sut --abort-on-container-exit

push:
@echo "Pushing to ${IMAGE_TAG} in 2sec"
@sleep 2
docker push "${IMAGE_TAG}"
IMAGE_TAG="$(IMAGE_TAG)" \
docker-compose -f ./docker-compose.test.yml up --exit-code-from sut --abort-on-container-exit
2 changes: 1 addition & 1 deletion alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG SOURCE_FILE="https://github.com/hickory-dns/hickory-dns/archive/refs/tags/v$
# wget https://github.com/hickory-dns/hickory-dns/archive/refs/tags/v${VERSION}.tar.gz -O - | sha256sum
ARG SOURCE_SHA256="e5158a8e412876768fc3d171ef4b2c3e0d4e99c1a1d082018b93bcda9fb31334"

FROM rust:alpine3.18 as build-env
FROM alpine:3.18 as build-env

ARG VERSION
ARG SOURCE_FILE
Expand Down

0 comments on commit 5b64a79

Please sign in to comment.