From 6689d85e08a48c0bc3acdddfadda99071edbd7e8 Mon Sep 17 00:00:00 2001 From: Marvin Steadfast Date: Tue, 16 Apr 2019 18:49:46 +0200 Subject: [PATCH] using multistage dockerfile --- Makefile | 2 +- builder/Dockerfile | 44 +++++++++++ builder/requirements.txt | 11 +++ docker-compose.yml | 2 +- writing_env/Dockerfile | 44 ----------- .../home/blog/playbooks/files/flickr2markdown | 6 -- .../root/home/blog/playbooks/writing_env.yml | 75 ------------------- 7 files changed, 57 insertions(+), 127 deletions(-) create mode 100644 builder/Dockerfile create mode 100644 builder/requirements.txt delete mode 100644 writing_env/Dockerfile delete mode 100644 writing_env/root/home/blog/playbooks/files/flickr2markdown delete mode 100644 writing_env/root/home/blog/playbooks/writing_env.yml diff --git a/Makefile b/Makefile index d6e68e2..283e3c5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PY?=/usr/bin/python3 +PY?=/usr/local/bin/python3 PELICAN?=pelican PELICANOPTS= diff --git a/builder/Dockerfile b/builder/Dockerfile new file mode 100644 index 0000000..3d13473 --- /dev/null +++ b/builder/Dockerfile @@ -0,0 +1,44 @@ +FROM python:3.7.3-alpine3.9 as base +ENV LANG C.UTF-8 +ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt +ENV BLOG_UID 1000 +ENV BLOG_GID 1000 +RUN set -ex \ + && echo "http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ + && apk upgrade -a --no-cache \ + && apk add --no-cache \ + lftp \ + make \ + tzdata \ + && cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime \ + && echo "Europe/Berlin" > /etc/timezone \ + && apk del tzdata \ + && addgroup -g $BLOG_GID blog \ + && adduser -h /home/blog -D -s /bin/sh -G blog blog \ + && chown -R $BLOG_UID:$BLOG_GID /home/blog +COPY requirements.txt . + +FROM base as builder +RUN set -ex \ + && apk add --no-cache\ + ca-certificates \ + g++ \ + git \ + ca-certificates \ + cython \ + gcc \ + git \ + linux-headers \ + make \ + musl-dev \ + && pip install -r requirements.txt + +FROM base +COPY --from=builder /root/.cache /root/.cache +RUN set -ex \ + && pip install -r requirements.txt \ + && rm -rf /root/.cache \ + && rm requirements.txt +USER blog +WORKDIR /blog +EXPOSE 8000 diff --git a/builder/requirements.txt b/builder/requirements.txt new file mode 100644 index 0000000..71caafd --- /dev/null +++ b/builder/requirements.txt @@ -0,0 +1,11 @@ +beautifulsoup4 +cookiecutter==1.4.0 +flickr2markdown +ipython>=4.0 +jinja2-slug +jupyter>=1.0 +markdown +nbconvert>=4.0 +pelican==4.0.1 +typogrify +tzlocal diff --git a/docker-compose.yml b/docker-compose.yml index ccc3b46..b9357a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: blog: - build: writing_env/ + build: builder/ image: xsteadfastx/blog container_name: blog environment: diff --git a/writing_env/Dockerfile b/writing_env/Dockerfile deleted file mode 100644 index 3b704d1..0000000 --- a/writing_env/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM alpine:3.9 - -ENV LANG C.UTF-8 -ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt - -ENV BLOG_UID 1000 -ENV BLOG_GID 1000 - -# prepare repositories -RUN set -ex \ - && echo "http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ - && apk update - -# add files -ADD root / - -# prepare for provisioning -RUN set -ex \ - && apk upgrade -a --no-cache \ - && apk add --no-cache\ - ansible \ - bash \ - ca-certificates \ - g++ \ - git \ - openssh \ - python \ - sudo \ - && addgroup -g $BLOG_GID blog \ - && adduser -h /home/blog -D -s /bin/sh -G blog blog \ - && echo 'blog ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/blog \ - && chmod 0440 /etc/sudoers.d/blog \ - && chown -R $BLOG_UID:$BLOG_GID /home/blog - -# switch user to blog -USER blog - -# provision -RUN set -ex \ - && ansible-playbook -c local /home/blog/playbooks/writing_env.yml - -WORKDIR /blog - -EXPOSE 8000 diff --git a/writing_env/root/home/blog/playbooks/files/flickr2markdown b/writing_env/root/home/blog/playbooks/files/flickr2markdown deleted file mode 100644 index 204ef20..0000000 --- a/writing_env/root/home/blog/playbooks/files/flickr2markdown +++ /dev/null @@ -1,6 +0,0 @@ -[API] -key = 2207902126a225122e46533e82b6a947 - -[Defaults] -user = marvinxsteadfast -size = large diff --git a/writing_env/root/home/blog/playbooks/writing_env.yml b/writing_env/root/home/blog/playbooks/writing_env.yml deleted file mode 100644 index 020bf68..0000000 --- a/writing_env/root/home/blog/playbooks/writing_env.yml +++ /dev/null @@ -1,75 +0,0 @@ -# vim:ft=ansible ---- -- hosts: 127.0.0.1 - connection: local - - tasks: - - - name: install deps - apk: - state: present - update_cache: true - name: - - ack - - ansible - - bash-completion - - ca-certificates - - coreutils - - curl - - cython - - gcc - - git - - grep - - imagemagick - - lftp - - linux-headers - - make - - musl-dev - - nodejs - - python3 - - python3-dev - - wget - become: yes - - - name: pip status - stat: - path=/usr/bin/pip - register: pip - - - name: install pip - shell: curl https://bootstrap.pypa.io/get-pip.py | python3 - become: yes - when: pip.stat.exists == False - - - name: install pip packages - pip: - executable: pip3 - name: - - beautifulsoup4 - - cookiecutter==1.4.0 - - flickr2markdown - - ipython>=4.0 - - jinja2-slug - - jupyter>=1.0 - - markdown - - nbconvert>=4.0 - - pelican==4.0.1 - - typogrify - - tzlocal - - virtualenv - become: yes - - - name: add flickr2markdown config - copy: - src=flickr2markdown - dest=~/.flickr2markdown - - - name: set timezone - copy: - content="Europe/Berlin" - dest=/etc/timezone - owner=root - group=root - mode=0644 - backup=yes - become: yes