Skip to content

Commit

Permalink
Merge pull request #56 from graphite-project/DZ-multistage
Browse files Browse the repository at this point in the history
Switching to multistage
  • Loading branch information
deniszh authored Oct 27, 2018
2 parents ad71513 + b66d0fc commit 5228e94
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
62 changes: 39 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM phusion/baseimage:0.11
FROM phusion/baseimage:0.11 as build
MAINTAINER Denys Zhdanov <[email protected]>

RUN apt-get -y update \
Expand All @@ -8,28 +8,15 @@ RUN apt-get -y update \
python3-dev \
python3-pip \
python3-ldap \
expect \
git \
memcached \
sqlite3 \
libffi-dev \
libcairo2 \
libcairo2-dev \
python3-cairo \
python3-rrdtool \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

# choose a timezone at build-time
# use `--build-arg CONTAINER_TIMEZONE=Europe/Brussels` in `docker build`
ARG CONTAINER_TIMEZONE
ENV DEBIAN_FRONTEND noninteractive

RUN if [ ! -z "${CONTAINER_TIMEZONE}" ]; \
then ln -sf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata; \
fi

# fix python dependencies (LTS Django)
RUN python3 -m pip install --upgrade virtualenv virtualenv-tools && \
virtualenv /opt/graphite && \
Expand Down Expand Up @@ -91,18 +78,46 @@ RUN mkdir -p /var/log/graphite/ \
# config statsd
ADD conf/opt/statsd/config_*.js /opt/statsd/

FROM phusion/baseimage:0.11 as production
MAINTAINER Denys Zhdanov <[email protected]>

# choose a timezone at build-time
# use `--build-arg CONTAINER_TIMEZONE=Europe/Brussels` in `docker build`
ARG CONTAINER_TIMEZONE
ENV DEBIAN_FRONTEND noninteractive

RUN if [ ! -z "${CONTAINER_TIMEZONE}" ]; \
then ln -sf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata; \
fi

RUN apt-get update --fix-missing \
&& apt-get -y upgrade \
&& apt-get install --yes --no-install-recommends \
nginx \
python-flup \
python-pip \
python-ldap \
expect \
memcached \
sqlite3 \
libcairo2 \
python-cairo \
python-rrdtool && \
apt-get clean && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt/lists/*

# copy /opt from build image
COPY --from=build /opt /opt

# config nginx
RUN rm /etc/nginx/sites-enabled/default
ADD conf/etc/nginx/nginx.conf /etc/nginx/nginx.conf
ADD conf/etc/nginx/sites-enabled/graphite-statsd.conf /etc/nginx/sites-enabled/graphite-statsd.conf

# init django admin
ADD conf/usr/local/bin/django_admin_init.exp /usr/local/bin/django_admin_init.exp
ADD conf/usr/local/bin/manage.sh /usr/local/bin/manage.sh
RUN chmod +x /usr/local/bin/manage.sh && /usr/local/bin/django_admin_init.exp

# logging support
RUN mkdir -p /var/log/carbon /var/log/graphite /var/log/nginx
RUN mkdir -p /var/log/carbon /var/log/graphite /var/log/nginx /var/log/graphite/
ADD conf/etc/logrotate.d/graphite-statsd /etc/logrotate.d/graphite-statsd

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

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

# defaults
EXPOSE 80 2003-2004 2023-2024 8080 8125 8125/udp 8126
Expand Down
15 changes: 7 additions & 8 deletions conf/etc/my_init.d/01_conf_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

conf_dir=/etc/graphite-statsd/conf

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

0 comments on commit 5228e94

Please sign in to comment.