infra-nimbus/ansible/roles/beacon-node-builds/templates/build.sh.j2

45 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/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
IMAGE="{{ beacon_node_builds_image_name }}"
TAG="{{ item.name }}"
# Build the Beacon node binaries
pushd repo
COMMIT_BEFORE=$(git rev-parse --short=8 HEAD)
# We cannot use "git pull" in here, because history may be changed upstream
git fetch
git reset --hard origin/{{ item.branch }}
COMMIT_AFTER=$(git rev-parse --short=8 HEAD)
if [[ "$1" == "--force" ]]; then
echo "Forcing rebuild!"
elif [[ "${COMMIT_BEFORE}" == "${COMMIT_AFTER}" ]]; then
echo "Nothing new to build."
exit
fi
# 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
${NICE} make -j1 {{ item.targets | join(" ") }} \
LOG_LEVEL="TRACE" NIMFLAGS="-d:insecure -d:testnet_servers_image"
popd
# Add binary into a simple Alpine image
docker build -t "${IMAGE}:${COMMIT_AFTER}" --build-arg=COMMIT=${COMMIT_AFTER} .
docker tag "${IMAGE}:${COMMIT_AFTER}" "${IMAGE}:${TAG}"
docker push "${IMAGE}:${TAG}"
echo "SUCCESS - pushed: ${IMAGE}:${TAG}"