Skip to content

Commit

Permalink
make+scripts: add lndsigner to release script
Browse files Browse the repository at this point in the history
Update the release script to include the `lndsigner` binary in the
release. Each environment will have its own zipped folder containing
`lndsigner` and an `lncli` binary built with fewer build tags, limiting
the available RPCs.
  • Loading branch information
ViktorTigerstrom committed Nov 21, 2024
1 parent 395956b commit 6f6cebf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ release-install:
# Make sure the generated mobile RPC stubs don't influence our vendor package
# by removing them first in the clean-mobile target.
release: clean-mobile
@$(call print, "Releasing lnd and lncli binaries.")
@$(call print, "Releasing lnd/lndsigner and lncli binaries.")
$(VERSION_CHECK)
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_TAGS)" "$(RELEASE_LDFLAGS)" "$(GO_VERSION)"
./scripts/release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_TAGS)" "$(LND_SIGNER_TAGS)" "$(RELEASE_LDFLAGS)" "$(GO_VERSION)"

#? docker-release: Same as release but within a docker container to support reproducible builds on BSD/MacOS platforms
docker-release:
Expand Down
75 changes: 49 additions & 26 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ set -e

LND_VERSION_REGEX="lnd version (.+) commit"
PKG="github.com/lightningnetwork/lnd"
PACKAGE=lnd
LND_PACKAGE=lnd
SIGNER_PACKAGE=lndsigner

# Needed for setting file timestamps to get reproducible archives.
BUILD_DATE="2020-01-01 00:00:00"
Expand Down Expand Up @@ -127,15 +128,50 @@ function check_tag_correct() {
fi
}

# build_package builds release binaries for the passed package and lncli, for
# the passed environment.
# arguments: <package-name> <iteration-index> <tag> <os> <arch> <arm>
# <build-tags> <ldflags>
function build_package() {
local package_name=$1
local index=$2
local tag=$3
local os=$4
local arch=$5
local arm=$6
local build_tags=$7
local ldflags=$8

dir="${package_name}-${index}-${tag}"
mkdir "${dir}"
pushd "${dir}"

green " - Building ${package_name}: ${os} ${arch} ${arm} with build tags '${build_tags}'"
env GOEXPERIMENT=loopvar CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" -tags="${build_tags}" ${PKG}/cmd/${package_name}
env GOEXPERIMENT=loopvar CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" -tags="${build_tags}" ${PKG}/cmd/lncli
popd

# Add the hashes for the individual binaries as well for easy verification
# of a single installed binary.
shasum -a 256 "${dir}/"* >> "manifest-$tag.txt"

if [[ $os == "windows" ]]; then
reproducible_zip "${dir}"
else
reproducible_tar_gzip "${dir}"
fi
}

# build_release builds the actual release binaries.
# arguments: <version-tag> <build-system(s)> <build-tags> <ldflags>
# <go-version>
# arguments: <version-tag> <build-system(s)> <lnd-build-tags>
# <lndsigner-build-tags> <ldflags> <go-version>
function build_release() {
local tag=$1
local sys=$2
local buildtags=$3
local ldflags=$4
local goversion=$5
local lndbuildtags=$3
local signerbuildtags=$4
local ldflags=$5
local goversion=$6

# Check if the active Go version matches the specified Go version.
active_go_version=$(go version | awk '{print $3}' | sed 's/go//')
Expand All @@ -151,13 +187,13 @@ required Go version ($goversion)."
go mod vendor
reproducible_tar_gzip vendor

maindir=$PACKAGE-$tag
maindir=$LND_PACKAGE-$tag
mkdir -p $maindir
mv vendor.tar.gz "${maindir}/"

# Don't use tag in source directory, otherwise our file names get too long and
# tar starts to package them non-deterministically.
package_source="${PACKAGE}-source"
package_source="${LND_PACKAGE}-source"

# The git archive command doesn't support setting timestamps and file
# permissions. That's why we unpack the tar again, then use our reproducible
Expand All @@ -184,28 +220,15 @@ required Go version ($goversion)."
arm=7
fi

dir="${PACKAGE}-${i}-${tag}"
mkdir "${dir}"
pushd "${dir}"
# Build lnd package
build_package "${LND_PACKAGE}" "${i}" "${tag}" "${os}" "${arch}" "${arm}" "${lndbuildtags}" "${ldflags}"

green " - Building: ${os} ${arch} ${arm} with build tags '${buildtags}'"
env GOEXPERIMENT=loopvar CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" -tags="${buildtags}" ${PKG}/cmd/lnd
env GOEXPERIMENT=loopvar CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" -tags="${buildtags}" ${PKG}/cmd/lncli
popd

# Add the hashes for the individual binaries as well for easy verification
# of a single installed binary.
shasum -a 256 "${dir}/"* >> "manifest-$tag.txt"

if [[ $os == "windows" ]]; then
reproducible_zip "${dir}"
else
reproducible_tar_gzip "${dir}"
fi
# Build lndsigner package
build_package "${SIGNER_PACKAGE}" "${i}" "${tag}" "${os}" "${arch}" "${arm}" "${signerbuildtags}" "${ldflags}"
done

# Add the hash of the packages too, then sort by the second column (name).
shasum -a 256 lnd-* vendor* >> "manifest-$tag.txt"
shasum -a 256 "${LND_PACKAGE}"-* "${SIGNER_PACKAGE}"-* vendor* >> "manifest-$tag.txt"
LC_ALL=C sort -k2 -o "manifest-$tag.txt" "manifest-$tag.txt"
cat "manifest-$tag.txt"
}
Expand Down

0 comments on commit 6f6cebf

Please sign in to comment.