From 091b05f15505f4b1032eadc1e01f6c1c8a2d6462 Mon Sep 17 00:00:00 2001 From: ohdearaugustin Date: Wed, 6 Jul 2022 21:23:01 +0200 Subject: [PATCH 1/3] Change build os --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9139f09..ad021858 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Builder image -FROM docker.io/golang:1.18.0-bullseye AS build +FROM --platform=$BUILDPLATFORM docker.io/golang:1.18.0-bullseye AS build ARG VERSION=dev ENV GOPATH /go WORKDIR /go/src/headscale @@ -8,8 +8,8 @@ COPY go.mod go.sum /go/src/headscale/ RUN go mod download COPY . . - -RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale +ARG TARGETOS TARGETARCH +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN strip /go/bin/headscale RUN test -e /go/bin/headscale From 34d261179eeb56bd7bb8f0435956ccb14f4238bc Mon Sep 17 00:00:00 2001 From: ohdearaugustin Date: Wed, 6 Jul 2022 23:29:34 +0200 Subject: [PATCH 2/3] Speedup docker container build --- Dockerfile | 3 +-- Dockerfile.alpine | 6 +++--- Dockerfile.debug | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ad021858..33aa5780 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,7 @@ RUN go mod download COPY . . ARG TARGETOS TARGETARCH -RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale -RUN strip /go/bin/headscale +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /go/bin/headscale -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN test -e /go/bin/headscale # Production image diff --git a/Dockerfile.alpine b/Dockerfile.alpine index de683f2d..b8d9e33a 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,5 +1,5 @@ # Builder image -FROM docker.io/golang:1.18.0-alpine AS build +FROM --platform=$BUILDPLATFORM docker.io/golang:1.18.0-alpine AS build ARG VERSION=dev ENV GOPATH /go WORKDIR /go/src/headscale @@ -10,8 +10,8 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale -RUN strip /go/bin/headscale +ARG TARGETOS TARGETARCH +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /go/bin/headscale -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN test -e /go/bin/headscale # Production image diff --git a/Dockerfile.debug b/Dockerfile.debug index 9b1b7c6b..4333e94d 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -1,5 +1,5 @@ # Builder image -FROM docker.io/golang:1.18.0-bullseye AS build +FROM --platform=$BUILDPLATFORM docker.io/golang:1.18.0-bullseye AS build ARG VERSION=dev ENV GOPATH /go WORKDIR /go/src/headscale @@ -9,6 +9,7 @@ RUN go mod download COPY . . +ARG TARGETOS TARGETARCH RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN test -e /go/bin/headscale From 96221cc4f7d980a472281445deae27c0c7aeca55 Mon Sep 17 00:00:00 2001 From: ohdearaugustin Date: Sun, 17 Jul 2022 21:15:35 +0200 Subject: [PATCH 3/3] docs: add bulding container docs --- docs/build-headscale-container.md | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 docs/build-headscale-container.md diff --git a/docs/build-headscale-container.md b/docs/build-headscale-container.md new file mode 100644 index 00000000..b0220167 --- /dev/null +++ b/docs/build-headscale-container.md @@ -0,0 +1,32 @@ +# Build docker from scratch + +The Dockerfiles included in the repository are using the [buildx plugin](https://docs.docker.com/buildx/working-with-buildx/). This plugin is includes in docker newer than Docker-ce CLI 19.03.2. The plugin is used to be able to build different container arches. Building the Dockerfiles without buildx is not possible. + +# Build native + +To build the container on the native arch you can just use: +``` +$ sudo docker buildx build -t headscale:custom-arch . +``` + +For example: This will build a amd64(x86_64) container if your hostsystem is amd64(x86_64). Or a arm64 container on a arm64 hostsystem (raspberry pi4). + +# Build cross platform + +To build a arm64 container on a amd64 hostsystem you could use: +``` +$ sudo docker buildx build --platform linux/arm64 -t headscale:custom-arm64 . + +``` + +**Import: Currently arm32 build are not supported as there is a problem with a library used by headscale. Hopefully this will be fixed soon.** + +# Build multiple arches + +To build multiple archres you could use: + +``` +$ sudo docker buildx create --use +$ sudo docker buildx build --platform linux/amd64,linux/arm64 . + +```