diff --git a/.gitignore b/.gitignore index 352989fc..8734dcdb 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ pip-selfcheck.json /docker-compose.yml /.idea /.vscode +qemu-arm-static diff --git a/core/admin/Dockerfile b/core/admin/Dockerfile index f6d28bf5..485ad261 100644 --- a/core/admin/Dockerfile +++ b/core/admin/Dockerfile @@ -1,5 +1,8 @@ # First stage to build assets -FROM node:8 as assets +ARG DISTRO=alpine:3.10 +ARG ARCH="" +FROM ${ARCH}node:8 as assets +COPY --from=balenalib/rpi-alpine:3.10 /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static COPY package.json ./ RUN npm install @@ -11,7 +14,7 @@ RUN mkdir static \ # Actual application -FROM alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip git bash \ @@ -40,5 +43,4 @@ ENV FLASK_APP mailu CMD /start.py -HEALTHCHECK CMD curl -f -L http://localhost/ui/login?next=ui.index || exit 1 - +HEALTHCHECK CMD curl -f -L http://localhost/ui/login?next=ui.index || exit 1 \ No newline at end of file diff --git a/core/dovecot/Dockerfile b/core/dovecot/Dockerfile index 188d4b85..2e6a46e1 100644 --- a/core/dovecot/Dockerfile +++ b/core/dovecot/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip git bash \ diff --git a/core/nginx/Dockerfile b/core/nginx/Dockerfile index 6b54cbf9..66a6e485 100644 --- a/core/nginx/Dockerfile +++ b/core/nginx/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip git bash \ diff --git a/core/none/Dockerfile b/core/none/Dockerfile index 96bf8411..b80a2d10 100644 --- a/core/none/Dockerfile +++ b/core/none/Dockerfile @@ -1,5 +1,6 @@ # This is an idle image to dynamically replace any component if disabled. -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO CMD sleep 1000000d diff --git a/core/postfix/Dockerfile b/core/postfix/Dockerfile index 830c2347..503558db 100644 --- a/core/postfix/Dockerfile +++ b/core/postfix/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip git bash \ diff --git a/docs/Dockerfile b/docs/Dockerfile index c2661262..b3257a80 100644 --- a/docs/Dockerfile +++ b/docs/Dockerfile @@ -1,12 +1,13 @@ -FROM python:3-alpine +ARG DISTRO=alpine:3.8 +FROM $DISTRO COPY requirements.txt /requirements.txt ARG version=master ENV VERSION=$version -RUN pip install -r /requirements.txt \ - && apk add --no-cache nginx curl \ +RUN apk add --no-cache nginx curl python3 \ + && pip3 install -r /requirements.txt \ && mkdir /run/nginx COPY ./nginx.conf /etc/nginx/conf.d/default.conf diff --git a/docs/rpi_build.rst b/docs/rpi_build.rst new file mode 100644 index 00000000..5796e188 --- /dev/null +++ b/docs/rpi_build.rst @@ -0,0 +1,25 @@ +.. _rpi_build: + +Building for a Raspberry Pi +=========================== + +The build does not need to be done on the Pi. + +To do so, go to ``tests/`` and call ``./build_arm.sh``, it will build all +necessary images for arm. + +To push the locally built images to a remote server, run ``./deploy_to_pi.sh``. +Docker 18.09+ is needed to use ``-H ssh://@``. + +Adjustments +----------- + +``build_arm.sh`` uses some variables passed as ``build-arg`` to docker-compose: + +- ``ALPINE_VER``: version of ALPINE to use +- ``DISTRO``: is the main distro used. Dockerfiles are set on Alpine 3.10, and + build script overrides for ``balenalib/rpi-alpine:3.10`` +- ``QEMU``: Used by webmails dockerfiles. It will add ``qemu-arm-static`` only + if ``QEMU`` is set to ``arm`` +- ``ARCH``: Architecture to use for ``admin``, and ``webmails`` as their images + are available for those architectures. diff --git a/docs/setup.rst b/docs/setup.rst index a68a4286..c150d29a 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -19,9 +19,7 @@ Prepare the environment Mailu images are designed to work on x86 or equivalent hardware, so it should run on pretty much any cloud server as long as enough power is -provided. If you find yourself running Mailu on small hardware, e.g. -Raspberry Pi or other platforms based on ARM, you will probably find -some support from `MFAshby's fork`_. +provided. For non x86 machines, see :ref:`rpi_build` You are free to choose any operating system that runs Docker (>= 1.11), then chose between various flavors including Docker Compose, Kubernetes @@ -34,7 +32,6 @@ You should also have at least a DNS hostname and a DNS name for receiving emails. Some instructions are provided on the matter in the article :ref:`dns_setup`. -.. _`MFAshby's fork`: https://github.com/MFAshby/Mailu Pick a Mailu version -------------------- diff --git a/optional/clamav/Dockerfile b/optional/clamav/Dockerfile index 02d0279a..60f8c87b 100644 --- a/optional/clamav/Dockerfile +++ b/optional/clamav/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip bash \ diff --git a/optional/postgresql/Dockerfile b/optional/postgresql/Dockerfile index 7f44204a..a2317426 100644 --- a/optional/postgresql/Dockerfile +++ b/optional/postgresql/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip bash \ diff --git a/optional/radicale/Dockerfile b/optional/radicale/Dockerfile index 66c1d5ca..ab819d69 100644 --- a/optional/radicale/Dockerfile +++ b/optional/radicale/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO RUN echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \ && apk add --no-cache radicale@testing curl bash diff --git a/services/fetchmail/Dockerfile b/services/fetchmail/Dockerfile index 756630f6..271dd68a 100644 --- a/services/fetchmail/Dockerfile +++ b/services/fetchmail/Dockerfile @@ -1,5 +1,6 @@ # First stage: Build -FROM alpine:3.10 as builder +ARG DISTRO=alpine:3.10 +FROM $DISTRO as builder # build dependencies RUN apk add --no-cache curl tar xz autoconf git gettext build-base openssl openssl-dev @@ -10,7 +11,8 @@ RUN cd fetchmail-7.0.0-alpha6 && \ ./configure --with-ssl --prefix /usr/local --disable-nls && \ make -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ diff --git a/services/rspamd/Dockerfile b/services/rspamd/Dockerfile index b7ee8653..2e4589f6 100644 --- a/services/rspamd/Dockerfile +++ b/services/rspamd/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip git bash \ diff --git a/services/unbound/Dockerfile b/services/unbound/Dockerfile index 62bc81ce..aa0abe25 100644 --- a/services/unbound/Dockerfile +++ b/services/unbound/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:3.10 +ARG DISTRO=alpine:3.10 +FROM $DISTRO # python3 shared with most images RUN apk add --no-cache \ python3 py3-pip git bash \ diff --git a/setup/Dockerfile b/setup/Dockerfile index 7c4ba773..2b3c3c6c 100644 --- a/setup/Dockerfile +++ b/setup/Dockerfile @@ -1,11 +1,12 @@ -FROM python:3-alpine +ARG DISTRO=alpine:3.10 +FROM $DISTRO RUN mkdir -p /app WORKDIR /app COPY requirements.txt requirements.txt -RUN apk add --no-cache curl \ - && pip install -r requirements.txt +RUN apk add --no-cache curl python3 py3-pip \ + && pip3 install -r requirements.txt COPY server.py ./server.py COPY main.py ./main.py diff --git a/tests/build_arm.sh b/tests/build_arm.sh new file mode 100755 index 00000000..04836ddb --- /dev/null +++ b/tests/build_arm.sh @@ -0,0 +1,15 @@ +#!/bin/bash -x + +ALPINE_VER="3.10" +DISTRO="balenalib/rpi-alpine:$ALPINE_VER" +# Used for webmails +QEMU="arm" +ARCH="arm32v7/" + +# use qemu-*-static from docker container +docker run --rm --privileged multiarch/qemu-user-static:register +docker-compose -f build.yml build \ + --build-arg DISTRO=$DISTRO \ + --build-arg ARCH=$ARCH \ + --build-arg QEMU=$QEMU \ + --parallel $@ diff --git a/tests/deploy_to_pi.sh b/tests/deploy_to_pi.sh new file mode 100755 index 00000000..dab5a53f --- /dev/null +++ b/tests/deploy_to_pi.sh @@ -0,0 +1,6 @@ +#!/bin/bash -x +# Small script to deploy locally built images to a remote docker +compose_options=$1 +images=$(docker-compose $1 images | awk 'NR > 2 { printf $2":"$3" " }') +docker save $images | pigz - > mail.local.tgz +echo "now run 'docker -H \"ssh://user@host\" load -i mail.local.tgz" diff --git a/towncrier/newsfragments/985.feature b/towncrier/newsfragments/985.feature new file mode 100644 index 00000000..99caa7e2 --- /dev/null +++ b/towncrier/newsfragments/985.feature @@ -0,0 +1 @@ +Add options to support different architectures builds diff --git a/webmails/rainloop/Dockerfile b/webmails/rainloop/Dockerfile index 140e1aff..05f8fa2d 100644 --- a/webmails/rainloop/Dockerfile +++ b/webmails/rainloop/Dockerfile @@ -1,4 +1,13 @@ -FROM php:7.3-apache +ARG ARCH="" +ARG QEMU=other + +# NOTE: only add file if building for arm +FROM ${ARCH}php:7.3-apache as build_arm +ONBUILD COPY --from=balenalib/rpi-alpine:3.10 /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static + +FROM ${ARCH}php:7.3-apache as build_other + +FROM build_${QEMU} #Shared layer between rainloop and roundcube RUN apt-get update && apt-get install -y \ python3 curl python3-pip git \ diff --git a/webmails/roundcube/Dockerfile b/webmails/roundcube/Dockerfile index 5fe9acbf..107c2a35 100644 --- a/webmails/roundcube/Dockerfile +++ b/webmails/roundcube/Dockerfile @@ -1,4 +1,12 @@ -FROM php:7.3-apache +# NOTE: only add file if building for arm +ARG ARCH="" +ARG QEMU=other +FROM ${ARCH}php:7.3-apache as build_arm +ONBUILD COPY --from=balenalib/rpi-alpine:3.10 /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static + +FROM ${ARCH}php:7.3-apache as build_other + +FROM build_${QEMU} #Shared layer between rainloop and roundcube RUN apt-get update && apt-get install -y \ python3 curl python3-pip git \