diff --git a/Makefile b/Makefile index 33096d3f..426a8a3e 100644 --- a/Makefile +++ b/Makefile @@ -38,10 +38,18 @@ endif DOCKER_TOOLS = docker run \ --rm \ - -v $(shell bash -c "go env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \ - -v $(shell bash -c "go env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \ + -v $(shell bash -c "go env GOCACHE 2>/dev/null || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \ + -v $(shell bash -c "go env GOMODCACHE 2>/dev/null || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \ -v $$(pwd):/build loop-tools +DOCKER_RELEASE_BUILDER = docker run \ + --rm \ + -v $(shell bash -c "go env GOCACHE 2>/dev/null || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \ + -v $(shell bash -c "go env GOMODCACHE 2>/dev/null || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \ + -v $$(pwd):/repo \ + -e LOOPBUILDSYS='$(buildsys)' \ + loop-release-builder + GREEN := "\\033[0;32m" NC := "\\033[0m" define print @@ -71,6 +79,13 @@ install: $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loop $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loopd +# docker-release: Same as release.sh but within a docker container to support +# reproducible builds on any platform. +docker-release: docker-release-builder + @$(call print, "Building release binaries in docker.") + @if [ "$(tag)" = "" ]; then echo "Must specify tag=!"; exit 1; fi + $(DOCKER_RELEASE_BUILDER) bash release.sh $(tag) + rpc: @$(call print, "Compiling protos.") cd ./swapserverrpc; ./gen_protos_docker.sh @@ -131,6 +146,10 @@ docker-tools: @$(call print, "Building tools docker image.") docker build -q -t loop-tools $(TOOLS_DIR) +docker-release-builder: + @$(call print, "Building release builder docker image.") + docker build -q -t loop-release-builder -f release.Dockerfile . + mod-tidy: @$(call print, "Tidying modules.") $(GOMOD) tidy diff --git a/release.Dockerfile b/release.Dockerfile new file mode 100644 index 00000000..a4258893 --- /dev/null +++ b/release.Dockerfile @@ -0,0 +1,23 @@ +FROM golang:1.24.6 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + git ca-certificates zip gpg && rm -rf /var/lib/apt/lists/* + +# Add GPG key of Alex Bosworth to verify release tag signature. +RUN gpg --keyserver keys.openpgp.org \ + --recv-keys DE23E73BFA8A0AD5587D2FCDE80D2F3F311FD87E + +# Mark the repo directory safe for git. User ID may be different inside +# Docker and Git might refuse to work without this setting. +RUN git config --global --add safe.directory /repo +RUN git config --global --add safe.directory /repo/.git + +# Set GO build time environment variables. +ENV GOCACHE=/tmp/build/.cache \ + GOMODCACHE=/tmp/build/.modcache + +# Create directories to which host's Go caches are mounted. +RUN mkdir -p /tmp/build/.cache /tmp/build/.modcache \ + && chmod -R 777 /tmp/build/ + +WORKDIR /repo