diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2da854c..8697c52 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 196a2c2..dbcd5a5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/Makefile b/Makefile index fe8539b..e595ae2 100644 --- a/Makefile +++ b/Makefile @@ -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 ?= @@ -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 diff --git a/alpine/Dockerfile b/alpine/Dockerfile index 1a5e9e6..71f3a48 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -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