Skip to content

Commit

Permalink
Split dockerfiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
glogiotatidis committed Nov 30, 2017
1 parent af5c58f commit cfd2386
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dockerignore
Expand Up @@ -5,3 +5,10 @@ venv
/static
.env
/media
*.gz
/locale
/node_modules
/bower_components
Dockerfile
/jsi18n
docker/dockerfiles/
14 changes: 14 additions & 0 deletions .env-build
@@ -0,0 +1,14 @@
ALLOWED_HOSTS=*
BROKER_URL=redis://redis:643
CACHE_URL=dummy://
REDIS_HELPFULVOTES_URL=foo
REDIS_DEFAULT_URL=bar
CELERY_ALWAYS_EAGER=True
CSRF_COOKIE_SECURE=False
DATABASE_URL=sqlite://
DOMAIN=localhost
ES_URLS=elasticsearch:9200
SESSION_COOKIE_SECURE=False
SITE_URL=http://localhost:8000
SECRET_KEY=secret

3 changes: 2 additions & 1 deletion Procfile
@@ -1 +1,2 @@
web: ./bin/run-prod.sh
# Deis ignores Dockerfile entrypoint.
web: /entrypoint.sh ./bin/run-prod.sh
22 changes: 22 additions & 0 deletions docker/bin/build-docker-images.sh
@@ -0,0 +1,22 @@
#!/bin/bash
set -e

DOCKER_REPO=${DOCKER_REPO:-mozmeao/kitsune}
GIT_SHA=${GIT_SHA:-auto}

if [ $GIT_SHA == "auto" ];
then
GIT_SHA_FULL=$(git rev-parse HEAD);
GIT_SHA=${GIT_SHA_FULL:0:7};
fi

for image in base staticfiles locales full-no-locales full;
do
docker build -t kitsune:${image}-latest \
-t ${DOCKER_REPO}:${image}-${GIT_SHA} \
-t ${DOCKER_REPO}:${image}-latest \
--cache-from ${DOCKER_REPO}:${image}-latest \
--cache-from kitsune:${image}-latest \
-f docker/dockerfiles/${image} \
--build-arg GIT_SHA=${GIT_SHA} .
done
5 changes: 5 additions & 0 deletions docker/bin/entrypoint.sh
@@ -0,0 +1,5 @@
#!/bin/bash

source /venv/bin/activate

exec $@
9 changes: 9 additions & 0 deletions docker/bin/pull-docker-images.sh
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

DOCKER_REPO=${DOCKER_REPO:-mozmeao/kitsune}

for image in base staticfiles locales full-no-locales full;
do
docker pull ${DOCKER_REPO}:${image}-latest || true
done
26 changes: 26 additions & 0 deletions docker/bin/push-docker-images.sh
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

DOCKER_REPO=${DOCKER_REPO:-mozmeao/kitsune}
GIT_SHA=${GIT_SHA:-latest}

if ! ([ "$DOCKER_USERNAME" ] || [ -f ~/.docker/config.json ]);
then
echo "No docker configuration, exiting."
exit 0;
fi

if [ "$DOCKER_USERNAME" ];
then
docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}"
fi

for image in base staticfiles locales full-no-locales full;
do
docker push ${DOCKER_REPO}:${image}-${GIT_SHA}

if [ $GIT_BRANCH == "master" ];
then
docker push ${DOCKER_REPO}:${image}-latest
fi
done
34 changes: 34 additions & 0 deletions docker/dockerfiles/base
@@ -0,0 +1,34 @@
FROM python:2-stretch

WORKDIR /app

ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN groupadd --gid 1000 kitsune && useradd -g kitsune --uid 1000 --shell /usr/sbin/nologin kitsune

# Node is used in the staticfiles dockerfile but since this base image
# is used for development get it installed here.
RUN apt-get update && apt-get install apt-transport-https && \
echo "deb https://deb.nodesource.com/node_0.10 jessie main" >> /etc/apt/sources.list && \
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
apt-get update && \
apt-get install -y --no-install-recommends \
gettext build-essential \
libxml2-dev libxslt1-dev zlib1g-dev git \
libjpeg-dev libffi-dev libssl-dev libxslt1.1 \
libmariadbclient-dev mariadb-client && \
rm -rf /var/lib/apt/lists/*

COPY ./requirements/ /app/requirements/

RUN bash -c '\
virtualenv /venv && \
source /venv/bin/activate && \
pip install --no-cache-dir --require-hashes -r requirements/default.txt && \
pip install --no-cache-dir --require-hashes -r requirements/test.txt && \
pip install --no-cache-dir --require-hashes -r requirements/dev.txt'

ARG GIT_SHA=head
ENV GIT_SHA ${GIT_SHA}
6 changes: 6 additions & 0 deletions docker/dockerfiles/full
@@ -0,0 +1,6 @@
FROM kitsune:full-no-locales-latest

USER root
COPY --from=kitsune:locales-latest /app/locale /app/locale
RUN chown kitsune.kitsune -R /app/locale
USER kitsune
32 changes: 32 additions & 0 deletions docker/dockerfiles/full-no-locales
@@ -0,0 +1,32 @@
FROM python:2-slim-stretch

WORKDIR /app

EXPOSE 8000

ENTRYPOINT ["/entrypoint.sh"]

ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN apt-get update && \
apt-get install -y --no-install-recommends \
libmariadbclient18 optipng \
libxslt1.1 && \
rm -rf /var/lib/apt/lists/*

RUN groupadd --gid 1000 kitsune && useradd -g kitsune --uid 1000 --shell /usr/sbin/nologin kitsune

COPY docker/bin/entrypoint.sh /entrypoint.sh

COPY --from=kitsune:base-latest /venv /venv
COPY --from=kitsune:staticfiles-latest /app/static /app/static

COPY . .

RUN chown kitsune.kitsune -R /app
USER kitsune

ARG GIT_SHA=head
ENV GIT_SHA ${GIT_SHA}
24 changes: 24 additions & 0 deletions docker/dockerfiles/locales
@@ -0,0 +1,24 @@
FROM python:2-stretch

WORKDIR /app

RUN apt-get update && \
apt-get install -y --no-install-recommends gettext

COPY --from=kitsune:base-latest /venv /venv

COPY . .

ARG LOCALE_ENV=master
RUN bash -c '\
mkdir locale && \
curl -s -L https://github.com/mozilla-l10n/sumo-l10n/archive/${LOCALE_ENV}.tar.gz | \
tar xz --strip-components=1 -C locale'

RUN bash -c '\
source /venv/bin/activate && \
./scripts/compile-linted-mo.sh && \
find ./locale ! -name '*.mo' -type f -delete'

ARG GIT_SHA=head
ENV GIT_SHA ${GIT_SHA}
32 changes: 32 additions & 0 deletions docker/dockerfiles/staticfiles
@@ -0,0 +1,32 @@
FROM python:2-stretch

WORKDIR /app

RUN apt-get update && apt-get install apt-transport-https && \
echo "deb https://deb.nodesource.com/node_0.10 jessie main" >> /etc/apt/sources.list && \
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
apt-get update && \
apt-get install -y --no-install-recommends \
nodejs=0.10.48-1nodesource1~jessie1 && \
rm -rf /var/lib/apt/lists/*

COPY ./package.json /app/package.json
COPY ./bower.json /app/bower.json

RUN npm install

RUN ./node_modules/.bin/bower install --allow-root

COPY --from=kitsune:base-latest /venv /venv

COPY . .

RUN bash -c '\
source /venv/bin/activate && \
cp .env-build .env && \
./manage.py nunjucks_precompile && \
./manage.py compilejsi18n && \
./manage.py collectstatic --noinput'

ARG GIT_SHA=head
ENV GIT_SHA ${GIT_SHA}

0 comments on commit cfd2386

Please sign in to comment.