Skip to content

Commit 9e5685f

Browse files
authored
Merge pull request #881 from lightninglabs/reproducible-build
build: make builds fully reproducible across systems
2 parents d66fd09 + ea33903 commit 9e5685f

35 files changed

+645
-367
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
# If you change this value, please change it in the following files as well:
1313
# /Dockerfile
1414
# /dev.Dockerfile
15-
GO_VERSION: 1.22.3
15+
GO_VERSION: 1.22.6
1616

1717
jobs:
1818
########################

.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@ itest/litd-itest
1313
itest/lnd-itest
1414
itest/itest.test
1515
itest/.logs
16-
itest/*.log
16+
itest/*.log
17+
18+
vendor
19+
*.idea
20+
*.run
21+
*.iml
22+
profile.cov
23+
profile.tmp
24+
25+
.DS_Store
26+
27+
.vscode
28+
*.code-workspace

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ linters-settings:
3131
- G402 # Look for bad TLS connection settings.
3232
- G306 # Poor file permissions used when writing to a new file.
3333
staticcheck:
34-
go: "1.18"
34+
go: "1.22.6"
3535
checks: ["-SA1019"]
3636

3737
linters:

Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Start with a NodeJS base image that also contains yarn.
2-
FROM node:22.8.0-alpine as nodejsbuilder
2+
FROM node:22.8.0-alpine@sha256:bec0ea49c2333c429b62e74e91f8ba1201b060110745c3a12ff957cd51b363c6 as nodejsbuilder
33

44
# Pass a tag, branch or a commit using build-arg. This allows a docker image to
55
# be built from a specified Git state. The default image will use the Git tip of
@@ -32,10 +32,7 @@ RUN apk add --no-cache --update alpine-sdk \
3232

3333
# The first stage is already done and all static assets should now be generated
3434
# in the app/build sub directory.
35-
# If you change this value, please also update:
36-
# /dev.Dockerfile
37-
# /.github/workflows/main.yml
38-
FROM golang:1.22.3-alpine as golangbuilder
35+
FROM golang:1.22.6-alpine@sha256:1a478681b671001b7f029f94b5016aed984a23ad99c707f6a0ab6563860ae2f3 as golangbuilder
3936

4037
# Instead of checking out from git again, we just copy the whole working
4138
# directory of the previous stage that includes the generated static assets.
@@ -53,7 +50,7 @@ RUN apk add --no-cache --update alpine-sdk \
5350
&& make go-install-cli
5451

5552
# Start a new, final image to reduce size.
56-
FROM alpine as final
53+
FROM alpine:3.20.3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d as final
5754

5855
# Define a root volume for data persistence.
5956
VOLUME /root/.lnd

Makefile

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
1818
COMMIT_HASH := $(shell git rev-parse HEAD)
1919
PUBLIC_URL :=
2020

21+
# GO_VERSION is the Go version used for the release build, docker files, and
22+
# GitHub Actions. This is the reference version for the project. All other Go
23+
# versions are checked against this version.
24+
GO_VERSION = 1.22.6
25+
2126
LOOP_COMMIT := $(shell cat go.mod | \
2227
grep $(LOOP_PKG) | \
2328
head -n1 | \
@@ -159,9 +164,25 @@ app-build: yarn-install
159164
@$(call print, "Building production app.")
160165
cd app; yarn build
161166

162-
release: app-build
167+
docker-app-build:
168+
@$(call print, "Building production app in docker.")
169+
cd app; ./gen_app_docker.sh
170+
171+
release: docker-app-build go-release
172+
173+
go-release:
163174
@$(call print, "Creating release of lightning-terminal.")
164-
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
175+
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)" "$(GO_VERSION)"
176+
177+
docker-release: docker-app-build
178+
@$(call print, "Building release helper docker image.")
179+
if [ "$(tag)" = "" ]; then echo "Must specify tag=<commit_or_tag>!"; exit 1; fi
180+
181+
docker build -t litd-release-helper -f make/builder.Dockerfile make/
182+
183+
# Run the actual compilation inside the docker image. We pass in all flags
184+
# that we might want to overwrite in manual tests.
185+
$(DOCKER_RELEASE_HELPER) make go-release tag="$(tag)" sys="$(sys)" COMMIT="$(COMMIT)"
165186

166187
docker-tools:
167188
@$(call print, "Building tools docker image.")
@@ -226,7 +247,17 @@ fmt: $(GOIMPORTS_BIN)
226247
@$(call print, "Formatting source.")
227248
gofmt -l -w -s $(GOFILES_NOVENDOR)
228249

229-
lint: docker-tools
250+
check-go-version-yaml:
251+
@$(call print, "Checking for target Go version (v$(GO_VERSION)) in YAML files (*.yaml, *.yml)")
252+
./scripts/check-go-version-yaml.sh $(GO_VERSION)
253+
254+
check-go-version-dockerfile:
255+
@$(call print, "Checking for target Go version (v$(GO_VERSION)) in Dockerfile files (*Dockerfile)")
256+
./scripts/check-go-version-dockerfile.sh $(GO_VERSION)
257+
258+
check-go-version: check-go-version-dockerfile check-go-version-yaml
259+
260+
lint: check-go-version docker-tools
230261
@$(call print, "Linting source.")
231262
$(DOCKER_TOOLS) golangci-lint run -v $(LINT_WORKERS)
232263

@@ -267,3 +298,11 @@ clean: clean-itest
267298
$(RM) ./litcli-debug
268299
$(RM) ./litd-debug
269300
$(RM) coverage.txt
301+
302+
# Prevent make from interpreting any of the defined goals as folders or files to
303+
# include in the build process.
304+
.PHONY: default all yarn-install build install go-build go-build-noui \
305+
go-install go-install-noui go-install-cli app-build release go-release \
306+
docker-release docker-tools scratch check unit unit-cover unit-race \
307+
clean-itest build-itest itest-only itest flake-unit fmt lint mod mod-check \
308+
list rpc protos protos-check rpc-js-compile clean

app/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Start with a NodeJS base image that also contains yarn.
2+
FROM node:22.8.0-bookworm@sha256:bd00c03095f7586432805dbf7989be10361d27987f93de904b1fc003949a4794 as nodejsbuilder
3+
4+
RUN apt-get update && apt-get install -y git
5+
6+
ENV HOME=/tmp
7+
8+
RUN mkdir /build
9+
10+
WORKDIR /build
11+
12+
CMD ["/bin/bash", "-c", "chown $(id -u):$(id -g) /build && cd app && rm -rf node_modules && yarn cache clean && yarn install && yarn build"]

app/gen_app_docker.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Directory of the script file, independent of where it's called from.
6+
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
7+
8+
echo "Building app compiler docker image..."
9+
docker build -q -t lit-app-builder .
10+
11+
echo "Compiling app files..."
12+
docker run \
13+
--rm \
14+
--user $(id -u):$(id -g) \
15+
-v "$DIR/../:/build" \
16+
lit-app-builder

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"start": "BROWSER=none react-scripts start",
99
"develop": "REACT_APP_USE_SAMPLE_DATA=true yarn start",
1010
"build": "react-scripts build",
11-
"postbuild": "echo '# Keep directory in git.' > build/.gitkeep",
11+
"postbuild": "git restore build/.gitkeep",
1212
"test": "react-scripts test --env=jest-environment-jsdom --transformIgnorePatterns \"node_modules/(?!d3)/\"",
1313
"test:ci": "cross-env CI=true yarn test --coverage",
1414
"eject": "react-scripts eject",

autopilotserverrpc/autopilotserver.pb.go

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev.Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Start with a NodeJS base image that also contains yarn.
2-
FROM node:22.8.0-alpine as nodejsbuilder
2+
FROM node:22.8.0-alpine@sha256:bec0ea49c2333c429b62e74e91f8ba1201b060110745c3a12ff957cd51b363c6 as nodejsbuilder
33

44
# Copy in the local repository to build from.
55
COPY . /go/src/github.com/lightninglabs/lightning-terminal
@@ -10,10 +10,7 @@ RUN cd /go/src/github.com/lightninglabs/lightning-terminal/app \
1010

1111
# The first stage is already done and all static assets should now be generated
1212
# in the app/build sub directory.
13-
# If you change this value, please also update:
14-
# /Dockerfile
15-
# /.github/workflows/main.yml
16-
FROM golang:1.22.3-alpine as golangbuilder
13+
FROM golang:1.22.6-alpine@sha256:1a478681b671001b7f029f94b5016aed984a23ad99c707f6a0ab6563860ae2f3 as golangbuilder
1714

1815
# Instead of checking out from git again, we just copy the whole working
1916
# directory of the previous stage that includes the generated static assets.
@@ -31,7 +28,7 @@ RUN apk add --no-cache --update alpine-sdk \
3128
&& make go-install-cli
3229

3330
# Start a new, final image to reduce size.
34-
FROM alpine as final
31+
FROM alpine:3.20.3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d as final
3532

3633
# Define a root volume for data persistence.
3734
VOLUME /root/.lnd

0 commit comments

Comments
 (0)