Skip to content

Commit 5228e94

Browse files
authored
Merge pull request #56 from graphite-project/DZ-multistage
Switching to multistage
2 parents ad71513 + b66d0fc commit 5228e94

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

Dockerfile

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM phusion/baseimage:0.11
1+
FROM phusion/baseimage:0.11 as build
22
MAINTAINER Denys Zhdanov <denis.zhdanov@gmail.com>
33

44
RUN apt-get -y update \
@@ -8,28 +8,15 @@ RUN apt-get -y update \
88
python3-dev \
99
python3-pip \
1010
python3-ldap \
11-
expect \
1211
git \
13-
memcached \
1412
sqlite3 \
1513
libffi-dev \
16-
libcairo2 \
1714
libcairo2-dev \
1815
python3-cairo \
1916
python3-rrdtool \
2017
pkg-config \
2118
&& rm -rf /var/lib/apt/lists/*
2219

23-
# choose a timezone at build-time
24-
# use `--build-arg CONTAINER_TIMEZONE=Europe/Brussels` in `docker build`
25-
ARG CONTAINER_TIMEZONE
26-
ENV DEBIAN_FRONTEND noninteractive
27-
28-
RUN if [ ! -z "${CONTAINER_TIMEZONE}" ]; \
29-
then ln -sf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && \
30-
dpkg-reconfigure -f noninteractive tzdata; \
31-
fi
32-
3320
# fix python dependencies (LTS Django)
3421
RUN python3 -m pip install --upgrade virtualenv virtualenv-tools && \
3522
virtualenv /opt/graphite && \
@@ -91,18 +78,46 @@ RUN mkdir -p /var/log/graphite/ \
9178
# config statsd
9279
ADD conf/opt/statsd/config_*.js /opt/statsd/
9380

81+
FROM phusion/baseimage:0.11 as production
82+
MAINTAINER Denys Zhdanov <denis.zhdanov@gmail.com>
83+
84+
# choose a timezone at build-time
85+
# use `--build-arg CONTAINER_TIMEZONE=Europe/Brussels` in `docker build`
86+
ARG CONTAINER_TIMEZONE
87+
ENV DEBIAN_FRONTEND noninteractive
88+
89+
RUN if [ ! -z "${CONTAINER_TIMEZONE}" ]; \
90+
then ln -sf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && \
91+
dpkg-reconfigure -f noninteractive tzdata; \
92+
fi
93+
94+
RUN apt-get update --fix-missing \
95+
&& apt-get -y upgrade \
96+
&& apt-get install --yes --no-install-recommends \
97+
nginx \
98+
python-flup \
99+
python-pip \
100+
python-ldap \
101+
expect \
102+
memcached \
103+
sqlite3 \
104+
libcairo2 \
105+
python-cairo \
106+
python-rrdtool && \
107+
apt-get clean && \
108+
apt-get autoremove --yes && \
109+
rm -rf /var/lib/apt/lists/*
110+
111+
# copy /opt from build image
112+
COPY --from=build /opt /opt
113+
94114
# config nginx
95115
RUN rm /etc/nginx/sites-enabled/default
96116
ADD conf/etc/nginx/nginx.conf /etc/nginx/nginx.conf
97117
ADD conf/etc/nginx/sites-enabled/graphite-statsd.conf /etc/nginx/sites-enabled/graphite-statsd.conf
98118

99-
# init django admin
100-
ADD conf/usr/local/bin/django_admin_init.exp /usr/local/bin/django_admin_init.exp
101-
ADD conf/usr/local/bin/manage.sh /usr/local/bin/manage.sh
102-
RUN chmod +x /usr/local/bin/manage.sh && /usr/local/bin/django_admin_init.exp
103-
104119
# logging support
105-
RUN mkdir -p /var/log/carbon /var/log/graphite /var/log/nginx
120+
RUN mkdir -p /var/log/carbon /var/log/graphite /var/log/nginx /var/log/graphite/
106121
ADD conf/etc/logrotate.d/graphite-statsd /etc/logrotate.d/graphite-statsd
107122

108123
# daemons
@@ -116,9 +131,10 @@ ADD conf/etc/service/nginx/run /etc/service/nginx/run
116131
ADD conf /etc/graphite-statsd/conf
117132
ADD conf/etc/my_init.d/01_conf_init.sh /etc/my_init.d/01_conf_init.sh
118133

119-
# cleanup
120-
RUN apt-get clean\
121-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
134+
# init django admin
135+
ADD conf/usr/local/bin/django_admin_init.exp /usr/local/bin/django_admin_init.exp
136+
ADD conf/usr/local/bin/manage.sh /usr/local/bin/manage.sh
137+
RUN chmod +x /usr/local/bin/manage.sh && /usr/local/bin/django_admin_init.exp
122138

123139
# defaults
124140
EXPOSE 80 2003-2004 2023-2024 8080 8125 8125/udp 8126

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
conf_dir=/etc/graphite-statsd/conf
44

5-
# auto setup graphite with default configs if /opt/graphite is missing
5+
# auto setup graphite with default configs if /opt/graphite/conf is missing
66
# needed for the use case when a docker host volume is mounted at an of the following:
7-
# - /opt/graphite
87
# - /opt/graphite/conf
9-
# - /opt/graphite/webapp/graphite
10-
graphite_dir_contents=$(find /opt/graphite -mindepth 1 -print -quit)
8+
# - /opt/graphite/storage
119
graphite_conf_dir_contents=$(find /opt/graphite/conf -mindepth 1 -print -quit)
1210
graphite_webapp_dir_contents=$(find /opt/graphite/webapp/graphite -mindepth 1 -print -quit)
1311
graphite_storage_dir_contents=$(find /opt/graphite/storage -mindepth 1 -not -path /opt/graphite/storage/lost+found -print -quit | grep -v lost+found)
@@ -17,9 +15,6 @@ if [[ -z $graphite_log_dir_contents ]]; then
1715
mkdir -p /var/log/graphite
1816
touch /var/log/syslog
1917
fi
20-
if [[ -z $graphite_dir_contents ]]; then
21-
cd /usr/local/src/graphite-web && python3 ./setup.py install
22-
fi
2318
if [[ -z $graphite_conf_dir_contents ]]; then
2419
cp -R $conf_dir/opt/graphite/conf/*.conf /opt/graphite/conf/
2520
fi
@@ -38,7 +33,11 @@ fi
3833
# - /opt/statsd
3934
statsd_dir_contents=$(find /opt/statsd -mindepth 1 -print -quit)
4035
if [[ -z $statsd_dir_contents ]]; then
41-
git clone -b v0.8.0 https://github.com/etsy/statsd.git /opt/statsd
36+
apt-get install git && \
37+
cd /opt && \
38+
wget https://nodejs.org/download/release/v6.14.4/node-v6.14.4-linux-x64.tar.gz && \
39+
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 && \
40+
git clone -b v0.8.0 https://github.com/etsy/statsd.git /opt/statsd && \
4241
cp $conf_dir/opt/statsd/config_*.js /opt/statsd/
4342
fi
4443

0 commit comments

Comments
 (0)