Skip to content

Commit 70784c8

Browse files
authored
Merge pull request #5 from guggero/standalone-release
Support standalone binary release
2 parents 62038bd + 7d84115 commit 70784c8

File tree

4 files changed

+146
-8
lines changed

4 files changed

+146
-8
lines changed

.github/workflows/docker.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Docker image build
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- 'docker/v*'
77

88
defaults:
99
run:
@@ -30,14 +30,14 @@ jobs:
3030
password: ${{ secrets.DOCKER_API_KEY }}
3131

3232
- name: Set env for RELEASE_VERSION
33-
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
33+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/docker}" >> $GITHUB_ENV
3434

35-
# We will push tags with the format v0.x.y-lnd-v0.aa.bb-beta where x and y
36-
# are lndinit's version and aa and bb are lnd's version. This variable
37-
# LND_VERSION extracts everything after v0.x.y-lnd- so we know which base
38-
# image we need to build on top of.
35+
# We will push tags with the format docker/v0.x.y-beta-lnd-v0.aa.bb-beta
36+
# where x and y are lndinit's version and aa and bb are lnd's version.
37+
# This variable LND_VERSION extracts everything after v0.x.y-lnd- so we
38+
# know which base image we need to build on top of.
3939
- name: Set env for LND_VERSION
40-
run: echo "LND_VERSION=${RELEASE_VERSION##v*\.*\.*-lnd-}" >> $GITHUB_ENV
40+
run: echo "LND_VERSION=${RELEASE_VERSION##v*\.*\.*-beta-lnd-}" >> $GITHUB_ENV
4141

4242
- name: Build and push
4343
id: docker_build

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ _testmain.go
2727
/lndinit
2828
/lndinit-debug
2929

30+
lndinit-v*/
31+
3032
*.key
3133
*.hex
3234

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ CP := cp
2020
MAKE := make
2121
XARGS := xargs -L 1
2222

23+
VERSION_TAG = $(shell git describe --tags)
24+
25+
BUILD_SYSTEM = darwin-amd64 \
26+
linux-386 \
27+
linux-amd64 \
28+
linux-armv6 \
29+
linux-armv7 \
30+
linux-arm64 \
31+
windows-386 \
32+
windows-amd64 \
33+
windows-arm
34+
35+
# By default we will build all systems. But with the 'sys' tag, a specific
36+
# system can be specified. This is useful to release for a subset of
37+
# systems/architectures.
38+
ifneq ($(sys),)
39+
BUILD_SYSTEM = $(sys)
40+
endif
41+
42+
ifneq ($(tag),)
43+
VERSION_TAG = $(tag)
44+
endif
45+
2346
# We only return the part inside the double quote here to avoid escape issues
2447
# when calling the external release script. The second parameter can be used to
2548
# add additional ldflags if needed (currently only used for the release).
@@ -28,7 +51,6 @@ make_ldflags = $(2) -X $(PKG).Commit=$(COMMIT)
2851
DEV_GCFLAGS := -gcflags "all=-N -l"
2952
LDFLAGS := -ldflags "$(call make_ldflags, ${tags}, -s -w)"
3053
DEV_LDFLAGS := -ldflags "$(call make_ldflags, $(DEV_TAGS))"
31-
ITEST_LDFLAGS := -ldflags "$(call make_ldflags, $(ITEST_TAGS))"
3254

3355
# For the release, we want to remove the symbol table and debug information (-s)
3456
# and omit the DWARF symbol table (-w). Also we clear the build ID.
@@ -67,6 +89,10 @@ release-install:
6789
@$(call print, "Installing release lndinit.")
6890
env CGO_ENABLED=0 $(GOINSTALL) -v -trimpath -ldflags="$(RELEASE_LDFLAGS)" -tags="$(RELEASE_TAGS)" $(PKG)
6991

92+
release:
93+
@$(call print, "Creating release of lndinit.")
94+
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(RELEASE_LDFLAGS)"
95+
7096
docker-tools:
7197
@$(call print, "Building tools docker image.")
7298
docker build -q -t lndinit-tools $(TOOLS_DIR)

release.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# Simple bash script to build basic lndinit for all the platforms we support
4+
# with the golang cross-compiler.
5+
#
6+
# Copyright (c) 2016 Company 0, LLC.
7+
# Use of this source code is governed by the ISC
8+
# license.
9+
10+
set -e
11+
12+
PKG="github.com/lightninglabs/lndinit"
13+
PACKAGE=lndinit
14+
15+
# green prints one line of green text (if the terminal supports it).
16+
function green() {
17+
echo -e "\e[0;32m${1}\e[0m"
18+
}
19+
20+
# red prints one line of red text (if the terminal supports it).
21+
function red() {
22+
echo -e "\e[0;31m${1}\e[0m"
23+
}
24+
25+
# build_release builds the actual release binaries.
26+
# arguments: <version-tag> <build-system(s)> <ldflags>
27+
function build_release() {
28+
local tag=$1
29+
local sys=$2
30+
local ldflags=$3
31+
32+
green " - Packaging vendor"
33+
go mod vendor
34+
tar -czf vendor.tar.gz vendor
35+
36+
maindir=$PACKAGE-$tag
37+
mkdir -p $maindir
38+
39+
cp vendor.tar.gz $maindir/
40+
rm vendor.tar.gz
41+
rm -r vendor
42+
43+
package_source="${maindir}/${PACKAGE}-source-${tag}.tar"
44+
git archive -o "${package_source}" HEAD
45+
gzip -f "${package_source}" >"${package_source}.gz"
46+
47+
cd "${maindir}"
48+
49+
for i in $sys; do
50+
os=$(echo $i | cut -f1 -d-)
51+
arch=$(echo $i | cut -f2 -d-)
52+
arm=
53+
54+
if [[ $arch == "armv6" ]]; then
55+
arch=arm
56+
arm=6
57+
elif [[ $arch == "armv7" ]]; then
58+
arch=arm
59+
arm=7
60+
fi
61+
62+
dir="${PACKAGE}-${i}-${tag}"
63+
mkdir "${dir}"
64+
pushd "${dir}"
65+
66+
green " - Building: ${os} ${arch} ${arm}"
67+
env CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" ${PKG}
68+
popd
69+
70+
if [[ $os == "windows" ]]; then
71+
zip -r "${dir}.zip" "${dir}"
72+
else
73+
tar -cvzf "${dir}.tar.gz" "${dir}"
74+
fi
75+
76+
rm -r "${dir}"
77+
done
78+
79+
shasum -a 256 * >manifest-$tag.txt
80+
}
81+
82+
# usage prints the usage of the whole script.
83+
function usage() {
84+
red "Usage: "
85+
red "release.sh build-release <version-tag> <build-system(s)> <ldflags>"
86+
}
87+
88+
# Whatever sub command is passed in, we need at least 2 arguments.
89+
if [ "$#" -lt 2 ]; then
90+
usage
91+
exit 1
92+
fi
93+
94+
# Extract the sub command and remove it from the list of parameters by shifting
95+
# them to the left.
96+
SUBCOMMAND=$1
97+
shift
98+
99+
# Call the function corresponding to the specified sub command or print the
100+
# usage if the sub command was not found.
101+
case $SUBCOMMAND in
102+
build-release)
103+
green "Building release"
104+
build_release "$@"
105+
;;
106+
*)
107+
usage
108+
exit 1
109+
;;
110+
esac

0 commit comments

Comments
 (0)