From 30ddfeab38be44b5caeb6822dd617cd6c32416a5 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Sun, 5 Jan 2020 15:12:24 +1100 Subject: [PATCH] Build static Go binary --- .buildkite/pipeline.yml | 2 ++ Dockerfile | 4 ++-- Dockerfile.arm32v7 | 4 ++-- Dockerfile.arm64v8 | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 5999bbc2..f8b6a27c 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -19,6 +19,8 @@ steps: - label: ":docker: Image Builds" command: ".buildkite/steps/buildimages.sh | buildkite-agent pipeline upload" + agents: + build: "true" branches: "master v*" depends_on: - "build" diff --git a/Dockerfile b/Dockerfile index ca5dbceb..47581aa8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,10 +27,10 @@ RUN echo "Write tag ${BUILD_TAG} and commit ${BUILD_COMMIT} in binary." && \ sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -tags netgo -ldflags '-w' -o authelia && cd ../../ +RUN cd cmd/authelia && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && cd ../../ # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o authelia-scripts +RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o authelia-scripts -ldflags '-w -linkmode external -extldflags -static' # ======================================== diff --git a/Dockerfile.arm32v7 b/Dockerfile.arm32v7 index 4d724743..46c9b407 100644 --- a/Dockerfile.arm32v7 +++ b/Dockerfile.arm32v7 @@ -28,10 +28,10 @@ RUN echo "Write tag ${BUILD_TAG} and commit ${BUILD_COMMIT} in binary." && \ sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia && GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -tags netgo -ldflags '-w' -o authelia && cd ../../ +RUN cd cmd/authelia && GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && cd ../../ # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -o authelia-scripts +RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=arm CGO_ENABLED=1 go build -o authelia-scripts -ldflags '-w -linkmode external -extldflags -static' # ======================================== diff --git a/Dockerfile.arm64v8 b/Dockerfile.arm64v8 index ee80a500..11be6dbe 100644 --- a/Dockerfile.arm64v8 +++ b/Dockerfile.arm64v8 @@ -28,10 +28,10 @@ RUN echo "Write tag ${BUILD_TAG} and commit ${BUILD_COMMIT} in binary." && \ sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia && GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -tags netgo -ldflags '-w' -o authelia && cd ../../ +RUN cd cmd/authelia && GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && cd ../../ # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -o authelia-scripts +RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -o authelia-scripts -ldflags '-w -linkmode external -extldflags -static' # ========================================