Skip to content

Commit 9f8f4e6

Browse files
authored
Merge pull request #1007 from starius/docker-release
Docker release
2 parents c9e2467 + aec03c1 commit 9f8f4e6

File tree

5 files changed

+371
-36
lines changed

5 files changed

+371
-36
lines changed

Makefile

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ 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-
GREEN := "\\033[0;32m"
46-
NC := "\\033[0m"
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+
53+
GREEN=\033[0;32m
54+
NC=\033[0m
4755
define print
48-
echo $(GREEN)$1$(NC)
56+
@printf '%b%s%b\n' '${GREEN}' $1 '${NC}'
4957
endef
5058

5159
# ============
@@ -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

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ git clone https://github.com/lightninglabs/loop.git
125125
cd loop/cmd
126126
go install ./...
127127
```
128+
129+
## Reproducible builds
130+
131+
If you want to build release files yourself, follow
132+
[the guide](./docs/release.md).

docs/release.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Reproducible Builds
2+
3+
## Building with Docker
4+
5+
To create a Loop release with binaries that are identical to an official
6+
release, run the following command (available since release `v0.31.3-beta`):
7+
8+
```bash
9+
make docker-release tag=<tag-of-release>
10+
```
11+
12+
This command will create a directory named `loop-<tag-of-release>` containing
13+
the source archive, vendored dependencies, and the built binaries packaged in
14+
`.tar.gz` or `.zip` format. It also creates a manifest file with `SHA-256`
15+
checksums for all release files.
16+
17+
For example:
18+
19+
```bash
20+
make docker-release tag=v0.31.3-beta
21+
```
22+
23+
This will create the release artifacts in the `loop-v0.31.3-beta` directory.
24+
25+
If you want to build from an untagged commit, first check it out, then use the
26+
output of `git describe --abbrev=10` as the tag:
27+
28+
```bash
29+
git describe --abbrev=10
30+
# v0.31.2-beta-135-g35d0fa26ac
31+
32+
make docker-release tag=v0.31.2-beta-135-g35d0fa26ac
33+
```
34+
35+
You can filter the target platforms to speed up the build process. For example,
36+
to build only for `linux-amd64`:
37+
38+
```bash
39+
make docker-release buildsys=linux-amd64 tag=v0.31.3-beta
40+
```
41+
42+
Or for multiple platforms:
43+
44+
```bash
45+
make docker-release buildsys='linux-amd64 windows-amd64' tag=v0.31.3-beta
46+
```
47+
48+
Note: inside Docker the current directory is mapped as `/repo` and it might
49+
mention `/repo` as parts of file paths.
50+
51+
## Building on the Host
52+
53+
You can also build a release on your host system without Docker. You will need
54+
to install the Go version specified in the `go.mod` file, as well as a few
55+
other tools:
56+
57+
```bash
58+
sudo apt-get install build-essential git make zip perl gpg
59+
```
60+
61+
You can [download](https://go.dev/dl/) and unpack Go somewhere and set variable
62+
`GO_CMD=/path/to/go` (path to Go binary of the needed version).
63+
64+
If you already have another Go version, you can install the Go version needed
65+
for a release using the following commands:
66+
67+
```bash
68+
$ go version
69+
go version go1.25.0 linux/amd64
70+
$ go install golang.org/dl/go1.24.6@latest
71+
$ go1.24.6 download
72+
Unpacking /home/user/sdk/go1.24.6/go1.24.6.linux-amd64.tar.gz ...
73+
Success. You may now run 'go1.24.6'
74+
$ go1.24.6 version
75+
go version go1.24.6 linux/amd64
76+
77+
$ GO_CMD=/home/user/go/bin/go1.24.6 ./release.sh v0.31.3
78+
```
79+
80+
On MacOS, you will need to install GNU tar and GNU gzip, which can be done with
81+
`brew`:
82+
83+
```bash
84+
brew install gnu-tar gzip
85+
```
86+
87+
Add GPG key of Alex Bosworth to verify release tag signature:
88+
```bash
89+
gpg --keyserver keys.openpgp.org --recv-keys DE23E73BFA8A0AD5587D2FCDE80D2F3F311FD87E
90+
```
91+
92+
Then, run the `release.sh` script directly:
93+
94+
```bash
95+
./release.sh <tag-of-release>
96+
```
97+
98+
To filter the target platforms, pass them as a space-separated list in the
99+
`LOOPBUILDSYS` environment variable:
100+
101+
```bash
102+
LOOPBUILDSYS='linux-amd64 windows-amd64' ./release.sh v0.31.3-beta
103+
```
104+
105+
This will produce the same artifacts in a `loop-<tag-of-release>` directory as
106+
the `make docker-release` command. The latter simply runs the `release.sh`
107+
script inside a Docker container.

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)