Skip to content

Commit bbb036e

Browse files
authored
Merge pull request #66 from bebehei/smaller-baseimage
Smaller baseimage with Alpine
2 parents 2995f16 + 9838dfd commit bbb036e

File tree

17 files changed

+150
-192
lines changed

17 files changed

+150
-192
lines changed

Dockerfile

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
1-
FROM phusion/baseimage:0.11 as build
1+
FROM alpine:3.8 as base
22
LABEL maintainer="Denys Zhdanov <[email protected]>"
33

4-
RUN export DEBIAN_FRONTEND=noninteractive \
5-
&& apt-get -y update \
6-
&& apt-get -y upgrade \
7-
&& apt-get -y install \
4+
RUN true \
5+
&& apk add --no-cache \
6+
cairo \
7+
collectd \
8+
collectd-disk \
9+
collectd-nginx \
10+
findutils \
11+
librrd \
12+
memcached \
13+
nginx \
14+
nodejs \
15+
py3-pyldap \
16+
redis \
17+
runit \
18+
sqlite \
19+
&& rm -rf \
20+
/etc/nginx/conf.d/default.conf \
21+
&& mkdir -p \
22+
/var/log/carbon \
23+
/var/log/graphite
24+
25+
FROM base as build
26+
LABEL maintainer="Denys Zhdanov <[email protected]>"
27+
28+
RUN true \
29+
&& apk add --update \
30+
alpine-sdk \
831
git \
9-
libcairo2-dev \
1032
libffi-dev \
11-
librrd-dev \
12-
nginx \
13-
pkg-config \
14-
python3-cairo \
33+
pkgconfig \
34+
py3-cairo \
35+
py3-pip \
36+
py3-pyldap \
37+
py3-virtualenv \
38+
py-rrd \
1539
python3-dev \
16-
python3-ldap \
17-
python3-pip \
18-
python3-rrdtool \
19-
sqlite3 \
40+
rrdtool-dev \
2041
wget \
21-
&& rm -rf /var/lib/apt/lists/*
22-
23-
# fix python dependencies (LTS Django)
24-
RUN python3 -m pip install --upgrade virtualenv virtualenv-tools \
2542
&& virtualenv /opt/graphite \
2643
&& . /opt/graphite/bin/activate \
27-
&& python3 -m pip install --upgrade pip \
2844
&& pip3 install \
2945
django==1.11.15 \
3046
django-statsd-mozilla \
@@ -35,47 +51,48 @@ RUN python3 -m pip install --upgrade virtualenv virtualenv-tools \
3551
rrdtool
3652

3753
ARG version=1.1.4
38-
ARG whisper_version=${version}
39-
ARG carbon_version=${version}
40-
ARG graphite_version=${version}
41-
42-
ARG whisper_repo=https://github.com/graphite-project/whisper.git
43-
ARG carbon_repo=https://github.com/graphite-project/carbon.git
44-
ARG graphite_repo=https://github.com/graphite-project/graphite-web.git
45-
46-
ARG statsd_version=v0.8.0
47-
48-
ARG statsd_repo=https://github.com/etsy/statsd.git
4954

5055
# install whisper
51-
RUN git clone -b ${whisper_version} --depth 1 ${whisper_repo} /usr/local/src/whisper
52-
WORKDIR /usr/local/src/whisper
53-
RUN . /opt/graphite/bin/activate && python3 ./setup.py install
56+
ARG whisper_version=${version}
57+
ARG whisper_repo=https://github.com/graphite-project/whisper.git
58+
RUN git clone -b ${whisper_version} --depth 1 ${whisper_repo} /usr/local/src/whisper \
59+
&& cd /usr/local/src/whisper \
60+
&& . /opt/graphite/bin/activate \
61+
&& python3 ./setup.py install
5462

5563
# install carbon
56-
RUN git clone -b ${carbon_version} --depth 1 ${carbon_repo} /usr/local/src/carbon
57-
WORKDIR /usr/local/src/carbon
58-
RUN . /opt/graphite/bin/activate && pip3 install -r requirements.txt \
59-
&& python3 ./setup.py install
64+
ARG carbon_version=${version}
65+
ARG carbon_repo=https://github.com/graphite-project/carbon.git
66+
RUN . /opt/graphite/bin/activate \
67+
&& git clone -b ${carbon_version} --depth 1 ${carbon_repo} /usr/local/src/carbon \
68+
&& cd /usr/local/src/carbon \
69+
&& pip3 install -r requirements.txt \
70+
&& python3 ./setup.py install
6071

6172
# install graphite
62-
RUN git clone -b ${graphite_version} --depth 1 ${graphite_repo} /usr/local/src/graphite-web
63-
WORKDIR /usr/local/src/graphite-web
64-
RUN . /opt/graphite/bin/activate && pip3 install -r requirements.txt \
65-
&& python3 ./setup.py install
73+
ARG graphite_version=${version}
74+
ARG graphite_repo=https://github.com/graphite-project/graphite-web.git
75+
RUN . /opt/graphite/bin/activate \
76+
&& git clone -b ${graphite_version} --depth 1 ${graphite_repo} /usr/local/src/graphite-web \
77+
&& cd /usr/local/src/graphite-web \
78+
&& pip3 install -r requirements.txt \
79+
&& python3 ./setup.py install
80+
81+
# install statsd (as we have to use this ugly way)
82+
ARG statsd_version=8d5363cb109cc6363661a1d5813e0b96787c4411
83+
ARG statsd_repo=https://github.com/etsy/statsd.git
84+
RUN git init /opt/statsd \
85+
&& git -C /opt/statsd remote add origin "${statsd_repo}" \
86+
&& git -C /opt/statsd fetch origin "${statsd_version}" \
87+
&& git -C /opt/statsd checkout "${statsd_version}"
6688

6789
# fixing RRD support (see https://github.com/graphite-project/docker-graphite-statsd/issues/63)
6890
RUN sed -i \
6991
's/return os.path.realpath(fs_path)/return os.path.realpath(fs_path).decode("utf-8")/' \
7092
/opt/graphite/webapp/graphite/readers/rrd.py
7193

72-
# installing nodejs 6
73-
WORKDIR /opt
74-
RUN wget https://nodejs.org/download/release/v6.14.4/node-v6.14.4-linux-x64.tar.gz && \
75-
tar -xvpzf node-v6.14.4-linux-x64.tar.gz && rm node-v6.14.4-linux-x64.tar.gz && mv node-v6.14.4-linux-x64 nodejs
76-
77-
# install statsd
78-
RUN git clone -b ${statsd_version} ${statsd_repo} /opt/statsd
94+
COPY conf/opt/graphite/conf/ /opt/defaultconf/graphite/
95+
COPY conf/opt/graphite/webapp/graphite/local_settings.py /opt/defaultconf/graphite/local_settings.py
7996

8097
# config graphite
8198
COPY conf/opt/graphite/conf/*.conf /opt/graphite/conf/
@@ -85,56 +102,21 @@ RUN mkdir -p /var/log/graphite/ \
85102
&& PYTHONPATH=/opt/graphite/webapp /opt/graphite/bin/django-admin.py collectstatic --noinput --settings=graphite.settings
86103

87104
# config statsd
88-
COPY conf/opt/statsd/config_*.js /opt/statsd/
105+
COPY conf/opt/statsd/config/ /opt/defaultconf/statsd/config/
89106

90-
FROM phusion/baseimage:0.11 as production
107+
FROM base as production
91108
LABEL maintainer="Denys Zhdanov <[email protected]>"
92109

93110
ENV STATSD_INTERFACE udp
94111

95-
# choose a timezone at build-time
96-
# use `--build-arg CONTAINER_TIMEZONE=Europe/Brussels` in `docker build`
97-
ARG CONTAINER_TIMEZONE
98-
99-
RUN if [ ! -z "${CONTAINER_TIMEZONE}" ]; \
100-
then ln -sf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && \
101-
dpkg-reconfigure -f noninteractive tzdata; \
102-
fi
103-
104-
RUN export DEBIAN_FRONTEND=noninteractive \
105-
&& apt-get update --fix-missing \
106-
&& apt-get -y upgrade \
107-
&& apt-get install --yes --no-install-recommends \
108-
collectd \
109-
expect \
110-
git \
111-
libcairo2 \
112-
librrd-dev \
113-
memcached \
114-
nginx \
115-
python3-ldap \
116-
python3-pip \
117-
redis \
118-
sqlite3 \
119-
&& apt-get clean \
120-
&& apt-get autoremove --yes \
121-
&& rm -rf \
122-
/var/lib/apt/lists/* \
123-
/etc/nginx/sites-enabled/default \
124-
&& mkdir -p \
125-
/var/log/carbon \
126-
/var/log/graphite
127-
128112
COPY conf /
129-
COPY conf /etc/graphite-statsd/conf/
130113

131114
# copy /opt from build image
132115
COPY --from=build /opt /opt
133116

134-
RUN /usr/local/bin/django_admin_init.exp
135117

136118
# defaults
137119
EXPOSE 80 2003-2004 2023-2024 8080 8125 8125/udp 8126
138-
VOLUME ["/opt/graphite/conf", "/opt/graphite/storage", "/opt/graphite/webapp/graphite/functions/custom", "/etc/nginx", "/opt/statsd", "/etc/logrotate.d", "/var/log", "/var/lib/redis"]
120+
VOLUME ["/opt/graphite/conf", "/opt/graphite/storage", "/opt/graphite/webapp/graphite/functions/custom", "/etc/nginx", "/opt/statsd/config", "/etc/logrotate.d", "/var/log", "/var/lib/redis"]
139121

140-
CMD ["/sbin/my_init"]
122+
ENTRYPOINT ["/entrypoint"]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Host | Container | Service
4949
2024 | 2024 | [carbon aggregator - pickle](http://graphite.readthedocs.io/en/latest/carbon-daemons.html#carbon-aggregator-py)
5050
8080 | 8080 | Graphite internal gunicorn port (without Nginx proxying).
5151
8125 | 8125 | [statsd](https://github.com/etsy/statsd/blob/master/docs/server.md)
52-
8126 | 8126 | [statsd admin](https://github.com/etsy/statsd/blob/v0.7.2/docs/admin_interface.md)
52+
8126 | 8126 | [statsd admin](https://github.com/etsy/statsd/blob/master/docs/admin_interface.md)
5353

5454
By default, statsd listens on the UDP port 8125. If you want it to listen on the TCP port 8125 instead, you can set the environment variable `STATSD_INTERFACE` to `tcp` when running the container.
5555

@@ -63,7 +63,7 @@ DOCKER ASSIGNED | /opt/graphite/conf | graphite config
6363
DOCKER ASSIGNED | /opt/graphite/storage | graphite stats storage
6464
DOCKER ASSIGNED | /opt/graphite/webapp/graphite/functions/custom | graphite custom functions dir
6565
DOCKER ASSIGNED | /etc/nginx | nginx config
66-
DOCKER ASSIGNED | /opt/statsd | statsd config
66+
DOCKER ASSIGNED | /opt/statsd/config | statsd config
6767
DOCKER ASSIGNED | /etc/logrotate.d | logrotate config
6868
DOCKER ASSIGNED | /var/log | log files
6969
DOCKER ASSIGNED | /var/lib/redis | Redis TagDB data (optional)
@@ -179,7 +179,7 @@ be sure to delete the old whisper files under `/opt/graphite/storage/whisper/`.
179179
---
180180

181181
**Important:** Ensure your Statsd flush interval is at least as long as the highest-resolution retention.
182-
For example, if `/opt/statsd/config.js` looks like this.
182+
For example, if `/opt/statsd/config/udp.js` looks like this.
183183

184184
```
185185
flushInterval: 10000
@@ -218,12 +218,12 @@ docker run -d\
218218
--restart=always\
219219
-v /path/to/graphite/configs:/opt/graphite/conf\
220220
-v /path/to/graphite/data:/opt/graphite/storage\
221-
-v /path/to/statsd:/opt/statsd\
221+
-v /path/to/statsd_config:/opt/statsd/config\
222222
graphiteapp/graphite-statsd
223223
```
224224

225225
**Note**: The container will initialize properly if you mount empty volumes at
226-
`/opt/graphite/conf`, `/opt/graphite/storage`, or `/opt/statsd`.
226+
`/opt/graphite/conf`, `/opt/graphite/storage`, or `/opt/statsd/config`.
227227

228228
## Memcached config
229229

conf/entrypoint

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
. /opt/graphite/bin/activate
4+
5+
# Ensure /usr/local/bin is in PATH. On some
6+
# weird platforms,this might not be the case
7+
PATH="${PATH}:/usr/local/bin"
8+
9+
runsvdir -P /etc/service

conf/etc/my_init.d/01_conf_init.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

conf/etc/nginx/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
user www-data;
1+
user nginx;
22
worker_processes 4;
33
pid /run/nginx.pid;
44
daemon off;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
rm -f /opt/graphite/storage/carbon-aggregator-a.pid
4-
source /opt/graphite/bin/activate
5-
exec python3 /opt/graphite/bin/carbon-aggregator.py start --debug 2>&1 >> /var/log/carbon-aggregator.log
4+
exec python3 /opt/graphite/bin/carbon-aggregator.py start --debug 2>&1 | tee -a /var/log/carbon-aggregator.log

conf/etc/service/carbon/run

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
rm -f /opt/graphite/storage/carbon-cache-a.pid
4-
source /opt/graphite/bin/activate
5-
exec python3 /opt/graphite/bin/carbon-cache.py start --debug 2>&1 >> /var/log/carbon.log
4+
exec python3 /opt/graphite/bin/carbon-cache.py start --debug 2>&1 | tee -a /var/log/carbon.log

conf/etc/service/collectd/run

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
[[ -n ${COLLECTD} ]] || exit 1
4-
exec /usr/sbin/collectd -f -C /etc/collectd/collectd.conf
3+
[ -n "${COLLECTD}" ] || exit 0
4+
5+
[ -d /etc/collectd/collectd.conf.d ] || mkdir -p /etc/collectd/collectd.conf.d
6+
if folder_empty /etc/collectd/collectd.conf.d; then
7+
touch /etc/collectd/collectd.conf.d/do_not_spill_warning_about_folder_is_empty.conf
8+
fi
9+
10+
exec /usr/sbin/collectd -f -C /etc/collectd/collectd.conf

conf/etc/service/graphite/run

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,54 @@
1-
#!/bin/bash
1+
#!/bin/sh
2+
3+
if folder_empty /var/log/graphite; then
4+
mkdir -p /var/log/graphite
5+
touch /var/log/syslog
6+
fi
7+
8+
if folder_empty /opt/graphite/conf; then
9+
cp /opt/defaultconf/graphite/conf/*.conf /opt/graphite/conf/
10+
fi
11+
12+
if folder_empty /opt/graphite/webapp/graphite; then
13+
cp /opt/defaultconf/graphite/local_settings.py /opt/graphite/webapp/graphite/local_settings.py
14+
fi
15+
16+
if folder_empty /opt/graphite/storage; then
17+
mkdir -p /opt/graphite/storage/whisper
18+
19+
export PYTHONPATH=/opt/graphite/webapp
20+
export DJANGO_SETTINGS_MODULE=graphite.settings
21+
22+
/opt/graphite/bin/django-admin.py makemigrations
23+
/opt/graphite/bin/django-admin.py migrate auth
24+
/opt/graphite/bin/django-admin.py migrate --run-syncdb
25+
/opt/graphite/bin/django-admin.py createsuperuser
26+
--noinput \
27+
28+
--username root <<- ENDINPUT
29+
root
30+
root
31+
ENDINPUT
32+
fi
33+
34+
if folder_empty /opt/graphite/webapp/graphite/functions/custom; then
35+
touch /opt/graphite/webapp/graphite/functions/custom/__init__.py
36+
fi
237

3-
sv start nginx || exit 1
4-
source /opt/graphite/bin/activate
538
export GRAPHITE_WSGI_PROCESSES=${GRAPHITE_WSGI_PROCESSES:-4}
639
export GRAPHITE_WSGI_THREADS=${GRAPHITE_WSGI_THREADS:-2}
740
export GRAPHITE_WSGI_REQUEST_TIMEOUT=${GRAPHITE_WSGI_REQUEST_TIMEOUT:-65}
841
export GRAPHITE_WSGI_REQUEST_LINE=${GRAPHITE_WSGI_REQUEST_LINE:-0}
942
export GRAPHITE_WSGI_MAX_REQUESTS=${GRAPHITE_WSGI_MAX_REQUESTS:-1000}
10-
export PYTHONPATH=/opt/graphite/webapp && \
43+
export PYTHONPATH=/opt/graphite/webapp
44+
45+
sv start nginx || exit 1
46+
1147
exec /opt/graphite/bin/gunicorn wsgi --preload --pythonpath=/opt/graphite/webapp/graphite \
1248
--workers=${GRAPHITE_WSGI_PROCESSES} \
1349
--threads=${GRAPHITE_WSGI_THREADS} \
1450
--limit-request-line=${GRAPHITE_WSGI_REQUEST_LINE} \
1551
--max-requests=${GRAPHITE_WSGI_MAX_REQUESTS} \
1652
--timeout=${GRAPHITE_WSGI_REQUEST_TIMEOUT} \
1753
--bind=0.0.0.0:8080 \
18-
--log-file=/var/log/gunicorn.log
54+
--log-file=/var/log/gunicorn.log

0 commit comments

Comments
 (0)