Skip to content

Commit e7a9db6

Browse files
committed
Upgraded to cross-compiler build system and standardized images
1 parent 1bdcd9c commit e7a9db6

File tree

6 files changed

+128
-19
lines changed

6 files changed

+128
-19
lines changed

daemon-build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Get the platform type and run the build script if possible
44
PLATFORM=$(uname -s)
55
if [ "$PLATFORM" = "Linux" ]; then
6-
docker run --rm -v $PWD:/smartnode debian:10 /smartnode/rocketpool/build.sh
6+
docker run --rm -v $PWD:/smartnode rocketpool/smartnode-builder:latest /smartnode/rocketpool/build.sh
77
else
88
echo "Platform ${PLATFORM} is not supported by this script, please build the daemon manually."
99
exit 1

docker/build-base.sh

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
# Build the images
4+
build_docker() {
5+
echo -n "Building Docker images... "
6+
docker buildx build --platform=linux/amd64 -t rocketpool/smartnode-base:$VERSION-amd64 --load -f smartnode-base .
7+
docker buildx build --platform=linux/arm64 -t rocketpool/smartnode-base:$VERSION-arm64 --load -f smartnode-base .
8+
docker push rocketpool/smartnode-base:$VERSION-amd64
9+
docker push rocketpool/smartnode-base:$VERSION-arm64
10+
echo "done!"
11+
}
12+
13+
# Build the manifest
14+
build_manifest() {
15+
echo -n "Building Docker manifest... "
16+
rm -f ~/.docker/manifests/docker.io_rocketpool_smartnode-base-$VERSION
17+
rm -f ~/.docker/manifests/docker.io_rocketpool_smartnode-base-latest
18+
docker manifest create rocketpool/smartnode-base:$VERSION --amend rocketpool/smartnode-base:$VERSION-amd64 --amend rocketpool/smartnode-base:$VERSION-arm64
19+
docker manifest create rocketpool/smartnode-base:latest --amend rocketpool/smartnode-base:$VERSION-amd64 --amend rocketpool/smartnode-base:$VERSION-arm64
20+
echo "done!"
21+
echo -n "Pushing to Docker Hub... "
22+
docker manifest push --purge rocketpool/smartnode-base:$VERSION
23+
docker manifest push --purge rocketpool/smartnode-base:latest
24+
echo "done!"
25+
}
26+
27+
# Print usage
28+
usage() {
29+
echo "Usage: build-release.sh [options] -v <version number>"
30+
echo "This script builds the base image for the Smartnode."
31+
echo "Options:"
32+
echo $'\t-a\tBuild all of the artifacts.'
33+
echo $'\t-d\tBuild the Docker image'
34+
echo $'\t-m\tBuild the Docker manifest'
35+
exit 0
36+
}
37+
38+
# =================
39+
# === Main Body ===
40+
# =================
41+
42+
# Get the version
43+
while getopts "admv:" FLAG; do
44+
case "$FLAG" in
45+
a) DOCKER=true MANIFEST=true ;;
46+
d) DOCKER=true ;;
47+
m) MANIFEST=true ;;
48+
v) VERSION="$OPTARG" ;;
49+
*) usage ;;
50+
esac
51+
done
52+
if [ -z "$VERSION" ]; then
53+
usage
54+
fi
55+
56+
# Build the artifacts
57+
if [ "$DOCKER" = true ]; then
58+
build_docker
59+
fi
60+
if [ "$MANIFEST" = true ]; then
61+
build_manifest
62+
fi

docker/build-builder.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Print usage
4+
usage() {
5+
echo "Usage: build-release.sh -v <version number>"
6+
echo "This script builds the Smartnode builder image used to build the daemon binaries."
7+
exit 0
8+
}
9+
10+
# =================
11+
# === Main Body ===
12+
# =================
13+
14+
# Get the version
15+
while getopts "admv:" FLAG; do
16+
case "$FLAG" in
17+
v) VERSION="$OPTARG" ;;
18+
*) usage ;;
19+
esac
20+
done
21+
if [ -z "$VERSION" ]; then
22+
usage
23+
fi
24+
25+
echo -n "Building Docker image... "
26+
docker build -t rocketpool/smartnode-builder:$VERSION -f smartnode-builder .
27+
docker tag rocketpool/smartnode-builder:$VERSION rocketpool/smartnode-builder:latest
28+
docker push rocketpool/smartnode-builder:$VERSION
29+
docker push rocketpool/smartnode-builder:latest
30+
echo "done!"

docker/smartnode-base

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This image provides the base layer for Smartnode images
2+
3+
# Start from Alpine image
4+
FROM alpine:latest
5+
6+
# Add C libraries and updates
7+
RUN apk update
8+
RUN apk upgrade
9+
RUN apk add --no-cache libgcc libstdc++ gcompat

docker/smartnode-builder

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This image is used to build the Rocket Pool Smartnode and related artifacts
2+
3+
FROM golang:1.19-buster
4+
5+
# Install build tools
6+
RUN dpkg --add-architecture arm64
7+
RUN apt update && apt install -y \
8+
build-essential \
9+
gcc-aarch64-linux-gnu \
10+
libc6-dev-arm64-cross\
11+
g++-aarch64-linux-gnu \
12+
wget
13+
14+
# Cache go dependencies
15+
ADD go.mod /src/go.mod
16+
ADD go.sum /src/go.sum
17+
WORKDIR /src
18+
RUN go mod download all
19+
WORKDIR /
20+
RUN rm -rf /src

rocketpool/build.sh

+6-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/bin/bash
22

3-
GO_VERSION=1.19
3+
export CGO_ENABLED=1
4+
cd /smartnode/rocketpool
45

5-
# Get CPU architecture
6-
UNAME_VAL=$(uname -m)
7-
ARCH=""
8-
case $UNAME_VAL in
9-
x86_64) ARCH="amd64" ;;
10-
aarch64) ARCH="arm64" ;;
11-
*) fail "CPU architecture not supported: $UNAME_VAL" ;;
12-
esac
6+
# Build x64 version
7+
CGO_CFLAGS="-O -D__BLST_PORTABLE__" GOARCH=amd64 GOOS=linux go build -o rocketpool-daemon-linux-amd64 rocketpool.go
138

14-
apt update
15-
apt dist-upgrade -y
16-
apt install build-essential git wget -y
17-
cd /tmp
18-
wget https://golang.org/dl/go${GO_VERSION}.linux-$ARCH.tar.gz
19-
rm -rf /usr/local/go && tar -C /usr/local -xzf go${GO_VERSION}.linux-$ARCH.tar.gz
20-
export PATH=$PATH:/usr/local/go/bin
21-
cd /smartnode/rocketpool
22-
CGO_CFLAGS="-O -D__BLST_PORTABLE__" go build -o rocketpool-daemon-linux-$ARCH rocketpool.go
9+
# Build the arm64 version
10+
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-cpp CGO_CFLAGS="-O -D__BLST_PORTABLE__" GOARCH=arm64 GOOS=linux go build -o rocketpool-daemon-linux-arm64 rocketpool.go

0 commit comments

Comments
 (0)