Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,22 @@ 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

GREEN := "\\033[0;32m"
NC := "\\033[0m"
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
echo $(GREEN)$1$(NC)
@printf '%b%s%b\n' '${GREEN}' $1 '${NC}'
endef

# ============
Expand All @@ -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=<commit_or_tag>!"; exit 1; fi
$(DOCKER_RELEASE_BUILDER) bash release.sh $(tag)

rpc:
@$(call print, "Compiling protos.")
cd ./swapserverrpc; ./gen_protos_docker.sh
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,8 @@ git clone https://github.com/lightninglabs/loop.git
cd loop/cmd
go install ./...
```

## Reproducible builds

If you want to build release files yourself, follow
[the guide](./docs/release.md).
107 changes: 107 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Reproducible Builds

## Building with Docker

To create a Loop release with binaries that are identical to an official
release, run the following command (available since release `v0.31.3-beta`):

```bash
make docker-release tag=<tag-of-release>
```

This command will create a directory named `loop-<tag-of-release>` containing
the source archive, vendored dependencies, and the built binaries packaged in
`.tar.gz` or `.zip` format. It also creates a manifest file with `SHA-256`
checksums for all release files.

For example:

```bash
make docker-release tag=v0.31.3-beta
```

This will create the release artifacts in the `loop-v0.31.3-beta` directory.

If you want to build from an untagged commit, first check it out, then use the
output of `git describe --abbrev=10` as the tag:

```bash
git describe --abbrev=10
# v0.31.2-beta-135-g35d0fa26ac

make docker-release tag=v0.31.2-beta-135-g35d0fa26ac
```

You can filter the target platforms to speed up the build process. For example,
to build only for `linux-amd64`:

```bash
make docker-release buildsys=linux-amd64 tag=v0.31.3-beta
```

Or for multiple platforms:

```bash
make docker-release buildsys='linux-amd64 windows-amd64' tag=v0.31.3-beta
```

Note: inside Docker the current directory is mapped as `/repo` and it might
mention `/repo` as parts of file paths.

## Building on the Host

You can also build a release on your host system without Docker. You will need
to install the Go version specified in the `go.mod` file, as well as a few
other tools:

```bash
sudo apt-get install build-essential git make zip perl gpg
```

You can [download](https://go.dev/dl/) and unpack Go somewhere and set variable
`GO_CMD=/path/to/go` (path to Go binary of the needed version).

If you already have another Go version, you can install the Go version needed
for a release using the following commands:

```bash
$ go version
go version go1.25.0 linux/amd64
$ go install golang.org/dl/go1.24.6@latest
$ go1.24.6 download
Unpacking /home/user/sdk/go1.24.6/go1.24.6.linux-amd64.tar.gz ...
Success. You may now run 'go1.24.6'
$ go1.24.6 version
go version go1.24.6 linux/amd64

$ GO_CMD=/home/user/go/bin/go1.24.6 ./release.sh v0.31.3
```

On MacOS, you will need to install GNU tar and GNU gzip, which can be done with
`brew`:

```bash
brew install gnu-tar gzip
```

Add GPG key of Alex Bosworth to verify release tag signature:
```bash
gpg --keyserver keys.openpgp.org --recv-keys DE23E73BFA8A0AD5587D2FCDE80D2F3F311FD87E
```

Then, run the `release.sh` script directly:

```bash
./release.sh <tag-of-release>
```

To filter the target platforms, pass them as a space-separated list in the
`LOOPBUILDSYS` environment variable:

```bash
LOOPBUILDSYS='linux-amd64 windows-amd64' ./release.sh v0.31.3-beta
```

This will produce the same artifacts in a `loop-<tag-of-release>` directory as
the `make docker-release` command. The latter simply runs the `release.sh`
script inside a Docker container.
23 changes: 23 additions & 0 deletions release.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Loading