2020-11-07 10:49:53 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-06-01 19:26:42 +00:00
|
|
|
# vim: ft=sh
|
2020-11-07 10:49:53 +00:00
|
|
|
set -e
|
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
function headIsDetached() {
|
|
|
|
[[ $(git rev-parse --abbrev-ref --symbolic-full-name HEAD) == "HEAD" ]];
|
|
|
|
}
|
|
|
|
|
|
|
|
function dockerImageExists() {
|
|
|
|
docker image inspect "${IMAGE}:${COMMIT}" 2>&1 1>/dev/null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function binaryExists() {
|
2021-08-18 10:43:51 +00:00
|
|
|
ls -l build/nimbus_beacon_node_${COMMIT} 2>&1 1>/dev/null
|
2021-05-20 22:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fetchChanges() {
|
|
|
|
# We cannot use "git pull" in here, because history may be changed upstream
|
|
|
|
git fetch
|
|
|
|
git reset --hard "origin/${BRANCH}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildBinaries() {
|
|
|
|
# Lower CPU and I/O priority so it doesn't affect the running beacon node
|
|
|
|
NICE="nice -n 19 ionice -c2 -n7"
|
|
|
|
|
|
|
|
${NICE} make -j1 update
|
2021-08-18 10:43:51 +00:00
|
|
|
${NICE} make -j1 nimbus_beacon_node nimbus_signing_process \
|
2021-05-20 22:38:03 +00:00
|
|
|
LOG_LEVEL="TRACE" NIMFLAGS="-d:testnet_servers_image -d:noSignalHandler"
|
|
|
|
|
|
|
|
# Rename binaries to match commit the were built from.
|
2021-08-18 10:43:51 +00:00
|
|
|
mv "build/nimbus_beacon_node" "build/nimbus_beacon_node_${COMMIT}"
|
|
|
|
mv "build/nimbus_signing_process" "build/nimbus_signing_process_${COMMIT}"
|
2021-05-20 22:38:03 +00:00
|
|
|
|
|
|
|
# Delete copies that are older than 7 days
|
|
|
|
find build -mtime +7 -exec rm '{}' \+
|
|
|
|
}
|
|
|
|
|
|
|
|
# Adds binary into a simple Alpine image
|
|
|
|
function buildDockerImage() {
|
|
|
|
docker build -t "${IMAGE}:${COMMIT}" \
|
|
|
|
--build-arg=COMMIT=${COMMIT} \
|
|
|
|
--label "commit=${COMMIT}" .
|
|
|
|
}
|
|
|
|
|
|
|
|
function pushImageTag() {
|
|
|
|
docker tag "${IMAGE}:${COMMIT}" "${IMAGE}:${TAG}"
|
|
|
|
docker push "${IMAGE}:${TAG}"
|
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BRANCH="{{ item.version }}"
|
|
|
|
IMAGE="{{ beacon_node_builds_image_name }}"
|
|
|
|
TAG="{{ item.name }}"
|
|
|
|
|
2020-11-07 10:49:53 +00:00
|
|
|
if [[ "${USER}" != "{{ beacon_node_builds_user }}" ]]; then
|
|
|
|
echo "Incorrect user: ${USER}" >&2
|
|
|
|
echo "Expected: {{ beacon_node_builds_user }}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Build the Beacon node binaries
|
2021-05-20 22:38:03 +00:00
|
|
|
pushd repo >/dev/null
|
2021-02-04 22:47:59 +00:00
|
|
|
|
|
|
|
# Detached HEAD means we're probably on a tag
|
|
|
|
if headIsDetached; then
|
2021-05-20 22:38:03 +00:00
|
|
|
echo " >>> Deatached HEAD, nothing to fetch."
|
2021-02-04 22:47:59 +00:00
|
|
|
else
|
2021-05-20 22:38:03 +00:00
|
|
|
echo " >>> Fetching changes..."
|
|
|
|
fetchChanges
|
2021-02-04 22:47:59 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
COMMIT=$(git rev-parse --short=8 HEAD)
|
2020-11-08 23:53:16 +00:00
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
if binaryExists && [[ "$1" != "--force" ]]; then
|
|
|
|
echo " >>> Binary already built"
|
|
|
|
else
|
|
|
|
echo " >>> Building binaries..."
|
|
|
|
buildBinaries
|
2020-11-08 23:53:16 +00:00
|
|
|
fi
|
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
popd >/dev/null
|
2020-12-15 17:20:53 +00:00
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
if dockerImageExists && [[ "$1" != "--force" ]]; then
|
|
|
|
echo " >>> Image already built: ${IMAGE}:${COMMIT}"
|
|
|
|
else
|
|
|
|
echo " >>> Building Docker image..."
|
|
|
|
buildDockerImage
|
|
|
|
fi
|
2020-11-07 10:49:53 +00:00
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
echo " >>> Pushing Docker image..."
|
|
|
|
pushImageTag
|
2020-11-08 23:53:16 +00:00
|
|
|
|
2021-05-20 22:38:03 +00:00
|
|
|
echo " >>> SUCCESS - Pushed: ${IMAGE}:${TAG}"
|