multi arch support with docker buildx for the arm's race

This commit is contained in:
lanl0rd 2021-06-28 20:26:36 -04:00
parent 68bb6ab654
commit 506b4c202f
2 changed files with 54 additions and 0 deletions

23
Dockerfile.buildx Normal file
View File

@ -0,0 +1,23 @@
FROM --platform=$TARGETPLATFORM golang:1.13-alpine AS builder
LABEL maintainer="joona@kuori.org"
RUN apk add --update gcc musl-dev git
ENV GOPATH /tmp/buildcache
RUN git clone https://github.com/joohoi/acme-dns /tmp/acme-dns
WORKDIR /tmp/acme-dns
RUN CGO_ENABLED=1 go build
FROM --platform=$TARGETPLATFORM alpine:latest
WORKDIR /root/
COPY --from=builder /tmp/acme-dns .
RUN mkdir -p /etc/acme-dns
RUN mkdir -p /var/lib/acme-dns
RUN rm -rf ./config.cfg
RUN apk --no-cache add ca-certificates && update-ca-certificates
VOLUME ["/etc/acme-dns", "/var/lib/acme-dns"]
ENTRYPOINT ["./acme-dns"]
EXPOSE 53 80 443
EXPOSE 53/udp

31
docker-buildx.sh Executable file
View File

@ -0,0 +1,31 @@
# Check buildx:
# docker buildx ls
#
# Should have output like:
# default default running linux/amd64, linux/386, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6
#
# If not, to setup buildx (if you are using docker desktop) and buildx command is there:
# make sure in: $USER/.docker/config.json
# (may not exist), you have: {"experimental": "enabled"}
# If you see "buildx command not recognized":
# export DOCKER_BUILDKIT=1 && docker build --platform=local -o . git://github.com/docker/buildx && mkdir -p ~/.docker/cli-plugins && mv buildx ~/.docker/cli-plugins/docker-buildx
#
# But normally let's say you start a brand new digitalocean droplet for builds, and you just do apt install -y docker.io or use the prebuilt docker, I've had to do the following:
# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && docker buildx rm builder && docker buildx create --name builder --driver docker-container --use && docker buildx inspect --bootstrap
#
#
# Usage (assuming you have buildx, docker 18+):
# ./docker-buildx vX.X.X
version=$1
platforms="linux/arm64,linux/amd64"
echo "Building $version of acme-dns for platfroms: $platforms!"
docker buildx build \
--platform $platforms \
--rm \
--push \
--compress \
-t joohoi/acme-dns:$version \
-f ./Dockerfile.buildx .