nimbus-eth2/docker/dist/entry_point.sh

221 lines
7.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Copyright (c) 2020-2021 Status Research & Development GmbH. Licensed under
# either of:
# - Apache License, version 2.0
# - MIT license
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
set -e
cd /home/user/nimbus-eth2
2020-11-07 07:46:53 +00:00
git config --global core.abbrev 8
if [[ -z "${1}" ]]; then
echo "Usage: $(basename ${0}) PLATFORM"
exit 1
fi
PLATFORM="${1}"
2021-11-30 12:31:43 +00:00
BINARIES="nimbus_beacon_node"
2020-11-06 16:26:03 +00:00
#- we need to build everything against libraries available inside this container, including the Nim compiler
2020-11-06 16:26:03 +00:00
make clean
Logging and startup improvements (#3038) * Logging and startup improvements Color support for released binaries! * startup scripts no longer log to file by default - this only affects source builds - released binaries don't support file logging * add --log-stdout option to control logging to stdout (colors, json) * detect tty:s vs redirected logs and log accordingly * add option to disable log colors at runtime * simplify several "common" logs, showing the most important information earlier and more clearly * remove line numbers / file information / tid - these take up space and are of little use to end users * still enabled in debug builds and tools * remove `testnet_servers_image` compile-time option * server images, released binaries and compile-from-source now offer the same behaviour and features * fixes https://github.com/status-im/nimbus-eth2/issues/2326 * fixes https://github.com/status-im/nimbus-eth2/issues/1794 * remove instanteneous block speed from sync message, keeping only average before: ``` INF 2021-10-28 16:45:59.000+02:00 Slot start topics="beacnde" tid=386429 file=nimbus_beacon_node.nim:884 lastSlot=2384027 wallSlot=2384028 delay=461us84ns peers=0 head=75a10ee5:3348 headEpoch=104 finalized=cd6804ba:3264 finalizedEpoch=102 sync="wwwwwwwwww:0:0.0000:0.0000:00h00m (3348)" INF 2021-10-28 16:45:59.046+02:00 Slot end topics="beacnde" tid=386429 file=nimbus_beacon_node.nim:821 slot=2384028 nextSlot=2384029 head=75a10ee5:3348 headEpoch=104 finalizedHead=cd6804ba:3264 finalizedEpoch=102 nextAttestationSlot=-1 nextProposalSlot=-1 nextActionWait=n/a ``` after: ``` INF 2021-10-28 22:43:23.033+02:00 Slot start topics="beacnde" slot=2385815 epoch=74556 sync="DDPDDPUDDD:10:5.2258:01h19m (2361088)" peers=37 head=eacd2dae:2361096 finalized=73782:a4751487 delay=33ms687us715ns INF 2021-10-28 22:43:23.291+02:00 Slot end topics="beacnde" slot=2385815 nextActionWait=n/a nextAttestationSlot=-1 nextProposalSlot=-1 head=eacd2dae:2361096 ``` * fix comment * documentation updates * mention `--log-file` may be deprecated in the future * update various docs
2021-11-02 17:06:36 +00:00
NIMFLAGS_COMMON="-d:disableMarchNative --gcc.options.debug:'-g1' --clang.options.debug:'-gline-tables-only'"
if [[ "${PLATFORM}" == "Windows_amd64" ]]; then
# Cross-compilation using the MXE distribution of Mingw-w64
export PATH="/usr/lib/mxe/usr/bin:${PATH}"
2021-05-05 06:55:39 +00:00
CC=x86_64-w64-mingw32.static-gcc
CXX=x86_64-w64-mingw32.static-g++
make \
-j$(nproc) \
USE_LIBBACKTRACE=0 \
2021-02-11 19:03:29 +00:00
QUICK_AND_DIRTY_COMPILER=1 \
deps-common build/generate_makefile
make \
-j$(nproc) \
-C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc \
-f Makefile.mingw \
CC="${CC}" \
libminiupnpc.a &>/dev/null
make \
-j$(nproc) \
-C vendor/nim-nat-traversal/vendor/libnatpmp-upstream \
CC="${CC}" \
CFLAGS="-Wall -Os -DWIN32 -DNATPMP_STATICLIB -DENABLE_STRNATPMPERR -DNATPMP_MAX_RETRIES=4 ${CFLAGS}" \
libnatpmp.a &>/dev/null
# We set CXX and add CXXFLAGS for libunwind's C++ code, even though we don't
# use those C++ objects. I don't see an easy way of disabling the C++ parts in
# libunwind itself.
#
# "libunwind.a" combines objects produced from C and C++ code. Even though we
# don't link any C++-generated objects, the linker still checks them for
# undefined symbols, so we're forced to use g++ as a linker wrapper.
# For some reason, macOS's Clang doesn't need this trick, nor do native (and
# newer) Mingw-w64 toolchains on Windows.
make \
-j$(nproc) \
CC="${CC}" \
CXX="${CXX}" \
CXXFLAGS="${CXXFLAGS} -D__STDC_FORMAT_MACROS -D_WIN32_WINNT=0x0600" \
USE_VENDORED_LIBUNWIND=1 \
LOG_LEVEL="TRACE" \
NIMFLAGS="${NIMFLAGS_COMMON} --os:windows --gcc.exe=${CC} --gcc.linkerexe=${CXX} --passL:-static" \
${BINARIES}
elif [[ "${PLATFORM}" == "Linux_arm32v7" ]]; then
CC="arm-linux-gnueabihf-gcc"
make \
-j$(nproc) \
USE_LIBBACKTRACE=0 \
QUICK_AND_DIRTY_COMPILER=1 \
deps-common build/generate_makefile
make \
-j$(nproc) \
LOG_LEVEL="TRACE" \
CC="${CC}" \
NIMFLAGS="${NIMFLAGS_COMMON} --cpu:arm --gcc.exe=${CC} --gcc.linkerexe=${CC}" \
PARTIAL_STATIC_LINKING=1 \
${BINARIES}
elif [[ "${PLATFORM}" == "Linux_arm64v8" ]]; then
CC="aarch64-linux-gnu-gcc"
make \
-j$(nproc) \
USE_LIBBACKTRACE=0 \
QUICK_AND_DIRTY_COMPILER=1 \
deps-common build/generate_makefile
make \
-j$(nproc) \
LOG_LEVEL="TRACE" \
CC="${CC}" \
NIMFLAGS="${NIMFLAGS_COMMON} --cpu:arm64 --gcc.exe=${CC} --gcc.linkerexe=${CC}" \
PARTIAL_STATIC_LINKING=1 \
${BINARIES}
2021-05-19 06:38:13 +00:00
elif [[ "${PLATFORM}" == "macOS_amd64" ]]; then
export PATH="/opt/osxcross/bin:${PATH}"
export OSXCROSS_MP_INC=1 # sets up include and library paths
export ZERO_AR_DATE=1 # avoid timestamps in binaries
DARWIN_VER="20.4"
CC="o64-clang"
make \
-j$(nproc) \
USE_LIBBACKTRACE=0 \
QUICK_AND_DIRTY_COMPILER=1 \
deps-common build/generate_makefile
make \
-j$(nproc) \
CC="${CC}" \
LIBTOOL="x86_64-apple-darwin${DARWIN_VER}-libtool" \
OS="darwin" \
NIMFLAGS="${NIMFLAGS_COMMON} --os:macosx --clang.exe=${CC}" \
2021-05-19 06:38:13 +00:00
nat-libs
make \
-j$(nproc) \
LOG_LEVEL="TRACE" \
CC="${CC}" \
AR="x86_64-apple-darwin${DARWIN_VER}-ar" \
RANLIB="x86_64-apple-darwin${DARWIN_VER}-ranlib" \
CMAKE="x86_64-apple-darwin${DARWIN_VER}-cmake" \
DSYMUTIL="x86_64-apple-darwin${DARWIN_VER}-dsymutil" \
FORCE_DSYMUTIL=1 \
USE_VENDORED_LIBUNWIND=1 \
NIMFLAGS="${NIMFLAGS_COMMON} --os:macosx --clang.exe=${CC} --clang.linkerexe=${CC}" \
2021-05-19 06:38:13 +00:00
${BINARIES}
elif [[ "${PLATFORM}" == "macOS_arm64" ]]; then
export PATH="/opt/osxcross/bin:${PATH}"
export OSXCROSS_MP_INC=1 # sets up include and library paths
export ZERO_AR_DATE=1 # avoid timestamps in binaries
DARWIN_VER="20.4"
CC="oa64-clang"
make \
-j$(nproc) \
USE_LIBBACKTRACE=0 \
QUICK_AND_DIRTY_COMPILER=1 \
deps-common build/generate_makefile
make \
-j$(nproc) \
CC="${CC}" \
LIBTOOL="arm64-apple-darwin${DARWIN_VER}-libtool" \
OS="darwin" \
NIMFLAGS="${NIMFLAGS_COMMON} --os:macosx --cpu:arm64 --clang.exe=${CC}" \
2021-05-19 06:38:13 +00:00
nat-libs
make \
-j$(nproc) \
LOG_LEVEL="TRACE" \
CC="${CC}" \
AR="arm64-apple-darwin${DARWIN_VER}-ar" \
RANLIB="arm64-apple-darwin${DARWIN_VER}-ranlib" \
CMAKE="arm64-apple-darwin${DARWIN_VER}-cmake" \
DSYMUTIL="arm64-apple-darwin${DARWIN_VER}-dsymutil" \
FORCE_DSYMUTIL=1 \
USE_VENDORED_LIBUNWIND=1 \
NIMFLAGS="${NIMFLAGS_COMMON} --os:macosx --cpu:arm64 --clang.exe=${CC} --clang.linkerexe=${CC}" \
2021-05-19 06:38:13 +00:00
${BINARIES}
else
# Linux AMD64
make \
-j$(nproc) \
LOG_LEVEL="TRACE" \
NIMFLAGS="${NIMFLAGS_COMMON}" \
PARTIAL_STATIC_LINKING=1 \
2021-02-11 19:03:29 +00:00
QUICK_AND_DIRTY_COMPILER=1 \
${BINARIES}
fi
2020-11-06 16:26:03 +00:00
# archive directory (we need the Nim compiler in here)
PREFIX="nimbus-eth2_${PLATFORM}_"
GIT_COMMIT="$(git rev-parse --short HEAD)"
2020-11-06 16:26:03 +00:00
VERSION="$(./env.sh nim --verbosity:0 --hints:off --warnings:off scripts/print_version.nims)"
2020-11-07 07:46:53 +00:00
DIR="${PREFIX}${VERSION}_${GIT_COMMIT}"
DIST_PATH="dist/${DIR}"
# delete old artefacts
rm -rf "dist/${PREFIX}"*.tar.gz
2020-11-07 07:46:53 +00:00
if [[ -d "${DIST_PATH}" ]]; then
rm -rf "${DIST_PATH}"
fi
2020-11-09 08:12:48 +00:00
mkdir -p "${DIST_PATH}"
mkdir "${DIST_PATH}/scripts"
mkdir "${DIST_PATH}/build"
2020-11-06 16:26:03 +00:00
# copy and checksum binaries, copy scripts and docs
for BINARY in ${BINARIES}; do
cp -a "./build/${BINARY}" "${DIST_PATH}/build/"
2021-05-19 06:38:13 +00:00
if [[ "${PLATFORM}" =~ macOS ]]; then
# debug info
cp -a "./build/${BINARY}.dSYM" "${DIST_PATH}/build/"
fi
cd "${DIST_PATH}/build"
sha512sum "${BINARY}" > "${BINARY}.sha512sum"
if [[ "${PLATFORM}" == "Windows_amd64" ]]; then
mv "${BINARY}" "${BINARY}.exe"
fi
cd - >/dev/null
done
sed -e "s/GIT_COMMIT/${GIT_COMMIT}/" docker/dist/README.md.tpl > "${DIST_PATH}/README.md"
2021-02-06 20:22:25 +00:00
if [[ "${PLATFORM}" == "Linux_amd64" ]]; then
sed -i -e 's/^make dist$/make dist-amd64/' "${DIST_PATH}/README.md"
elif [[ "${PLATFORM}" == "Linux_arm32v7" ]]; then
sed -i -e 's/^make dist$/make dist-arm/' "${DIST_PATH}/README.md"
elif [[ "${PLATFORM}" == "Linux_arm64v8" ]]; then
sed -i -e 's/^make dist$/make dist-arm64/' "${DIST_PATH}/README.md"
elif [[ "${PLATFORM}" == "Windows_amd64" ]]; then
sed -i -e 's/^make dist$/make dist-win64/' "${DIST_PATH}/README.md"
cp -a docker/dist/README-Windows.md.tpl "${DIST_PATH}/README-Windows.md"
2021-05-19 06:38:13 +00:00
elif [[ "${PLATFORM}" == "macOS_amd64" ]]; then
sed -i -e 's/^make dist$/make dist-macos/' "${DIST_PATH}/README.md"
elif [[ "${PLATFORM}" == "macOS_arm64" ]]; then
sed -i -e 's/^make dist$/make dist-macos-arm64/' "${DIST_PATH}/README.md"
fi
2021-02-06 20:22:25 +00:00
2020-11-09 08:12:48 +00:00
cp -a scripts/run-beacon-node.sh "${DIST_PATH}/scripts"
cp -a ./run-*-beacon-node.sh "${DIST_PATH}/"
# create the tarball
cd dist
tar czf "${DIR}.tar.gz" "${DIR}"
# don't leave the directory hanging around
rm -rf "${DIR}"
cd - >/dev/null