diff options
author | James Mills <prologic@shortcircuit.net.au> | 2020-05-26 12:19:27 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 12:19:27 +1000 |
commit | a20e8f163fde7d64cbc258b6903230dda651adf9 (patch) | |
tree | e39afc950b1740c4853a346eb8a98f3f72f2e1ef /packaging | |
parent | b5f5675cb53d4b2f276666b55ef582aa8ba7a574 (diff) |
Add CI for our Static Netdata builds (which kickstart-static64 uses) (#9130)
* Add tool to build the static x864_64 Netdata
* Add error if the netdata binary is not statically linked
* Add Github Workflow for testing static builds
* Don't use docker run -i -t if not on a tty
Diffstat (limited to 'packaging')
-rwxr-xr-x | packaging/makeself/build-x86_64-static.sh | 14 | ||||
-rwxr-xr-x | packaging/makeself/build.sh | 50 | ||||
-rwxr-xr-x | packaging/makeself/install-alpine-packages.sh | 55 | ||||
-rwxr-xr-x | packaging/makeself/jobs/70-netdata-git.install.sh | 32 |
4 files changed, 81 insertions, 70 deletions
diff --git a/packaging/makeself/build-x86_64-static.sh b/packaging/makeself/build-x86_64-static.sh index 7326dd2055..dca6f1ae08 100755 --- a/packaging/makeself/build-x86_64-static.sh +++ b/packaging/makeself/build-x86_64-static.sh @@ -32,10 +32,16 @@ if ! docker inspect "${DOCKER_CONTAINER_NAME}" > /dev/null 2>&1; then fi # Run the build script inside the container -run docker run -a stdin -a stdout -a stderr -i -t -v \ - "$(pwd)":/usr/src/netdata.git:rw \ - "${DOCKER_CONTAINER_NAME}" \ - /bin/sh /usr/src/netdata.git/packaging/makeself/build.sh "${@}" +if [ -t 1 ]; then + run docker run -a stdin -a stdout -a stderr -i -t -v \ + "$(pwd)":/usr/src/netdata.git:rw \ + "${DOCKER_CONTAINER_NAME}" \ + /bin/sh /usr/src/netdata.git/packaging/makeself/build.sh "${@}" +else + run docker run -v "$(pwd)":/usr/src/netdata.git:rw \ + "${DOCKER_CONTAINER_NAME}" \ + /bin/sh /usr/src/netdata.git/packaging/makeself/build.sh "${@}" +fi if [ "${USER}" ]; then sudo chown -R "${USER}" . diff --git a/packaging/makeself/build.sh b/packaging/makeself/build.sh index e5804c5237..108f0ec8d3 100755 --- a/packaging/makeself/build.sh +++ b/packaging/makeself/build.sh @@ -6,20 +6,18 @@ export NETDATA_BUILD_WITH_DEBUG=0 -while [ ! -z "${1}" ] -do - case "${1}" in - debug) - export NETDATA_BUILD_WITH_DEBUG=1 - ;; - - *) - ;; - esac - - shift -done +while [ -n "${1}" ]; do + case "${1}" in + debug) + export NETDATA_BUILD_WITH_DEBUG=1 + ;; + + *) ;; + esac + + shift +done # ----------------------------------------------------------------------------- @@ -27,19 +25,18 @@ done # the required packages. build-x86_64-static.sh will do this for you # using docker. -cd $(dirname "$0") || exit 1 +cd "$(dirname "$0")" || exit 1 # if we don't run inside the netdata repo # download it and run from it -if [ ! -f ../../netdata-installer.sh ] -then - git clone https://github.com/netdata/netdata.git netdata.git || exit 1 - cd netdata.git/makeself || exit 1 - ./build.sh "$@" - exit $? +if [ ! -f ../../netdata-installer.sh ]; then + git clone https://github.com/netdata/netdata.git netdata.git || exit 1 + cd netdata.git/makeself || exit 1 + ./build.sh "$@" + exit $? fi -cat >&2 <<EOF +cat >&2 << EOF This program will create a self-extracting shell package containing a statically linked netdata, able to run on any 64bit Linux system, @@ -52,10 +49,11 @@ EOF # read -p "Press ENTER to continue > " -if [ ! -d tmp ] - then - mkdir tmp || exit 1 +if [ ! -d tmp ]; then + mkdir tmp || exit 1 fi -./run-all-jobs.sh "$@" -exit $? +if ! ./run-all-jobs.sh "$@"; then + printf >&2 "Build failed." + exit 1 +fi diff --git a/packaging/makeself/install-alpine-packages.sh b/packaging/makeself/install-alpine-packages.sh index 7872f2bcf7..3aee6922d0 100755 --- a/packaging/makeself/install-alpine-packages.sh +++ b/packaging/makeself/install-alpine-packages.sh @@ -12,32 +12,33 @@ apk update # Add required APK packages apk add --no-cache \ - bash \ - wget \ - curl \ - ncurses \ - git \ - netcat-openbsd \ - alpine-sdk \ - autoconf \ - automake \ - gcc \ - make \ - cmake \ - libtool \ - pkgconfig \ - util-linux-dev \ - openssl-dev \ - gnutls-dev \ - zlib-dev \ - libmnl-dev \ - libnetfilter_acct-dev \ - libuv-dev \ - lz4-dev \ - openssl-dev \ - snappy-dev \ - protobuf-dev \ - || exit 1 + bash \ + wget \ + curl \ + ncurses \ + git \ + netcat-openbsd \ + alpine-sdk \ + autoconf \ + automake \ + gcc \ + make \ + cmake \ + libtool \ + pkgconfig \ + util-linux-dev \ + openssl-dev \ + gnutls-dev \ + zlib-dev \ + libmnl-dev \ + libnetfilter_acct-dev \ + libuv-dev \ + lz4-dev \ + openssl-dev \ + snappy-dev \ + protobuf-dev \ + binutils || + exit 1 # snappy doesnt have static version in alpine, let's compile it export SNAPPY_VER="1.1.7" @@ -60,4 +61,4 @@ rm judy.tar.gz cd /judy-${JUDY_VER} CFLAGS="-O2 -s" CXXFLAGS="-O2 -s" ./configure make -make install; +make install diff --git a/packaging/makeself/jobs/70-netdata-git.install.sh b/packaging/makeself/jobs/70-netdata-git.install.sh index 238fc4817f..923c29667f 100755 --- a/packaging/makeself/jobs/70-netdata-git.install.sh +++ b/packaging/makeself/jobs/70-netdata-git.install.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash # SPDX-License-Identifier: GPL-3.0-or-later -. ${NETDATA_MAKESELF_PATH}/functions.sh "${@}" || exit 1 +# shellcheck source=./packaging/makeself/functions.sh +. "${NETDATA_MAKESELF_PATH}"/functions.sh "${@}" || exit 1 cd "${NETDATA_SOURCE_PATH}" || exit 1 -if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ] -then - export CFLAGS="-static -O3" +if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]; then + export CFLAGS="-static -O3" else - export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness -fstack-protector-all -D_FORTIFY_SOURCE=2 -DNETDATA_INTERNAL_CHECKS=1" + export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness -fstack-protector-all -D_FORTIFY_SOURCE=2 -DNETDATA_INTERNAL_CHECKS=1" # export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness" fi @@ -18,16 +18,22 @@ fi export IS_NETDATA_STATIC_BINARY="yes" run ./netdata-installer.sh --install "${NETDATA_INSTALL_PARENT}" \ - --dont-wait \ - --dont-start-it \ - ${NULL} + --dont-wait \ + --dont-start-it \ + "${NULL}" # Remove the netdata.conf file from the tree. It has hard-coded sensible defaults builtin. rm -f "${NETDATA_INSTALL_PARENT}/etc/netdata/netdata.conf" -if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ] -then - run strip ${NETDATA_INSTALL_PATH}/bin/netdata - run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/apps.plugin - run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/cgroup-network +# Ensure the netdata binary is in fact statically linked +if run readelf -l "${NETDATA_INSTALL_PATH}"/bin/netdata | grep 'INTERP'; then + printf >&2 "Ooops. %s is not a statically linked binary!\n" "${NETDATA_INSTALL_PATH}"/bin/netdata + ldd "${NETDATA_INSTALL_PATH}"/bin/netdata + exit 1 +fi + +if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]; then + run strip "${NETDATA_INSTALL_PATH}"/bin/netdata + run strip "${NETDATA_INSTALL_PATH}"/usr/libexec/netdata/plugins.d/apps.plugin + run strip "${NETDATA_INSTALL_PATH}"/usr/libexec/netdata/plugins.d/cgroup-network fi |