Skip to content

Commit 99664a6

Browse files
committed
update build scripts to support treegen
1 parent 8c30a6e commit 99664a6

6 files changed

Lines changed: 56 additions & 33 deletions

File tree

Makefile

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
BUILD_DIR=build
22
CLI_DIR=${BUILD_DIR}/cli
33
DAEMON_DIR=${BUILD_DIR}/daemon
4+
TREEGEN_DIR=${BUILD_DIR}/treegen
45

56
CLI_TARGET_OOS:=linux darwin
67
ARCHS:=arm64 amd64
78

9+
DOCKER_RUN_CMD=docker run --env OWNER=$(shell id -u):$(shell id -g) --rm -v /tmp/docker-go-build:/root/.cache/go-build
10+
DOCKER_BUILDER_TAG=rocketpool/smartnode-builder:latest
11+
812
CLI_TARGET_STRINGS:=$(foreach oos,$(CLI_TARGET_OOS), $(foreach arch,$(ARCHS),${CLI_DIR}/rocketpool-cli-$(oos)-$(arch)))
913
DAEMON_TARGET_STRINGS:=$(foreach arch,$(ARCHS),${DAEMON_DIR}/rocketpool-daemon-linux-$(arch))
1014

@@ -21,18 +25,33 @@ endef
2125
.PHONY: all
2226
all: lint rocketpool-cli rocketpool-daemon
2327

28+
.PHONY: docker-builder
29+
docker-builder: docker/smartnode-builder
30+
docker build -t $(DOCKER_BUILDER_TAG) -f docker/smartnode-builder .
31+
2432
.PHONY: rocketpool-cli
2533
rocketpool-cli: $(CLI_TARGET_STRINGS)
2634

2735
.PHONY: rocketpool-daemon
28-
rocketpool-daemon: ${DAEMON_DIR}
29-
docker build -t rocketpool/smartnode-builder:latest -f docker/smartnode-builder .
30-
docker run --env OWNER=$(shell id -u):$(shell id -g) --rm -v $(PWD):/src -v $(PWD)/${DAEMON_DIR}:/out -v /tmp/docker-go-build:/root/.cache/go-build rocketpool/smartnode-builder:latest /src/rocketpool/build.sh
36+
rocketpool-daemon: ${DAEMON_DIR} docker-builder
37+
$(DOCKER_RUN_CMD) -v $(PWD):/src -v $(PWD)/${DAEMON_DIR}:/out ${DOCKER_BUILDER_TAG} /src/rocketpool/build.sh
38+
.PHONY: treegen-bin
39+
treegen-bin: ${TREEGEN_DIR}/treegen-linux-amd64 ${TREEGEN_DIR}/treegen-linux-arm64
40+
.PHONY: treegen-docker
41+
treegen-container: treegen-bin
42+
./treegen/build-release.sh -a -v $(TREEGEN_VERSION)
43+
.PHONY: treegen-container-push
44+
treegen-container-push: treegen-container
45+
./treegen/build-release.sh -p -a -v $(TREEGEN_VERSION)
3146

3247
${CLI_DIR}:
3348
mkdir -p ${CLI_DIR}
3449
${DAEMON_DIR}:
3550
mkdir -p ${DAEMON_DIR}
51+
${TREEGEN_DIR}:
52+
mkdir -p ${TREEGEN_DIR}
53+
${TREEGEN_DIR}/treegen-linux-amd64 ${TREEGEN_DIR}/treegen-linux-arm64: $(shell find treegen -name "*.go") treegen/go.mod docker-builder
54+
$(DOCKER_RUN_CMD) -v $(PWD):/src -v $(PWD)/${TREEGEN_DIR}:/out ${DOCKER_BUILDER_TAG} /src/treegen/build_binaries.sh
3655

3756
$(foreach oos,$(CLI_TARGET_OOS),$(foreach arch,$(ARCHS),$(eval $(call rocketpool-cli-template,$(oos),$(arch)))))
3857

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ A [Makefile](./Makefile) is included for building, testing, and linting.
3131
* `make all` will build rocketpool-cli, rocketpool-daemon, and run the linter.
3232
* `make rocketpool-daemon` will build the docker containers required to build the daemon, then build the daemon.
3333
* `make rocketpool-cli` will build the cli for linux and osx.
34+
* `make treegen-bin` makes treegen binaries, `make treegen-docker` makes docker images with those binaries, and `make treegen-container-push` pushes them to docker hub.
3435
* `make test` runs all unit tests.
3536
* `make clean` deletes any binaries. It does not clear your go caches.
3637

docker/treegen

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM debian:bookworm-slim
2+
3+
ARG TARGETARCH
4+
COPY ./build/treegen/treegen-linux-${TARGETARCH} /treegen

treegen/Dockerfile

Lines changed: 0 additions & 4 deletions
This file was deleted.

treegen/build-release.sh

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/bin/bash
22

3-
# Builds the binaries
4-
build_binary() {
5-
echo -n "Building binaries... "
6-
docker run --rm -v $PWD:/treegen rocketpool/smartnode-builder:latest /treegen/build_binaries.sh
7-
echo "done!"
8-
}
9-
103
# Build the images
114
build_docker() {
5+
local PUSH=$1
126
echo -n "Building Docker images... "
13-
docker buildx build --platform=linux/amd64 -t rocketpool/treegen:$VERSION-amd64 --load .
14-
docker buildx build --platform=linux/arm64 -t rocketpool/treegen:$VERSION-arm64 --load .
15-
docker push rocketpool/treegen:$VERSION-amd64
16-
docker push rocketpool/treegen:$VERSION-arm64
7+
docker buildx build --no-cache --progress=plain --platform=linux/amd64 -t rocketpool/treegen:$VERSION-amd64 --load -f ./docker/treegen .
8+
docker buildx build --platform=linux/arm64 -t rocketpool/treegen:$VERSION-arm64 --load -f ./docker/treegen .
9+
if [ "$PUSH" = "true" ]; then
10+
echo -n "Pushing to Docker Hub... "
11+
docker push rocketpool/treegen:$VERSION-amd64
12+
docker push rocketpool/treegen:$VERSION-arm64
13+
fi
1714
echo "done!"
1815
}
1916

2017
# Build the manifest
2118
build_manifest() {
19+
local PUSH=$1
2220
echo -n "Building Docker manifest... "
2321
rm -f ~/.docker/manifests/docker.io_rocketpool_treegen-$VERSION
2422
rm -f ~/.docker/manifests/docker.io_rocketpool_treegen-latest
2523
docker manifest create rocketpool/treegen:$VERSION --amend rocketpool/treegen:$VERSION-amd64 --amend rocketpool/treegen:$VERSION-arm64
2624
docker manifest create rocketpool/treegen:latest --amend rocketpool/treegen:$VERSION-amd64 --amend rocketpool/treegen:$VERSION-arm64
2725
echo "done!"
28-
echo -n "Pushing to Docker Hub... "
29-
docker manifest push --purge rocketpool/treegen:$VERSION
30-
docker manifest push --purge rocketpool/treegen:latest
26+
if [ "$PUSH" = "true" ]; then
27+
echo -n "Pushing to Docker Hub... "
28+
docker manifest push --purge rocketpool/treegen:$VERSION
29+
docker manifest push --purge rocketpool/treegen:latest
30+
fi
3131
echo "done!"
3232
}
3333

@@ -37,9 +37,9 @@ usage() {
3737
echo "This script builds treegen's artifacts."
3838
echo "Options:"
3939
echo $'\t-a\tBuild all of the artifacts.'
40-
echo $'\t-b\tBuild the native binaries for most Linux distributions'
4140
echo $'\t-d\tBuild the Alpine-based Docker containers'
4241
echo $'\t-m\tBuild the Docker manifest'
42+
echo $'\t-p\tPush the docker manifests and/or containers'
4343
exit 0
4444
}
4545

@@ -48,12 +48,12 @@ usage() {
4848
# =================
4949

5050
# Get the version
51-
while getopts "abdmv:" FLAG; do
51+
while getopts "admpv:" FLAG; do
5252
case "$FLAG" in
53-
a) BINARIES=true DOCKER=true MANIFEST=true ;;
54-
b) BINARIES=true ;;
53+
a) DOCKER=true MANIFEST=true ;;
5554
d) DOCKER=true ;;
5655
m) MANIFEST=true ;;
56+
p) PUSH=true ;;
5757
v) VERSION="$OPTARG" ;;
5858
*) usage ;;
5959
esac
@@ -63,12 +63,9 @@ if [ -z "$VERSION" ]; then
6363
fi
6464

6565
# Build the artifacts
66-
if [ "$BINARIES" = true ]; then
67-
build_binary
68-
fi
6966
if [ "$DOCKER" = true ]; then
70-
build_docker
67+
build_docker $PUSH
7168
fi
7269
if [ "$MANIFEST" = true ]; then
73-
build_manifest
70+
build_manifest $PUSH
7471
fi

treegen/build_binaries.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/bin/bash
22

3-
cd /treegen
3+
cd $(dirname $0)
44

55
export CGO_ENABLED=1
66

77
# Build x64 version
8-
CGO_CFLAGS="-O -D__BLST_PORTABLE__" GOARCH=amd64 GOOS=linux go build -o Releases/treegen-linux-amd64 -buildvcs=false
8+
CGO_CFLAGS="-O -D__BLST_PORTABLE__" GOARCH=amd64 GOOS=linux go build -o /out/treegen-linux-amd64 -buildvcs=false
99

1010
# Build the arm64 version
11-
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-cpp CGO_CFLAGS="-O -D__BLST_PORTABLE__" GOARCH=arm64 GOOS=linux go build -o Releases/treegen-linux-arm64 -buildvcs=false
11+
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-cpp CGO_CFLAGS="-O -D__BLST_PORTABLE__" GOARCH=arm64 GOOS=linux go build -o /out/treegen-linux-arm64 -buildvcs=false
12+
13+
if [ -z "${OWNER}" ]; then
14+
exit 0
15+
fi
16+
17+
chown ${OWNER} /out/*

0 commit comments

Comments
 (0)