2020-11-07 10:49:53 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ "${USER}" != "{{ beacon_node_builds_user }}" ]]; then
|
|
|
|
echo "Incorrect user: ${USER}" >&2
|
|
|
|
echo "Expected: {{ beacon_node_builds_user }}" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-11-08 23:53:16 +00:00
|
|
|
IMAGE="{{ beacon_node_builds_image_name }}"
|
|
|
|
TAG="{{ item.name }}"
|
2020-11-07 10:49:53 +00:00
|
|
|
|
|
|
|
# Build the Beacon node binaries
|
2020-11-08 23:53:16 +00:00
|
|
|
pushd repo
|
|
|
|
|
|
|
|
COMMIT_BEFORE=$(git rev-parse --short=8 HEAD)
|
2021-02-04 22:47:59 +00:00
|
|
|
SYMBOLIC_NAME=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD)
|
|
|
|
|
|
|
|
function headIsDetached() { [[ "${SYMBOLIC_NAME}" == "HEAD" ]]; }
|
|
|
|
|
|
|
|
# Detached HEAD means we're probably on a tag
|
|
|
|
if headIsDetached; then
|
|
|
|
echo "Deatached HEAD, nothing to fetch."
|
|
|
|
else
|
|
|
|
# We cannot use "git pull" in here, because history may be changed upstream
|
|
|
|
git fetch
|
|
|
|
git reset --hard origin/{{ item.version }}
|
|
|
|
fi
|
|
|
|
|
2020-11-08 23:53:16 +00:00
|
|
|
COMMIT_AFTER=$(git rev-parse --short=8 HEAD)
|
|
|
|
|
|
|
|
if [[ "$1" == "--force" ]]; then
|
|
|
|
echo "Forcing rebuild!"
|
2021-02-04 22:47:59 +00:00
|
|
|
elif ! headIsDetached && [[ "${COMMIT_BEFORE}" == "${COMMIT_AFTER}" ]]; then
|
2020-11-08 23:53:16 +00:00
|
|
|
echo "Nothing new to build."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2020-11-12 01:29:17 +00:00
|
|
|
# Lower CPU and I/O priority so it doesn't affect the running beacon node
|
|
|
|
NICE="nice -n 19 ionice -c2 -n7"
|
|
|
|
|
2020-11-20 15:44:48 +00:00
|
|
|
${NICE} make -j1 update
|
|
|
|
${NICE} make -j1 {{ item.targets | join(" ") }} \
|
2020-12-15 17:20:53 +00:00
|
|
|
LOG_LEVEL="TRACE" NIMFLAGS="-d:insecure -d:testnet_servers_image -d:noSignalHandler"
|
|
|
|
|
|
|
|
# Keep some copies of the resulting binaries, to be used for debugging in case of core dumps
|
|
|
|
cp -a build/nimbus_beacon_node "build/nimbus_beacon_node_{{ item.name }}_$(date +%F_%H-%M-%S)"
|
|
|
|
# Delete copies that are older than 7 days
|
|
|
|
find build -name 'nimbus_beacon_node_*' -mtime +7 -exec rm '{}' \+
|
2020-11-08 23:53:16 +00:00
|
|
|
|
|
|
|
popd
|
2020-11-07 10:49:53 +00:00
|
|
|
|
|
|
|
# Add binary into a simple Alpine image
|
2021-02-22 15:05:56 +00:00
|
|
|
docker build -t "${IMAGE}:${COMMIT_AFTER}" \
|
|
|
|
--label "commit=${COMMIT_AFTER}" \
|
|
|
|
--build-arg=COMMIT=${COMMIT_AFTER} .
|
2020-11-08 23:53:16 +00:00
|
|
|
docker tag "${IMAGE}:${COMMIT_AFTER}" "${IMAGE}:${TAG}"
|
|
|
|
docker push "${IMAGE}:${TAG}"
|
|
|
|
|
|
|
|
echo "SUCCESS - pushed: ${IMAGE}:${TAG}"
|