:rainbow: :whale: unified, cross-arch, parametrized Dockerfile :whale: :rainbow:
paulfantom committed
Jul 23, 2018 at 20:11 UTC
b8c5c67e10205ecadba8bf23c525efeea6f192f6
10 files changed
+173
-172
.travis.yml
+22
-16
@@ -1,5 +1,7 @@
1
+---
2
dist: trusty
3
sudo: true
4
+
5
#
6
# C includes autotools and make by default
7
language: c
@@ -9,18 +11,20 @@ os:
11
- linux
12
- osx
13
compiler:
12
- - gcc
13
- - clang
14
+ - gcc
15
+ - clang
16
+
17
#
18
# Extra packages
19
addons:
20
apt:
21
packages:
19
- - gnupg
20
- - libcap2-bin
21
- - zlib1g-dev
22
- - uuid-dev
23
- - fakeroot
22
+ - gnupg
23
+ - libcap2-bin
24
+ - zlib1g-dev
25
+ - uuid-dev
26
+ - fakeroot
27
+
28
#
29
# Setup environment
30
before_install:
@@ -41,15 +45,17 @@ before_script:
45
# Run the commit hooks in case the developer didn't
46
- git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ./packaging/check-files -
47
script:
44
- # make release packages
45
- - fakeroot ./packaging/git-build
46
- # Make sure stdout is in blocking mode. If we don't, then conda create will barf during downloads.
47
- # See https://github.com/travis-ci/travis-ci/issues/4704#issuecomment-348435959 for details.
48
- - python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
49
- # make self-extractor
50
- - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./makeself/build-x86_64-static.sh; fi
51
- # test build and installer
52
- - fakeroot ./netdata-installer.sh --install $HOME --dont-wait --dont-start-it
48
+ # make release packages
49
+ - fakeroot ./packaging/git-build
50
+ # Make sure stdout is in blocking mode. If we don't, then conda create will barf during downloads.
51
+ # See https://github.com/travis-ci/travis-ci/issues/4704#issuecomment-348435959 for details.
52
+ - python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
53
+ # make self-extractor
54
+ - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./makeself/build-x86_64-static.sh; fi
55
+ # test build and installer
56
+ - fakeroot ./netdata-installer.sh --install $HOME --dont-wait --dont-start-it
57
+ # build docker containers
58
+ - if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_OS_NAME" == "linux" && "$CC" == "gcc" ]]; then REPOSITORY="firehol/netdata" ./docker/build.sh; fi
59
#
60
# Deploy as required
61
after_success:
Dockerfile
deleted
-16
@@ -1,16 +0,0 @@
1
-# author : titpetric
2
-# original: https://github.com/titpetric/netdata
3
-# SPDX-License-Identifier: CC0-1.0
4
-
5
-FROM debian:stretch
6
-
7
-ADD . /netdata.git
8
-
9
-RUN cd ./netdata.git && chmod +x ./docker-build.sh && sync && sleep 1 && ./docker-build.sh
10
-
11
-WORKDIR /
12
-
13
-ENV NETDATA_PORT 19999
14
-EXPOSE $NETDATA_PORT
15
-
16
-CMD /usr/sbin/netdata -D -s /host -p ${NETDATA_PORT}
Dockerfile.aarch64
deleted
-20
@@ -1,20 +0,0 @@
1
-# author : titpetric
2
-# original: https://github.com/titpetric/netdata
3
-# SPDX-License-Identifier: CC0-1.0
4
-
5
-FROM resin/aarch64-debian:stretch
6
-
7
-RUN [ "cross-build-start"]
8
-
9
-ADD . /netdata.git
10
-
11
-RUN cd ./netdata.git && chmod +x ./docker-build.sh && sync && sleep 1 && ./docker-build.sh
12
-
13
-WORKDIR /
14
-
15
-ENV NETDATA_PORT 19999
16
-EXPOSE $NETDATA_PORT
17
-
18
-CMD /usr/sbin/netdata -D -s /host -p ${NETDATA_PORT}
19
-
20
-RUN [ "cross-build-end"]
Dockerfile.alpine
deleted
-59
@@ -1,59 +0,0 @@
1
-# SPDX-License-Identifier: GPL-3.0+
2
-FROM alpine:edge as builder
3
-
4
-# Install prerequisites
5
-RUN apk --no-cache add alpine-sdk autoconf automake libmnl-dev build-base jq \
6
- lm_sensors nodejs pkgconfig py-mysqldb python libuuid \
7
- py-psycopg2 py-yaml util-linux-dev zlib-dev curl bash \
8
- netcat-openbsd
9
-
10
-# Copy source
11
-COPY . /opt/netdata.git
12
-WORKDIR /opt/netdata.git
13
-
14
-# Install source
15
-RUN chmod +x ./netdata-installer.sh && \
16
- sync && sleep 1 && \
17
- ./netdata-installer.sh --dont-wait --dont-start-it
18
-
19
-################################################################################
20
-FROM alpine:edge
21
-
22
-# Reinstall some prerequisites
23
-RUN apk --no-cache add lm_sensors nodejs libuuid python py-mysqldb \
24
- py-psycopg2 py-yaml netcat-openbsd jq curl fping
25
-
26
-# Copy files over
27
-COPY --from=builder /usr/share/netdata /usr/share/netdata
28
-COPY --from=builder /usr/libexec/netdata /usr/libexec/netdata
29
-COPY --from=builder /var/cache/netdata /var/cache/netdata
30
-COPY --from=builder /var/lib/netdata /var/lib/netdata
31
-COPY --from=builder /usr/sbin/netdata /usr/sbin/netdata
32
-COPY --from=builder /etc/netdata /etc/netdata
33
-
34
-ARG NETDATA_UID=101
35
-ARG NETDATA_GID=101
36
-
37
-RUN \
38
- # fping from alpine apk is on a different location. Moving it.
39
- mv /usr/sbin/fping /usr/local/bin/fping && \
40
- chmod 4755 /usr/local/bin/fping && \
41
- mkdir -p /var/log/netdata && \
42
- # Add netdata user
43
- addgroup -g ${NETDATA_GID} -S netdata && \
44
- adduser -S -H -s /bin/sh -u ${NETDATA_GID} -h /etc/netdata -G netdata netdata && \
45
- # Apply the permissions as described in
46
- # https://github.com/firehol/netdata/wiki/netdata-security#netdata-directories
47
- chown -R root:netdata /etc/netdata && \
48
- chown -R netdata:netdata /var/cache/netdata /var/lib/netdata /usr/share/netdata && \
49
- chown root:netdata /usr/libexec/netdata/plugins.d/apps.plugin /usr/libexec/netdata/plugins.d/cgroup-network && \
50
- chmod 4750 /usr/libexec/netdata/plugins.d/cgroup-network /usr/libexec/netdata/plugins.d/apps.plugin && \
51
- chmod 0750 /var/lib/netdata /var/cache/netdata && \
52
- # Link log files to stdout
53
- ln -sf /dev/stdout /var/log/netdata/access.log && \
54
- ln -sf /dev/stdout /var/log/netdata/debug.log && \
55
- ln -sf /dev/stderr /var/log/netdata/error.log
56
-
57
-EXPOSE 19999
58
-
59
-CMD [ "/usr/sbin/netdata" , "-D", "-s", "/host", "-p", "19999"]
Dockerfile.armv7hf
deleted
-20
@@ -1,20 +0,0 @@
1
-# author : titpetric
2
-# original: https://github.com/titpetric/netdata
3
-# SPDX-License-Identifier: CC0-1.0
4
-
5
-FROM resin/armv7hf-debian:stretch
6
-
7
-RUN [ "cross-build-start"]
8
-
9
-ADD . /netdata.git
10
-
11
-RUN cd ./netdata.git && chmod +x ./docker-build.sh && sync && sleep 1 && ./docker-build.sh
12
-
13
-WORKDIR /
14
-
15
-ENV NETDATA_PORT 19999
16
-EXPOSE $NETDATA_PORT
17
-
18
-CMD /usr/sbin/netdata -D -s /host -p ${NETDATA_PORT}
19
-
20
-RUN [ "cross-build-end"]
Makefile.am
+1
-5
@@ -76,10 +76,7 @@ SUBDIRS = \
76
dist_noinst_DATA= \
77
cppcheck.sh \
78
configs.signatures \
79
- Dockerfile \
80
- Dockerfile.alpine \
81
- Dockerfile.aarch64 \
82
- Dockerfile.armv7hf \
79
+ docker \
80
netdata.cppcheck \
81
netdata.spec \
82
package.json \
@@ -89,7 +86,6 @@ dist_noinst_DATA= \
86
# should be proper init.d/openrc/systemd usable
87
dist_noinst_SCRIPTS= \
88
coverity-scan.sh \
92
- docker-build.sh \
89
kickstart.sh \
90
kickstart-static64.sh \
91
netdata-installer.sh \
docker-build.sh
deleted
-36
@@ -1,36 +0,0 @@
1
-#!/bin/bash
2
-
3
-# author : titpetric
4
-# original: https://github.com/titpetric/netdata
5
-
6
-set -e
7
-DEBIAN_FRONTEND=noninteractive
8
-
9
-# some mirrors have issues, i skipped httpredir in favor of an eu mirror
10
-
11
-# install dependencies for build
12
-
13
-apt-get -qq update
14
-apt-get -y install zlib1g-dev uuid-dev libmnl-dev gcc make curl git autoconf autogen automake pkg-config netcat-openbsd jq
15
-apt-get -y install autoconf-archive lm-sensors nodejs python python-mysqldb python-yaml
16
-
17
-# use the provided installer
18
-
19
-./netdata-installer.sh --dont-wait --dont-start-it
20
-
21
-# remove build dependencies
22
-
23
-cd /
24
-rm -rf /netdata.git
25
-
26
-dpkg -P zlib1g-dev uuid-dev libmnl-dev gcc make git autoconf autogen automake pkg-config
27
-apt-get -y autoremove
28
-apt-get clean
29
-rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
30
-
31
-
32
-# symlink access log and error log to stdout/stderr
33
-
34
-ln -sf /dev/stdout /var/log/netdata/access.log
35
-ln -sf /dev/stdout /var/log/netdata/debug.log
36
-ln -sf /dev/stderr /var/log/netdata/error.log
docker/Dockerfile
new
+101
@@ -0,0 +1,101 @@
1
+# SPDX-License-Identifier: GPL-3.0+
2
+# author : paulfantom
3
+
4
+# Cross-arch building is achieved by specifying ARCH as a build parameter with `--build-arg` option.
5
+# It is automated in `build.sh` script
6
+ARG ARCH=amd64-v3.8
7
+FROM multiarch/alpine:${ARCH} as builder
8
+
9
+# Install prerequisites
10
+RUN apk --no-cache add alpine-sdk \
11
+ autoconf \
12
+ automake \
13
+ bash \
14
+ build-base \
15
+ curl \
16
+ jq \
17
+ libmnl-dev \
18
+ libuuid \
19
+ lm_sensors \
20
+ netcat-openbsd \
21
+ nodejs \
22
+ pkgconfig \
23
+ py-mysqldb \
24
+ py-psycopg2 \
25
+ py-yaml \
26
+ python \
27
+ util-linux-dev \
28
+ zlib-dev
29
+
30
+# Copy source
31
+COPY . /opt/netdata.git
32
+WORKDIR /opt/netdata.git
33
+
34
+# Install from source
35
+RUN chmod +x netdata-installer.sh && \
36
+ sync && sleep 1 && \
37
+ ./netdata-installer.sh --dont-wait --dont-start-it
38
+
39
+# files to one directory
40
+RUN mkdir -p /app/usr/sbin/ \
41
+ /app/usr/share \
42
+ /app/usr/libexec \
43
+ /app/var/cache \
44
+ /app/var/lib \
45
+ /app/etc && \
46
+ mv /usr/share/netdata /app/usr/share/ && \
47
+ mv /usr/libexec/netdata /app/usr/libexec/ && \
48
+ mv /var/cache/netdata /app/var/cache/ && \
49
+ mv /var/lib/netdata /app/var/lib/ && \
50
+ mv /etc/netdata /app/etc/ && \
51
+ mv /usr/sbin/netdata /app/usr/sbin/ && \
52
+ mv docker/run.sh /app/usr/sbin/ && \
53
+ chmod +x /app/usr/sbin/run.sh
54
+
55
+#####################################################################
56
+ARG ARCH
57
+FROM multiarch/alpine:${ARCH}
58
+
59
+# Reinstall some prerequisites
60
+RUN apk --no-cache add curl \
61
+ fping \
62
+ jq \
63
+ libuuid \
64
+ lm_sensors \
65
+ netcat-openbsd \
66
+ nodejs \
67
+ py-mysqldb \
68
+ py-psycopg2 \
69
+ py-yaml \
70
+ python
71
+
72
+# Copy files over
73
+COPY --from=builder /app /
74
+
75
+# Configure system
76
+ARG NETDATA_UID=201
77
+ARG NETDATA_GID=201
78
+RUN \
79
+ # fping from alpine apk is on a different location. Moving it.
80
+ mv /usr/sbin/fping /usr/local/bin/fping && \
81
+ chmod 4755 /usr/local/bin/fping && \
82
+ mkdir -p /var/log/netdata && \
83
+ # Add netdata user
84
+ addgroup -g ${NETDATA_GID} -S netdata && \
85
+ adduser -S -H -s /usr/sbin/nologin -u ${NETDATA_GID} -h /etc/netdata -G netdata netdata && \
86
+ # Apply the permissions as described in
87
+ # https://github.com/firehol/netdata/wiki/netdata-security#netdata-directories
88
+ chown -R root:netdata /etc/netdata && \
89
+ chown -R netdata:netdata /var/cache/netdata /var/lib/netdata /usr/share/netdata && \
90
+ chown -R root:netdata /usr/libexec/netdata/plugins.d/apps.plugin /usr/libexec/netdata/plugins.d/cgroup-network && \
91
+ chmod 4750 /usr/libexec/netdata/plugins.d/cgroup-network /usr/libexec/netdata/plugins.d/apps.plugin && \
92
+ chmod 0750 /var/lib/netdata /var/cache/netdata && \
93
+ # Link log files to stdout
94
+ ln -sf /dev/stdout /var/log/netdata/access.log && \
95
+ ln -sf /dev/stdout /var/log/netdata/debug.log && \
96
+ ln -sf /dev/stderr /var/log/netdata/error.log
97
+
98
+ENV NETDATA_PORT 19999
99
+EXPOSE $NETDATA_PORT
100
+
101
+ENTRYPOINT ["/usr/sbin/run.sh"]
docker/build.sh
new
+38
@@ -0,0 +1,38 @@
1
+#!/bin/bash
2
+# SPDX-License-Identifier: GPL-3.0+
3
+# author : paulfantom
4
+# Cross-arch docker build helper script
5
+
6
+REPOSITORY="${REPOSITORY:-netdata}"
7
+
8
+if [ ${VERSION+x} ]; then
9
+ VERSION="-${VERSION}"
10
+else
11
+ VERSION=""
12
+fi
13
+
14
+docker run --rm --privileged multiarch/qemu-user-static:register --reset
15
+
16
+if [ -f Dockerfile ]; then
17
+ cd ../
18
+fi
19
+
20
+for ARCH in i386 armhf aarch64 amd64; do
21
+ docker build --build-arg ARCH="${ARCH}-v3.8" --tag "${REPOSITORY}:${ARCH}${VERSION}" --file docker/Dockerfile ./
22
+done
23
+docker tag "${REPOSITORY}:${ARCH}${VERSION}" "${REPOSITORY}:latest"
24
+
25
+# Push images to registry
26
+if [ -z ${DOCKER_USERNAME+x} ]; then
27
+ echo "No docker hub username specified. Exiting without pushing images to registry"
28
+ exit 0
29
+fi
30
+if [ -z ${DOCKER_PASSWORD+x} ]; then
31
+ echo "No docker hub password specified. Exiting without pushing images to registry"
32
+ exit 0
33
+fi
34
+echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
35
+for ARCH in amd64 i386 armhf aarch64; do
36
+ docker push "${REPOSITORY}:${ARCH}${VERSION}"
37
+done
38
+docker push "${REPOSITORY}:latest"
docker/run.sh
new
+11
@@ -0,0 +1,11 @@
1
+#!/bin/sh
2
+
3
+#set -e
4
+
5
+if [ ${PGID+x} ]; then
6
+ echo "Adding user netdata to group with id ${PGID}"
7
+ addgroup -g "${PGID}" -S hostgroup 2>/dev/null
8
+ sed -i "s/${PGID}:$/${PGID}:netdata/g" /etc/group
9
+fi
10
+
11
+exec /usr/sbin/netdata -u netdata -D -s /host -p "${NETDATA_PORT}" "$@"