Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller baseimage with Alpine #66

Merged
merged 21 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 69 additions & 87 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
FROM phusion/baseimage:0.11 as build
FROM alpine:3.8 as base
LABEL maintainer="Denys Zhdanov <denis.zhdanov@gmail.com>"

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y update \
&& apt-get -y upgrade \
&& apt-get -y install \
RUN true \
&& apk add --no-cache \
cairo \
collectd \
collectd-disk \
collectd-nginx \
findutils \
librrd \
memcached \
nginx \
nodejs \
py3-pyldap \
redis \
runit \
sqlite \
&& rm -rf \
/etc/nginx/conf.d/default.conf \
&& mkdir -p \
/var/log/carbon \
/var/log/graphite

FROM base as build
LABEL maintainer="Denys Zhdanov <denis.zhdanov@gmail.com>"

RUN true \
&& apk add --update \
alpine-sdk \
git \
libcairo2-dev \
libffi-dev \
librrd-dev \
nginx \
pkg-config \
python3-cairo \
pkgconfig \
py3-cairo \
py3-pip \
py3-pyldap \
py3-virtualenv \
py-rrd \
python3-dev \
python3-ldap \
python3-pip \
python3-rrdtool \
sqlite3 \
rrdtool-dev \
wget \
&& rm -rf /var/lib/apt/lists/*

# fix python dependencies (LTS Django)
RUN python3 -m pip install --upgrade virtualenv virtualenv-tools \
&& virtualenv /opt/graphite \
&& . /opt/graphite/bin/activate \
&& python3 -m pip install --upgrade pip \
&& pip3 install \
django==1.11.15 \
django-statsd-mozilla \
Expand All @@ -35,47 +51,48 @@ RUN python3 -m pip install --upgrade virtualenv virtualenv-tools \
rrdtool

ARG version=1.1.4
ARG whisper_version=${version}
ARG carbon_version=${version}
ARG graphite_version=${version}

ARG whisper_repo=https://github.com/graphite-project/whisper.git
ARG carbon_repo=https://github.com/graphite-project/carbon.git
ARG graphite_repo=https://github.com/graphite-project/graphite-web.git

ARG statsd_version=v0.8.0

ARG statsd_repo=https://github.com/etsy/statsd.git

# install whisper
RUN git clone -b ${whisper_version} --depth 1 ${whisper_repo} /usr/local/src/whisper
WORKDIR /usr/local/src/whisper
RUN . /opt/graphite/bin/activate && python3 ./setup.py install
ARG whisper_version=${version}
ARG whisper_repo=https://github.com/graphite-project/whisper.git
RUN git clone -b ${whisper_version} --depth 1 ${whisper_repo} /usr/local/src/whisper \
&& cd /usr/local/src/whisper \
&& . /opt/graphite/bin/activate \
&& python3 ./setup.py install

# install carbon
RUN git clone -b ${carbon_version} --depth 1 ${carbon_repo} /usr/local/src/carbon
WORKDIR /usr/local/src/carbon
RUN . /opt/graphite/bin/activate && pip3 install -r requirements.txt \
&& python3 ./setup.py install
ARG carbon_version=${version}
ARG carbon_repo=https://github.com/graphite-project/carbon.git
RUN . /opt/graphite/bin/activate \
&& git clone -b ${carbon_version} --depth 1 ${carbon_repo} /usr/local/src/carbon \
&& cd /usr/local/src/carbon \
&& pip3 install -r requirements.txt \
&& python3 ./setup.py install

# install graphite
RUN git clone -b ${graphite_version} --depth 1 ${graphite_repo} /usr/local/src/graphite-web
WORKDIR /usr/local/src/graphite-web
RUN . /opt/graphite/bin/activate && pip3 install -r requirements.txt \
&& python3 ./setup.py install
ARG graphite_version=${version}
ARG graphite_repo=https://github.com/graphite-project/graphite-web.git
RUN . /opt/graphite/bin/activate \
&& git clone -b ${graphite_version} --depth 1 ${graphite_repo} /usr/local/src/graphite-web \
&& cd /usr/local/src/graphite-web \
&& pip3 install -r requirements.txt \
&& python3 ./setup.py install

# install statsd (as we have to use this ugly way)
ARG statsd_version=8d5363cb109cc6363661a1d5813e0b96787c4411
ARG statsd_repo=https://github.com/etsy/statsd.git
RUN git init /opt/statsd \
&& git -C /opt/statsd remote add origin "${statsd_repo}" \
&& git -C /opt/statsd fetch origin "${statsd_version}" \
&& git -C /opt/statsd checkout "${statsd_version}"

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

# installing nodejs 6
WORKDIR /opt
RUN 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

# install statsd
RUN git clone -b ${statsd_version} ${statsd_repo} /opt/statsd
COPY conf/opt/graphite/conf/ /opt/defaultconf/graphite/
COPY conf/opt/graphite/webapp/graphite/local_settings.py /opt/defaultconf/graphite/local_settings.py

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

# config statsd
COPY conf/opt/statsd/config_*.js /opt/statsd/
COPY conf/opt/statsd/config/ /opt/defaultconf/statsd/config/

FROM phusion/baseimage:0.11 as production
FROM base as production
LABEL maintainer="Denys Zhdanov <denis.zhdanov@gmail.com>"

ENV STATSD_INTERFACE udp

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

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

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update --fix-missing \
&& apt-get -y upgrade \
&& apt-get install --yes --no-install-recommends \
collectd \
expect \
git \
libcairo2 \
librrd-dev \
memcached \
nginx \
python3-ldap \
python3-pip \
redis \
sqlite3 \
&& apt-get clean \
&& apt-get autoremove --yes \
&& rm -rf \
/var/lib/apt/lists/* \
/etc/nginx/sites-enabled/default \
&& mkdir -p \
/var/log/carbon \
/var/log/graphite

COPY conf /
COPY conf /etc/graphite-statsd/conf/

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

RUN /usr/local/bin/django_admin_init.exp

# defaults
EXPOSE 80 2003-2004 2023-2024 8080 8125 8125/udp 8126
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"]
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"]

CMD ["/sbin/my_init"]
ENTRYPOINT ["/entrypoint"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Host | Container | Service
2024 | 2024 | [carbon aggregator - pickle](http://graphite.readthedocs.io/en/latest/carbon-daemons.html#carbon-aggregator-py)
8080 | 8080 | Graphite internal gunicorn port (without Nginx proxying).
8125 | 8125 | [statsd](https://github.com/etsy/statsd/blob/master/docs/server.md)
8126 | 8126 | [statsd admin](https://github.com/etsy/statsd/blob/v0.7.2/docs/admin_interface.md)
8126 | 8126 | [statsd admin](https://github.com/etsy/statsd/blob/master/docs/admin_interface.md)

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.

Expand All @@ -63,7 +63,7 @@ DOCKER ASSIGNED | /opt/graphite/conf | graphite config
DOCKER ASSIGNED | /opt/graphite/storage | graphite stats storage
DOCKER ASSIGNED | /opt/graphite/webapp/graphite/functions/custom | graphite custom functions dir
DOCKER ASSIGNED | /etc/nginx | nginx config
DOCKER ASSIGNED | /opt/statsd | statsd config
DOCKER ASSIGNED | /opt/statsd/config | statsd config
DOCKER ASSIGNED | /etc/logrotate.d | logrotate config
DOCKER ASSIGNED | /var/log | log files
DOCKER ASSIGNED | /var/lib/redis | Redis TagDB data (optional)
Expand Down Expand Up @@ -179,7 +179,7 @@ be sure to delete the old whisper files under `/opt/graphite/storage/whisper/`.
---

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

```
flushInterval: 10000
Expand Down Expand Up @@ -218,12 +218,12 @@ docker run -d\
--restart=always\
-v /path/to/graphite/configs:/opt/graphite/conf\
-v /path/to/graphite/data:/opt/graphite/storage\
-v /path/to/statsd:/opt/statsd\
-v /path/to/statsd_config:/opt/statsd/config\
graphiteapp/graphite-statsd
```

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

## Memcached config

Expand Down
9 changes: 9 additions & 0 deletions conf/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

. /opt/graphite/bin/activate

# Ensure /usr/local/bin is in PATH. On some
# weird platforms,this might not be the case
PATH="${PATH}:/usr/local/bin"

runsvdir -P /etc/service
42 changes: 0 additions & 42 deletions conf/etc/my_init.d/01_conf_init.sh

This file was deleted.

2 changes: 1 addition & 1 deletion conf/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
user www-data;
user nginx;
worker_processes 4;
pid /run/nginx.pid;
daemon off;
Expand Down
5 changes: 2 additions & 3 deletions conf/etc/service/carbon-aggregator/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#!/bin/sh

rm -f /opt/graphite/storage/carbon-aggregator-a.pid
source /opt/graphite/bin/activate
exec python3 /opt/graphite/bin/carbon-aggregator.py start --debug 2>&1 >> /var/log/carbon-aggregator.log
exec python3 /opt/graphite/bin/carbon-aggregator.py start --debug 2>&1 | tee -a /var/log/carbon-aggregator.log
5 changes: 2 additions & 3 deletions conf/etc/service/carbon/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#!/bin/sh

rm -f /opt/graphite/storage/carbon-cache-a.pid
source /opt/graphite/bin/activate
exec python3 /opt/graphite/bin/carbon-cache.py start --debug 2>&1 >> /var/log/carbon.log
exec python3 /opt/graphite/bin/carbon-cache.py start --debug 2>&1 | tee -a /var/log/carbon.log
12 changes: 9 additions & 3 deletions conf/etc/service/collectd/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash
#!/bin/sh

[[ -n ${COLLECTD} ]] || exit 1
exec /usr/sbin/collectd -f -C /etc/collectd/collectd.conf
[ -n "${COLLECTD}" ] || exit 0

[ -d /etc/collectd/collectd.conf.d ] || mkdir -p /etc/collectd/collectd.conf.d
if folder_empty /etc/collectd/collectd.conf.d; then
touch /etc/collectd/collectd.conf.d/do_not_spill_warning_about_folder_is_empty.conf
fi

exec /usr/sbin/collectd -f -C /etc/collectd/collectd.conf
46 changes: 41 additions & 5 deletions conf/etc/service/graphite/run
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
#!/bin/bash
#!/bin/sh

if folder_empty /var/log/graphite; then
mkdir -p /var/log/graphite
touch /var/log/syslog
fi

if folder_empty /opt/graphite/conf; then
cp /opt/defaultconf/graphite/conf/*.conf /opt/graphite/conf/
fi

if folder_empty /opt/graphite/webapp/graphite; then
cp /opt/defaultconf/graphite/local_settings.py /opt/graphite/webapp/graphite/local_settings.py
fi

if folder_empty /opt/graphite/storage; then
mkdir -p /opt/graphite/storage/whisper

export PYTHONPATH=/opt/graphite/webapp
export DJANGO_SETTINGS_MODULE=graphite.settings

/opt/graphite/bin/django-admin.py makemigrations
/opt/graphite/bin/django-admin.py migrate auth
/opt/graphite/bin/django-admin.py migrate --run-syncdb
/opt/graphite/bin/django-admin.py createsuperuser
--noinput \
--email root.graphite@mailinator.com \
--username root <<- ENDINPUT
root
root
ENDINPUT
fi

if folder_empty /opt/graphite/webapp/graphite/functions/custom; then
touch /opt/graphite/webapp/graphite/functions/custom/__init__.py
fi

sv start nginx || exit 1
source /opt/graphite/bin/activate
export GRAPHITE_WSGI_PROCESSES=${GRAPHITE_WSGI_PROCESSES:-4}
export GRAPHITE_WSGI_THREADS=${GRAPHITE_WSGI_THREADS:-2}
export GRAPHITE_WSGI_REQUEST_TIMEOUT=${GRAPHITE_WSGI_REQUEST_TIMEOUT:-65}
export GRAPHITE_WSGI_REQUEST_LINE=${GRAPHITE_WSGI_REQUEST_LINE:-0}
export GRAPHITE_WSGI_MAX_REQUESTS=${GRAPHITE_WSGI_MAX_REQUESTS:-1000}
export PYTHONPATH=/opt/graphite/webapp && \
export PYTHONPATH=/opt/graphite/webapp

sv start nginx || exit 1

exec /opt/graphite/bin/gunicorn wsgi --preload --pythonpath=/opt/graphite/webapp/graphite \
--workers=${GRAPHITE_WSGI_PROCESSES} \
--threads=${GRAPHITE_WSGI_THREADS} \
--limit-request-line=${GRAPHITE_WSGI_REQUEST_LINE} \
--max-requests=${GRAPHITE_WSGI_MAX_REQUESTS} \
--timeout=${GRAPHITE_WSGI_REQUEST_TIMEOUT} \
--bind=0.0.0.0:8080 \
--log-file=/var/log/gunicorn.log
--log-file=/var/log/gunicorn.log
Loading