diff --git a/Dockerfile b/Dockerfile index a3032b959..6bc669fe3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,53 +1,33 @@ -FROM ubuntu:16.10 +FROM alpine:3.5 -# Install dependencies -RUN apt-get update -y && \ - apt-get install -y openssl \ - python-pip \ - python-imaging \ - python-jinja2 \ - python-lxml \ - libxml2-dev \ - libxslt1-dev \ - python-pgpdump \ - python-cryptography \ - spambayes \ - tor - -# Add mailpile code (required for initial setup, not for develpoment) -ADD . /Mailpile - -# Create data dir -# This will be overriden by a volume hosted by the docker host (your dev machine) -RUN mkdir /mailpile-data - -# Create mailpile user and group. -RUN groupadd -r mailpile && \ - useradd -r -d /mailpile-data -g mailpile mailpile - -# Workaround: Setting mailpile users uid to 1000 to have write permissions -# from the docker host the to the shared volumes /Mailpile and /mailpile-data. -# Mounted volumes seem to be configured w/ uid/guid = 1000. -# Learn more here: -# - https://github.com/docker/docker/issues/7198 -# - https://denibertovic.com/posts/handling-permissions-with-docker-volumes/ -RUN usermod -u 1000 mailpile - -# Fix permissions for dirs (w/o they would only be accessible for root) -RUN chown -R mailpile:mailpile /Mailpile -RUN chown -R mailpile:mailpile /mailpile-data - -# Set /Mailpile as root dir for further RUN cmds WORKDIR /Mailpile -RUN pip install --upgrade pip -RUN pip install -r requirements-dev.txt - -# Run as mailpile user -USER mailpile - -# Initialize mailpile -RUN ./mp setup +# Create users and groups +RUN addgroup -S mailpile && adduser -S -h /mailpile-data -G mailpile mailpile -CMD ["./mp", "--www=0.0.0.0:33411", "--wait"] +# Install dependencies +RUN apk --no-cache add \ + ca-certificates \ + openssl \ + gnupg1 \ + py-pip \ + py-imaging \ + py-jinja2 \ + py-lxml \ + py-lockfile \ + py-pillow \ + py-pbr \ + py-cryptography \ + su-exec + +ADD requirements.txt /Mailpile/requirements.txt +RUN pip install -r requirements.txt + +# Entrypoint +ADD packages/docker/entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ./mp --www=0.0.0.0:33411 --wait EXPOSE 33411 + +# Add code +ADD . /Mailpile diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 000000000..acab521bc --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,22 @@ +FROM mailpile + +# Install C compiler for python deps w/ native extensions +RUN apk --no-cache add \ + gcc \ + libc-dev \ + python-dev \ + shadow + +# Workaround: Setting mailpile users uid to 1000 to have write permissions +# from the docker host the to the shared volumes /Mailpile and /mailpile-data. +# Mounted volumes seem to be configured w/ uid/guid = 1000. +# Learn more here: +# - https://github.com/docker/docker/issues/7198 +# - https://denibertovic.com/posts/handling-permissions-with-docker-volumes/ +RUN usermod -u 1000 mailpile + +RUN pip install -r requirements-dev.txt + +RUN chmod +x /entrypoint.sh + +CMD ["./mp", "--www=0.0.0.0:33411", "--wait"] diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 000000000..5c5157a6e --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,14 @@ +version: '3.0' +services: + mailpile_dev: + container_name: mailpile_dev + build: + context: . + dockerfile: Dockerfile.dev + image: mailpile_dev + volumes: + - .:/Mailpile + - .dev-mailpile-data:/mailpile-data:rw + ports: + - 33411:33411 + diff --git a/docker-compose.yml b/docker-compose.yml index 946858998..e2ffd6733 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ version: '3.0' services: mailpile: - container_name: mailpile_dev + container_name: mailpile build: . + image: mailpile volumes: - .:/Mailpile - .dev-mailpile-data:/mailpile-data diff --git a/packages/docker/entrypoint.sh b/packages/docker/entrypoint.sh new file mode 100644 index 000000000..1b3c28844 --- /dev/null +++ b/packages/docker/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +chown mailpile: /mailpile-data/ -R + +su-exec mailpile "$@"