@cryptotaxi247 / netdata-1 / commits / a20e8f163

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

James Mills committed May 26, 2020 at 12:19 UTC a20e8f163fde7d64cbc258b6903230dda651adf9
7 files changed +220 -71
.github/scripts/build-static-x86_64.sh new
+58
@@ -0,0 +1,58 @@
1 +#!/bin/sh
2 +#
3 +# Builds the netdata-vX.Y.Z-xxxx.gz.run (static x86_64) artifact.
4 +
5 +set -e
6 +
7 +# shellcheck source=.github/scripts/functions.sh
8 +. "$(dirname "$0")/functions.sh"
9 +
10 +NAME="${NAME:-netdata}"
11 +VERSION="${VERSION:-"$(git describe)"}"
12 +BASENAME="$NAME-$VERSION"
13 +
14 +prepare_build() {
15 + progress "Preparing build"
16 + (
17 + test -d artifacts || mkdir -p artifacts
18 + ) >&2
19 +}
20 +
21 +build_static_x86_64() {
22 + progress "Building static x86_64"
23 + (
24 + USER="" ./packaging/makeself/build-x86_64-static.sh
25 + ) >&2
26 +}
27 +
28 +prepare_assets() {
29 + progress "Preparing assets"
30 + (
31 + cp packaging/version artifacts/latest-version.txt
32 +
33 + cd artifacts || exit 1
34 + ln -s "${BASENAME}.gz.run" netdata-latest.gz.run
35 + sha256sum -b ./* > "sha256sums.txt"
36 + ) >&2
37 +}
38 +
39 +steps="prepare_build build_static_x86_64"
40 +steps="$steps prepare_assets"
41 +
42 +_main() {
43 + for step in $steps; do
44 + if ! run "$step"; then
45 + if [ -t 1 ]; then
46 + debug
47 + else
48 + fail "Build failed"
49 + fi
50 + fi
51 + done
52 +
53 + echo "🎉 All Done!"
54 +}
55 +
56 +if [ -n "$0" ] && [ x"$0" != x"-bash" ]; then
57 + _main "$@"
58 +fi
.github/scripts/functions.sh new
+69
@@ -0,0 +1,69 @@
1 +#!/bin/sh
2 +
3 +# This file is included by download.sh & build.sh
4 +
5 +set -e
6 +
7 +color() {
8 + fg="$1"
9 + bg="${2}"
10 + ft="${3:-0}"
11 +
12 + printf "\33[%s;%s;%s" "$ft" "$fg" "$bg"
13 +}
14 +
15 +color_reset() {
16 + printf "\033[0m"
17 +}
18 +
19 +ok() {
20 + if [ -t 1 ]; then
21 + printf "%s[ OK ]%s\n" "$(color 37 42m 1)" "$(color_reset)"
22 + else
23 + printf "%s\n" "[ OK ]"
24 + fi
25 +}
26 +
27 +err() {
28 + if [ -t 1 ]; then
29 + printf "%s[ ERR ]%s\n" "$(color 37 41m 1)" "$(color_reset)"
30 + else
31 + printf "%s\n" "[ ERR ]"
32 + fi
33 +}
34 +
35 +run() {
36 + retval=0
37 + logfile="$(mktemp -t "run-XXXXXX")"
38 + if "$@" 2> "$logfile"; then
39 + ok
40 + else
41 + retval=$?
42 + err
43 + tail -n 100 "$logfile" || true
44 + fi
45 + rm -rf "$logfile"
46 + return $retval
47 +}
48 +
49 +progress() {
50 + printf "%-40s" "$(printf "%s ... " "$1")"
51 +}
52 +
53 +log() {
54 + printf "%s\n" "$1"
55 +}
56 +
57 +error() {
58 + log "ERROR: ${1}"
59 +}
60 +
61 +fail() {
62 + log "FATAL: ${1}"
63 + exit 1
64 +}
65 +
66 +debug() {
67 + log "Dropping into a shell for debugging ..."
68 + exec /bin/sh
69 +}
.github/workflows/build-and-install.yml
+12 -1
@@ -6,7 +6,18 @@ on:
6 - master
7 pull_request:
8 jobs:
9 - build:
9 + static-build:
10 + name: Build (x86_64)
11 + runs-on: ubuntu-latest
12 + steps:
13 + - name: Git clone repository
14 + uses: actions/checkout@v2
15 + - run: |
16 + git fetch --prune --unshallow --tags
17 + - name: Build
18 + run: |
19 + .github/scripts/build-static-x86_64.sh
20 + source-build:
21 name: Build & Install
22 strategy:
23 fail-fast: false
packaging/makeself/build-x86_64-static.sh
+10 -4
@@ -32,10 +32,16 @@ if ! docker inspect "${DOCKER_CONTAINER_NAME}" > /dev/null 2>&1; then
32 fi
33
34 # Run the build script inside the container
35 -run docker run -a stdin -a stdout -a stderr -i -t -v \
36 - "$(pwd)":/usr/src/netdata.git:rw \
37 - "${DOCKER_CONTAINER_NAME}" \
38 - /bin/sh /usr/src/netdata.git/packaging/makeself/build.sh "${@}"
35 +if [ -t 1 ]; then
36 + run docker run -a stdin -a stdout -a stderr -i -t -v \
37 + "$(pwd)":/usr/src/netdata.git:rw \
38 + "${DOCKER_CONTAINER_NAME}" \
39 + /bin/sh /usr/src/netdata.git/packaging/makeself/build.sh "${@}"
40 +else
41 + run docker run -v "$(pwd)":/usr/src/netdata.git:rw \
42 + "${DOCKER_CONTAINER_NAME}" \
43 + /bin/sh /usr/src/netdata.git/packaging/makeself/build.sh "${@}"
44 +fi
45
46 if [ "${USER}" ]; then
47 sudo chown -R "${USER}" .
packaging/makeself/build.sh
+24 -26
@@ -6,20 +6,18 @@
6
7 export NETDATA_BUILD_WITH_DEBUG=0
8
9 -while [ ! -z "${1}" ]
10 -do
11 - case "${1}" in
12 - debug)
13 - export NETDATA_BUILD_WITH_DEBUG=1
14 - ;;
15 -
16 - *)
17 - ;;
18 - esac
19 -
20 - shift
21 -done
9 +while [ -n "${1}" ]; do
10 + case "${1}" in
11 + debug)
12 + export NETDATA_BUILD_WITH_DEBUG=1
13 + ;;
14 +
15 + *) ;;
16
17 + esac
18 +
19 + shift
20 +done
21
22 # -----------------------------------------------------------------------------
23
@@ -27,19 +25,18 @@ done
25 # the required packages. build-x86_64-static.sh will do this for you
26 # using docker.
27
30 -cd $(dirname "$0") || exit 1
28 +cd "$(dirname "$0")" || exit 1
29
30 # if we don't run inside the netdata repo
31 # download it and run from it
34 -if [ ! -f ../../netdata-installer.sh ]
35 -then
36 - git clone https://github.com/netdata/netdata.git netdata.git || exit 1
37 - cd netdata.git/makeself || exit 1
38 - ./build.sh "$@"
39 - exit $?
32 +if [ ! -f ../../netdata-installer.sh ]; then
33 + git clone https://github.com/netdata/netdata.git netdata.git || exit 1
34 + cd netdata.git/makeself || exit 1
35 + ./build.sh "$@"
36 + exit $?
37 fi
38
42 -cat >&2 <<EOF
39 +cat >&2 << EOF
40
41 This program will create a self-extracting shell package containing
42 a statically linked netdata, able to run on any 64bit Linux system,
@@ -52,10 +49,11 @@ EOF
49
50 # read -p "Press ENTER to continue > "
51
55 -if [ ! -d tmp ]
56 - then
57 - mkdir tmp || exit 1
52 +if [ ! -d tmp ]; then
53 + mkdir tmp || exit 1
54 fi
55
60 -./run-all-jobs.sh "$@"
61 -exit $?
56 +if ! ./run-all-jobs.sh "$@"; then
57 + printf >&2 "Build failed."
58 + exit 1
59 +fi
packaging/makeself/install-alpine-packages.sh
+28 -27
@@ -12,32 +12,33 @@ apk update
12
13 # Add required APK packages
14 apk add --no-cache \
15 - bash \
16 - wget \
17 - curl \
18 - ncurses \
19 - git \
20 - netcat-openbsd \
21 - alpine-sdk \
22 - autoconf \
23 - automake \
24 - gcc \
25 - make \
26 - cmake \
27 - libtool \
28 - pkgconfig \
29 - util-linux-dev \
30 - openssl-dev \
31 - gnutls-dev \
32 - zlib-dev \
33 - libmnl-dev \
34 - libnetfilter_acct-dev \
35 - libuv-dev \
36 - lz4-dev \
37 - openssl-dev \
38 - snappy-dev \
39 - protobuf-dev \
40 - || exit 1
15 + bash \
16 + wget \
17 + curl \
18 + ncurses \
19 + git \
20 + netcat-openbsd \
21 + alpine-sdk \
22 + autoconf \
23 + automake \
24 + gcc \
25 + make \
26 + cmake \
27 + libtool \
28 + pkgconfig \
29 + util-linux-dev \
30 + openssl-dev \
31 + gnutls-dev \
32 + zlib-dev \
33 + libmnl-dev \
34 + libnetfilter_acct-dev \
35 + libuv-dev \
36 + lz4-dev \
37 + openssl-dev \
38 + snappy-dev \
39 + protobuf-dev \
40 + binutils ||
41 + exit 1
42
43 # snappy doesnt have static version in alpine, let's compile it
44 export SNAPPY_VER="1.1.7"
@@ -60,4 +61,4 @@ rm judy.tar.gz
61 cd /judy-${JUDY_VER}
62 CFLAGS="-O2 -s" CXXFLAGS="-O2 -s" ./configure
63 make
63 -make install;
64 +make install
packaging/makeself/jobs/70-netdata-git.install.sh
+19 -13
@@ -1,15 +1,15 @@
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: GPL-3.0-or-later
3
4 -. ${NETDATA_MAKESELF_PATH}/functions.sh "${@}" || exit 1
4 +# shellcheck source=./packaging/makeself/functions.sh
5 +. "${NETDATA_MAKESELF_PATH}"/functions.sh "${@}" || exit 1
6
7 cd "${NETDATA_SOURCE_PATH}" || exit 1
8
8 -if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
9 -then
10 - export CFLAGS="-static -O3"
9 +if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]; then
10 + export CFLAGS="-static -O3"
11 else
12 - export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness -fstack-protector-all -D_FORTIFY_SOURCE=2 -DNETDATA_INTERNAL_CHECKS=1"
12 + export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness -fstack-protector-all -D_FORTIFY_SOURCE=2 -DNETDATA_INTERNAL_CHECKS=1"
13 # export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness"
14 fi
15
@@ -18,16 +18,22 @@ fi
18 export IS_NETDATA_STATIC_BINARY="yes"
19
20 run ./netdata-installer.sh --install "${NETDATA_INSTALL_PARENT}" \
21 - --dont-wait \
22 - --dont-start-it \
23 - ${NULL}
21 + --dont-wait \
22 + --dont-start-it \
23 + "${NULL}"
24
25 # Remove the netdata.conf file from the tree. It has hard-coded sensible defaults builtin.
26 rm -f "${NETDATA_INSTALL_PARENT}/etc/netdata/netdata.conf"
27
28 -if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
29 -then
30 - run strip ${NETDATA_INSTALL_PATH}/bin/netdata
31 - run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/apps.plugin
32 - run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/cgroup-network
28 +# Ensure the netdata binary is in fact statically linked
29 +if run readelf -l "${NETDATA_INSTALL_PATH}"/bin/netdata | grep 'INTERP'; then
30 + printf >&2 "Ooops. %s is not a statically linked binary!\n" "${NETDATA_INSTALL_PATH}"/bin/netdata
31 + ldd "${NETDATA_INSTALL_PATH}"/bin/netdata
32 + exit 1
33 +fi
34 +
35 +if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]; then
36 + run strip "${NETDATA_INSTALL_PATH}"/bin/netdata
37 + run strip "${NETDATA_INSTALL_PATH}"/usr/libexec/netdata/plugins.d/apps.plugin
38 + run strip "${NETDATA_INSTALL_PATH}"/usr/libexec/netdata/plugins.d/cgroup-network
39 fi