diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2024-01-20 10:31:58 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2024-01-20 10:31:58 +0100 |
commit | d2580f0a3815c5d5ec452fceac3b2cd34c7d57c0 (patch) | |
tree | b5f4422071de5d5a6302a93f0c74d8c34aec0d3f | |
parent | e7045f6b32b0d49976472de84b37f31b2f204142 (diff) |
buildx and cross-compilation support
-rw-r--r-- | .github/workflows/docker.yml | 1 | ||||
-rw-r--r-- | Dockerfile | 8 | ||||
-rw-r--r-- | devel.Dockerfile | 9 | ||||
-rw-r--r-- | doc/docker.md | 18 |
4 files changed, 29 insertions, 7 deletions
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 88a7031..3fa067a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -40,3 +40,4 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 @@ -1,9 +1,13 @@ -FROM golang:1.21.4 +FROM --platform=${BUILDPLATFORM} golang:1.21.4 ARG version=latest +ARG BUILDPLATFORM +ARG BUILDARCH +ARG TARGETARCH RUN mkdir /usr/local/mt-multiserver-proxy -RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@${version} +RUN GOARCH=${TARGETARCH} go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/...@${version} +RUN if [ "${TARGETARCH}" = "${BUILDARCH}" ]; then mv /go/bin/mt-* /usr/local/mt-multiserver-proxy/; else mv /go/bin/linux_${TARGETARCH}/mt-* /usr/local/mt-multiserver-proxy/; fi VOLUME ["/usr/local/mt-multiserver-proxy"] diff --git a/devel.Dockerfile b/devel.Dockerfile index 12eaf08..990ff2a 100644 --- a/devel.Dockerfile +++ b/devel.Dockerfile @@ -1,11 +1,16 @@ -FROM golang:1.21.4 +FROM --platform=${BUILDPLATFORM} golang:1.21.4 + +ARG BUILDPLATFORM +ARG BUILDARCH +ARG TARGETARCH COPY . /go/src/github.com/HimbeerserverDE/mt-multiserver-proxy WORKDIR /go/src/github.com/HimbeerserverDE/mt-multiserver-proxy RUN mkdir /usr/local/mt-multiserver-proxy -RUN GOBIN=/usr/local/mt-multiserver-proxy go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/... +RUN GOARCH=${TARGETARCH} go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/... +RUN if [ "${TARGETARCH}" = "${BUILDARCH}" ]; then mv /go/bin/mt-* /usr/local/mt-multiserver-proxy/; else mv /go/bin/linux_${TARGETARCH}/mt-* /usr/local/mt-multiserver-proxy/; fi VOLUME ["/usr/local/mt-multiserver-proxy"] diff --git a/doc/docker.md b/doc/docker.md index 7be7ab1..6af77c5 100644 --- a/doc/docker.md +++ b/doc/docker.md @@ -11,13 +11,15 @@ For example, you can add a `:devel` suffix for development builds, though remember to refer the image using that name in compose files or the `docker run` command. +The images are intended to be built by the default buildx builder. + ### Regular To build an image of the latest commit, run the following command from the repository root: ``` -docker build -t mt-multiserver-proxy . +docker buildx build -t mt-multiserver-proxy --load . ``` This is the version most people will want. @@ -25,7 +27,7 @@ This is the version most people will want. It is also possible to build a specific version into an image: ``` -docker build -t mt-multiserver-proxy --build-arg version=VERSION . +docker buildx build -t mt-multiserver-proxy --load --build-arg version=VERSION . ``` where `VERSION` is a Go pseudo-version. @@ -36,7 +38,17 @@ To build an image of the checked-out commit, run the following command from the repository root: ``` -docker build -t mt-multiserver-proxy -f devel.Dockerfile . +docker buildx build -t mt-multiserver-proxy --load -f devel.Dockerfile . +``` + +### Cross-compilation + +You can add the `--platform linux/ARCH` argument to any of the build commands. + +Example (ARMv8 64-bit): + +``` +docker buildx build --platform linux/arm64 -t mt-multiserver-proxy --load . ``` ## Run |