Skip to content

Commit f70678f

Browse files
committed
make: add target "docker-release"
"make docker-release tag=..." produces the same binaries regardless on the platform and the installed Go version, because it uses Docker.
1 parent c9e2467 commit f70678f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ endif
3838

3939
DOCKER_TOOLS = docker run \
4040
--rm \
41-
-v $(shell bash -c "go env GOCACHE || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
42-
-v $(shell bash -c "go env GOMODCACHE || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \
41+
-v $(shell bash -c "go env GOCACHE 2>/dev/null || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
42+
-v $(shell bash -c "go env GOMODCACHE 2>/dev/null || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \
4343
-v $$(pwd):/build loop-tools
4444

45+
DOCKER_RELEASE_BUILDER = docker run \
46+
--rm \
47+
-v $(shell bash -c "go env GOCACHE 2>/dev/null || (mkdir -p /tmp/go-cache; echo /tmp/go-cache)"):/tmp/build/.cache \
48+
-v $(shell bash -c "go env GOMODCACHE 2>/dev/null || (mkdir -p /tmp/go-modcache; echo /tmp/go-modcache)"):/tmp/build/.modcache \
49+
-v $$(pwd):/repo \
50+
-e LOOPBUILDSYS='$(buildsys)' \
51+
loop-release-builder
52+
4553
GREEN := "\\033[0;32m"
4654
NC := "\\033[0m"
4755
define print
@@ -71,6 +79,13 @@ install:
7179
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loop
7280
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/loopd
7381

82+
# docker-release: Same as release.sh but within a docker container to support
83+
# reproducible builds on any platform.
84+
docker-release: docker-release-builder
85+
@$(call print, "Building release binaries in docker.")
86+
@if [ "$(tag)" = "" ]; then echo "Must specify tag=<commit_or_tag>!"; exit 1; fi
87+
$(DOCKER_RELEASE_BUILDER) bash release.sh $(tag)
88+
7489
rpc:
7590
@$(call print, "Compiling protos.")
7691
cd ./swapserverrpc; ./gen_protos_docker.sh
@@ -131,6 +146,10 @@ docker-tools:
131146
@$(call print, "Building tools docker image.")
132147
docker build -q -t loop-tools $(TOOLS_DIR)
133148

149+
docker-release-builder:
150+
@$(call print, "Building release builder docker image.")
151+
docker build -q -t loop-release-builder -f release.Dockerfile .
152+
134153
mod-tidy:
135154
@$(call print, "Tidying modules.")
136155
$(GOMOD) tidy

release.Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM golang:1.24.6
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
git ca-certificates zip gpg && rm -rf /var/lib/apt/lists/*
5+
6+
# Add GPG key of Alex Bosworth to verify release tag signature.
7+
RUN gpg --keyserver keys.openpgp.org \
8+
--recv-keys DE23E73BFA8A0AD5587D2FCDE80D2F3F311FD87E
9+
10+
# Mark the repo directory safe for git. User ID may be different inside
11+
# Docker and Git might refuse to work without this setting.
12+
RUN git config --global --add safe.directory /repo
13+
RUN git config --global --add safe.directory /repo/.git
14+
15+
# Set GO build time environment variables.
16+
ENV GOCACHE=/tmp/build/.cache \
17+
GOMODCACHE=/tmp/build/.modcache
18+
19+
# Create directories to which host's Go caches are mounted.
20+
RUN mkdir -p /tmp/build/.cache /tmp/build/.modcache \
21+
&& chmod -R 777 /tmp/build/
22+
23+
WORKDIR /repo

0 commit comments

Comments
 (0)