@cryptotaxi247 / netdata-1 / commits / d307ba7ec

Adds Docker based build system for Binary Packages, CI/CD, Smoke Testing and Development. (#7735)

* Added Dockerfile for building, packaging and performing basic smoke tests of the package(s) and NetData Agent itself * Moved install of package per distro into a script and refactor in order to supprot other distro(s) * Add support for RPM based systems too (Fedora, CentOS) * Drop the unnecessary (for now) Debian cleanup steps * Reverse the order of installing NetData agent and testing tools * Update default VERSION to 0.1 to match builder images * Added support for openSUSE * Minor fixes from review * Update Dockerfile Co-Authored-By: Austin S. Hemmelgarn <ahferroin7@gmail.com> * Update Dockerfile Co-Authored-By: Austin S. Hemmelgarn <ahferroin7@gmail.com> * Move thigns around a bit * Re-update test/install shell scripts to be POSIX. We don't really want to depend on Bash here * Fixed support for yum vs. dnf * Fixed paths to scripts * Added a script to kick off the build/package/install/test flow more easily for both humans and CI/CD Co-authored-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>

James Mills committed Jan 28, 2020 at 05:51 UTC d307ba7ec545f9e76f55cd9f2af08ffd6db6fbc2
5 files changed +165
.dockerignore new
+1
@@ -0,0 +1 @@
1 +.gitignore
\ No newline at end of file
packaging/Dockerfile.packager new
+42
@@ -0,0 +1,42 @@
1 +ARG ARCH=amd64
2 +ARG DISTRO=debian
3 +ARG DISTRO_VERSION=10
4 +ARG VERSION=0.1
5 +
6 +FROM netdata/package-builders:${DISTRO}${DISTRO_VERSION} AS build
7 +
8 +ARG ARCH
9 +ARG DISTRO
10 +ARG DISTRO_VERSION
11 +ARG VERSION
12 +
13 +ENV ARCH=$ARCH
14 +ENV DISTRO=$DISTRO
15 +ENV DISTRO_VERSION=$DISTRO_VERSION
16 +ENV VERSION=$VERSION
17 +
18 +WORKDIR /netdata
19 +COPY . .
20 +
21 +RUN /build.sh
22 +
23 +FROM ${DISTRO}:${DISTRO_VERSION} AS runtime
24 +
25 +ARG ARCH
26 +ARG DISTRO
27 +ARG DISTRO_VERSION
28 +ARG VERSION
29 +
30 +ENV ARCH=$ARCH
31 +ENV DISTRO=$DISTRO
32 +ENV DISTRO_VERSION=$DISTRO_VERSION
33 +ENV VERSION=$VERSION
34 +
35 +COPY ./packaging/scripts/install.sh /install.sh
36 +COPY ./packaging/scripts/test.sh /test.sh
37 +
38 +COPY --from=build /netdata/artifacts /artifacts
39 +
40 +RUN /install.sh
41 +
42 +CMD ["/test.sh"]
packaging/build_package_install_test.sh new
+37
@@ -0,0 +1,37 @@
1 +#!/bin/sh
2 +# SPDX-License-Identifier: GPL-3.0-or-later
3 +
4 +set -e
5 +
6 +# If we are not in netdata git repo, at the top level directory, FAIL
7 +TOP_LEVEL=$(basename "$(git rev-parse --show-toplevel)")
8 +CWD=$(git rev-parse --show-cdup || echo "")
9 +if [ -n "${CWD}" ] || [ ! "${TOP_LEVEL}" = "netdata" ]; then
10 + echo "Run as ./packaging/$(basename "$0") from top level directory of netdata git repository"
11 + exit 1
12 +fi
13 +
14 +if [ $# -lt 2 ] || [ $# -gt 3 ]; then
15 + echo "Usage: ./packaging/$(basename "$0") <distro> <distro_version> [<netdata_version>]"
16 + exit 1
17 +fi
18 +
19 +if ! command -v docker > /dev/null; then
20 + echo "Docker CLI not found. You need Docker to run this!"
21 + exit 2
22 +fi
23 +
24 +DISTRO="$1"
25 +DISTRO_VERSION="$2"
26 +# TODO: Auto compute this?
27 +VERSION="${3:-1.19.0}"
28 +
29 +TAG="netdata/netdata:${DISTRO}_${DISTRO_VERSION}"
30 +
31 +docker build \
32 + -f ./packaging/Dockerfile.packager \
33 + --build-arg DISTRO="$DISTRO" \
34 + --build-arg DISTRO_VERSION="$DISTRO_VERSION" \
35 + --build-arg VERSION="$VERSION" \
36 + -t "$TAG" . |
37 + tee build.log
packaging/scripts/install.sh new
+58
@@ -0,0 +1,58 @@
1 +#!/bin/sh
2 +
3 +install_debian_like() {
4 + # This is needed to ensure package installs don't prompt for any user input.
5 + export DEBIAN_FRONTEND=noninteractive
6 +
7 + apt-get update
8 +
9 + # Install NetData
10 + apt-get install -y "/artifacts/netdata_${VERSION}_${ARCH}.deb"
11 +
12 + # Install testing tools
13 + apt-get install -y --no-install-recommends \
14 + curl netcat jq
15 +}
16 +
17 +install_fedora_like() {
18 + # Using a glob pattern here because I can't reliably determine what the
19 + # resulting package name will be (TODO: There must be a better way!)
20 +
21 + PKGMGR="$( (command -v dnf > /dev/null && echo "dnf") || echo "yum")"
22 +
23 + # Install NetData
24 + "$PKGMGR" install -y /artifacts/netdata-"${VERSION}"-*.rpm
25 +
26 + # Install testing tools
27 + "$PKGMGR" install -y curl nc jq
28 +}
29 +
30 +install_suse_like() {
31 + # Using a glob pattern here because I can't reliably determine what the
32 + # resulting package name will be (TODO: There must be a better way!)
33 +
34 + # Install NetData
35 + # FIXME: Allow unsigned packages (for now) #7773
36 + zypper install -y --allow-unsigned-rpm \
37 + /artifacts/netdata-"${VERSION}"-*.rpm
38 +
39 + # Install testing tools
40 + zypper install -y --no-recommends \
41 + curl netcat jq
42 +}
43 +
44 +case "${DISTRO}" in
45 + debian | ubuntu)
46 + install_debian_like
47 + ;;
48 + fedora | centos)
49 + install_fedora_like
50 + ;;
51 + opensuse)
52 + install_suse_like
53 + ;;
54 + *)
55 + printf "ERROR: unspported distro: %s_%s\n" "${DISTRO}" "${DISTRO_VERSION}"
56 + exit 1
57 + ;;
58 +esac
packaging/scripts/test.sh new
+27
@@ -0,0 +1,27 @@
1 +#!/bin/sh
2 +
3 +wait_for() {
4 + host="${1}"
5 + port="${2}"
6 + name="${3}"
7 + timeout="${4:-30}"
8 +
9 + printf "Waiting for %s on %s:%s ... " "${name}" "${host}" "${port}"
10 +
11 + i=0
12 + while ! nc -z "${host}" "${port}"; do
13 + sleep 1
14 + if [ "$i" -gt "$timeout" ]; then
15 + printf "Timed out!\n"
16 + return 1
17 + fi
18 + i="$((i + 1))"
19 + done
20 + printf "OK\n"
21 +}
22 +
23 +netdata -D > netdata.log 2>&1 &
24 +
25 +wait_for localhost 19999 netdata
26 +
27 +curl -sS http://127.0.0.1:19999/api/v1/info | jq '.version'