Skip to content

Commit cd0f1dc

Browse files
authored
Merge pull request #479 from jshufro/jms/v2/build
Refactor build.sh a bit
2 parents c74a4e2 + 28e70be commit cd0f1dc

4 files changed

Lines changed: 39 additions & 77 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Dockerfile
1717
/rocketpool/rocketpool-daemon-linux-amd64
1818
/rocketpool/rocketpool-daemon-darwin-arm64
1919
/rocketpool/rocketpool-daemon-linux-arm64
20+
*.swp
2021

2122
# Packaging
2223
build/

build.sh

Lines changed: 34 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22

33
# This script will build all of the artifacts involved in a new Smart Node release.
4-
# NOTE: You MUST put this in a directory that has the `smartnode` repository cloned as a subdirectory.
54

65
# =================
76
# === Functions ===
@@ -19,78 +18,57 @@ fail() {
1918

2019
# Builds all of the CLI binaries
2120
build_cli() {
22-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
23-
2421
echo -n "Building CLI binaries... "
25-
docker buildx build --rm -f docker/cli.dockerfile --output ../$VERSION --target cli . || fail "Error building CLI binaries."
26-
#rm -rf rocketpool-cli/build
22+
docker buildx build --rm -f docker/cli.dockerfile --output build/$VERSION --target cli . || fail "Error building CLI binaries."
2723
echo "done!"
28-
29-
cd ..
3024
}
3125

3226

3327
# Builds the smart node distro packages
3428
build_distro_packages() {
35-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
36-
3729
echo -n "Building deb packages..."
38-
docker buildx build --rm -f install/packages/debian/package.dockerfile --output ../$VERSION --target package . || fail "Error building deb packages."
39-
rm ../$VERSION/*.build ../$VERSION/*.buildinfo ../$VERSION/*.changes
30+
docker buildx build --rm -f install/packages/debian/package.dockerfile --output build/$VERSION --target package . || fail "Error building deb packages."
31+
rm build/$VERSION/*.build build/$VERSION/*.buildinfo build/$VERSION/*.changes
4032
echo "done!"
41-
42-
cd ..
4333
}
4434

4535

4636
# Builds the .tar.xz file packages with the RP configuration files
4737
build_install_packages() {
48-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
49-
rm -f smartnode-install.tar.xz
50-
5138
echo -n "Building Smart Node installer packages... "
52-
tar cfJ smartnode-install.tar.xz install/deploy || fail "Error building installer package."
53-
mv smartnode-install.tar.xz ../$VERSION
54-
cp install/install.sh ../$VERSION
55-
cp install/install-update-tracker.sh ../$VERSION
39+
tar cfJ build/$VERSION/smartnode-install.tar.xz install/deploy || fail "Error building installer package."
40+
cp install/install.sh build/$VERSION
41+
cp install/install-update-tracker.sh build/$VERSION
5642
echo "done!"
5743

5844
echo -n "Building update tracker package... "
59-
tar cfJ rp-update-tracker.tar.xz install/rp-update-tracker || fail "Error building update tracker package."
60-
mv rp-update-tracker.tar.xz ../$VERSION
45+
tar cfJ build/$VERSION/rp-update-tracker.tar.xz install/rp-update-tracker || fail "Error building update tracker package."
6146
echo "done!"
62-
63-
cd ..
6447
}
6548

6649

6750
# Builds the daemon binaries and Docker Smart Node images, and pushes them to Docker Hub
6851
# NOTE: You must install qemu first; e.g. sudo apt-get install -y qemu qemu-user-static
6952
build_daemon() {
70-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
71-
7253
echo "Building Smart Node daemon binaries..."
73-
docker buildx build --rm --platform=linux/amd64,linux/arm64 -f docker/daemon-build.dockerfile --output ../$VERSION --target daemon . || fail "Error building Smart Node daemon binaries."
54+
docker buildx build --rm --platform=linux/amd64,linux/arm64 -f docker/daemon-build.dockerfile --output build/$VERSION --target daemon . || fail "Error building Smart Node daemon binaries."
7455
echo "done!"
7556

76-
# Copy the daemon binaries to a build folder so the image can access them
77-
mkdir -p ./build
78-
cp ../$VERSION/linux_amd64/* ./build
79-
cp ../$VERSION/linux_arm64/* ./build
80-
echo "done!"
57+
# Flatted the folders to make it easier to upload artifacts to github
58+
mv build/$VERSION/linux_amd64/rocketpool-daemon build/$VERSION/rocketpool-daemon-linux-amd64
59+
mv build/$VERSION/linux_arm64/rocketpool-daemon build/$VERSION/rocketpool-daemon-linux-arm64
60+
61+
# Clean up the empty directories
62+
rmdir build/$VERSION/linux_amd64 build/$VERSION/linux_arm64
8163

8264
echo "Building Smart Node Docker image..."
83-
docker buildx build --rm --platform=linux/amd64,linux/arm64 -t rocketpool/smartnode:$VERSION -f docker/daemon.dockerfile --push . || fail "Error building Smart Node Docker image."
65+
# If uploading, make and push a manifest
66+
if [ "$UPLOAD" = true ]; then
67+
docker buildx build --rm --platform=linux/amd64,linux/arm64 --build-arg BINARIES_PATH=build/$VERSION -t rocketpool/smartnode:$VERSION -f docker/daemon.dockerfile --push . || fail "Error building Smart Node Docker image."
68+
else
69+
docker buildx build --rm --load --build-arg BINARIES_PATH=build/$VERSION -t rocketpool/smartnode:$VERSION -f docker/daemon.dockerfile . || fail "Error building Smart Node Docker image."
70+
fi
8471
echo "done!"
85-
86-
# Cleanup
87-
mv ../$VERSION/linux_amd64/* ../$VERSION
88-
mv ../$VERSION/linux_arm64/* ../$VERSION
89-
rm -rf ../$VERSION/linux_amd64/
90-
rm -rf ../$VERSION/linux_arm64/
91-
rm -rf ./build
92-
93-
cd ..
9472
}
9573

9674

@@ -100,9 +78,13 @@ build_latest_docker_manifest() {
10078
docker tag rocketpool/smartnode:$VERSION rocketpool/smartnode:latest
10179
echo "done!"
10280

103-
echo -n "Pushing to Docker Hub... "
104-
docker push rocketpool/smartnode:latest
105-
echo "done!"
81+
if [ "$UPLOAD" = true ]; then
82+
echo -n "Pushing to Docker Hub... "
83+
docker push rocketpool/smartnode:latest
84+
echo "done!"
85+
else
86+
echo "The image tag only exists locally. Rerun with -u to upload to Docker Hub."
87+
fi
10688
}
10789

10890

@@ -115,8 +97,9 @@ usage() {
11597
echo $'\t-c\tBuild the CLI binaries for all platforms'
11698
echo $'\t-t\tBuild the distro packages (.deb)'
11799
echo $'\t-p\tBuild the Smart Node installer packages'
118-
echo $'\t-d\tBuild the Smart Node Daemon image, and push it to Docker Hub'
119-
echo $'\t-l\tTag the Docker image as "latest" and push it to Docker Hub'
100+
echo $'\t-d\tBuild the Smart Node Daemon image'
101+
echo $'\t-l\tTag the Docker image as "latest"'
102+
echo $'\t-u\tWhen passed with a build, upload the resulting image tags to Docker Hub'
120103
exit 0
121104
}
122105

@@ -126,14 +109,15 @@ usage() {
126109
# =================
127110

128111
# Parse arguments
129-
while getopts "actpdlv:" FLAG; do
112+
while getopts "actpdluv:" FLAG; do
130113
case "$FLAG" in
131114
a) CLI=true DISTRO=true PACKAGES=true DAEMON=true ;;
132115
c) CLI=true ;;
133116
t) DISTRO=true ;;
134117
p) PACKAGES=true ;;
135118
d) DAEMON=true ;;
136119
l) LATEST_MANIFEST=true ;;
120+
u) UPLOAD=true ;;
137121
v) VERSION="$OPTARG" ;;
138122
*) usage ;;
139123
esac
@@ -143,8 +127,8 @@ if [ -z "$VERSION" ]; then
143127
fi
144128

145129
# Cleanup old artifacts
146-
rm -f ./$VERSION/*
147-
mkdir -p ./$VERSION
130+
rm -rf build/$VERSION/*
131+
mkdir -p build/$VERSION
148132

149133
# Make a multiarch builder, ignore if it's already there
150134
docker buildx create --name multiarch-builder --driver docker-container --use > /dev/null 2>&1
@@ -173,47 +157,23 @@ fi
173157

174158
# Builds the deb package builder image
175159
build_deb_builder() {
176-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
177-
178160
echo -n "Building deb builder..."
179161
docker buildx build --rm --platform=linux/amd64,linux/arm64 -t rocketpool/smartnode-deb-builder:$VERSION -f install/packages/debian/builder.dockerfile --push . || fail "Error building deb builder."
180162
echo "done!"
181-
182-
cd ..
183163
}
184164

185165

186166
# Builds the prune provisioner image and pushes it to Docker Hub
187167
build_docker_prune_provision() {
188-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
189-
190168
echo "Building Prune Provisioner image..."
191169
docker buildx build --platform=linux/amd64,linux/arm64 -t rocketpool/eth1-prune-provision:$VERSION -f util-containers/prune-provision.dockerfile --push . || fail "Error building Prune Provision image."
192170
echo "done!"
193-
194-
cd ..
195171
}
196172

197173

198174
# Builds the EC migrator image and pushes it to Docker Hub
199175
build_ec_migrator() {
200-
cd smartnode || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
201-
202176
echo "Building EC Migrator image..."
203177
docker buildx build --platform=linux/amd64,linux/arm64 -t rocketpool/ec-migrator:$VERSION -f util-containers/ec-migrator.dockerfile --push . || fail "Error building EC Migrator image."
204178
echo "done!"
205-
206-
cd ..
207179
}
208-
209-
# Builds the Docker prune starter image and pushes it to Docker Hub
210-
# TODO: Move this to the NPS repo
211-
build_docker_prune_starter() {
212-
cd NethermindPruneStarter || fail "Directory ${PWD}/smartnode does not exist or you don't have permissions to access it."
213-
214-
echo "Building Docker Prune Starter image..."
215-
docker buildx build --platform=linux/amd64,linux/arm64 -t rocketpool/nm-prune-starter:$VERSION -f docker/rocketpool-nm-prune-starter --push . || fail "Error building Docker Prune Starter image."
216-
echo "done!"
217-
218-
cd ..
219-
}

docker/daemon-build.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ RUN if [ "$BUILDPLATFORM" = "linux/amd64" -a "$TARGETARCH" = "arm64" ]; then \
1313
export CC=x86_64-linux-gnu-gcc && export CC_FOR_TARGET=gcc-x86-64-linux-gnu; \
1414
fi && \
1515
cd /rocketpool/src/rocketpool-daemon && \
16-
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /build/rocketpool-daemon-${TARGETOS}-${TARGETARCH}
16+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /build/rocketpool-daemon
1717

1818
# Copy the output
1919
FROM scratch AS daemon
2020
ARG TARGETOS TARGETARCH
21-
COPY --from=builder /build/rocketpool-daemon-${TARGETOS}-${TARGETARCH} /
21+
COPY --from=builder /build/rocketpool-daemon /rocketpool-daemon

docker/daemon.dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# The daemon image
22
FROM debian:bookworm-slim
3+
ARG BINARIES_PATH
34
ARG TARGETOS TARGETARCH
4-
COPY ./build/rocketpool-daemon-${TARGETOS}-${TARGETARCH} /usr/bin/rocketpool-daemon
5+
COPY ${BINARIES_PATH}/rocketpool-daemon-${TARGETOS}-${TARGETARCH} /usr/bin/rocketpool-daemon
56
RUN apt update && \
67
apt install ca-certificates -y && \
78
# Cleanup

0 commit comments

Comments
 (0)