aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2024-01-20 10:31:58 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2024-01-20 10:31:58 +0100
commitd2580f0a3815c5d5ec452fceac3b2cd34c7d57c0 (patch)
treeb5f4422071de5d5a6302a93f0c74d8c34aec0d3f
parente7045f6b32b0d49976472de84b37f31b2f204142 (diff)
buildx and cross-compilation support
-rw-r--r--.github/workflows/docker.yml1
-rw-r--r--Dockerfile8
-rw-r--r--devel.Dockerfile9
-rw-r--r--doc/docker.md18
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
diff --git a/Dockerfile b/Dockerfile
index 4fc2960..44edb5f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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