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

Permit raspberry pi (and other architectures) builds #985

Merged
merged 16 commits into from Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ pip-selfcheck.json
/docker-compose.yml
/.idea
/.vscode
qemu-arm-static
1 change: 1 addition & 0 deletions CHANGELOG.md.20190330
@@ -0,0 +1 @@
find . -iname 'dockerfile' -exec sed -i "s/FROM.*/ARG DISTRO=alpine:3.8\nFROM \$DISTRO/" '{}' \;
abondis marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 6 additions & 4 deletions 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
Expand All @@ -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 \
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion 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 \
Expand Down
3 changes: 2 additions & 1 deletion 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 \
Expand Down
3 changes: 2 additions & 1 deletion 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
3 changes: 2 additions & 1 deletion 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 \
Expand Down
7 changes: 4 additions & 3 deletions 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
Expand Down
19 changes: 19 additions & 0 deletions docs/rpi_build.rst
@@ -0,0 +1,19 @@
.. _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://<user>@<host>``.

Adjustments
-----------

``build_arm.sh`` uses some variables passed as ``build-arg`` to docker-compose:

- ``DISTRO``: is the main distro used (ie: alpine:3.8)
- ``PHP_DISTRO``: is used for the ``rainloop`` and ``roundcube`` images
- ``EDGE_DISTRO``: is used for ``radicale`` as edge has dulwich and radicale as packages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edge is no longer used:

FROM alpine:3.10

5 changes: 1 addition & 4 deletions docs/setup.rst
Expand Up @@ -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
Expand All @@ -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
--------------------
Expand Down
3 changes: 2 additions & 1 deletion 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 \
Expand Down
3 changes: 2 additions & 1 deletion 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 \
Expand Down
3 changes: 2 additions & 1 deletion optional/radicale/Dockerfile
@@ -1,4 +1,5 @@
FROM alpine:3.10
ARG DISTRO=alpine:3.10
FROM $DISTRO

muhlemmer marked this conversation as resolved.
Show resolved Hide resolved
RUN echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk add --no-cache radicale@testing curl bash
Expand Down
6 changes: 4 additions & 2 deletions 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
Expand All @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion 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 \
Expand Down
3 changes: 2 additions & 1 deletion 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 \
Expand Down
7 changes: 4 additions & 3 deletions setup/Dockerfile
@@ -1,11 +1,12 @@
FROM python:3-alpine
ARG DISTRO=alpine:3.8
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
RUN pip3 install -r requirements.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small notice, this should not be split in two layera.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep these actions in a single RUN statement, in order to avoid additional layers.

COPY server.py ./server.py
COPY main.py ./main.py
Expand Down
15 changes: 15 additions & 0 deletions tests/build_arm.sh
@@ -0,0 +1,15 @@
#!/bin/bash -x

ALPINE_VER="3.10"
DISTRO="balenalib/rpi-alpine:$ALPINE_VER"
# Used for webmails
muhlemmer marked this conversation as resolved.
Show resolved Hide resolved
QEMU="arm"
ARCH="arm32v7/"

# use qemu-*-static from docker container
docker run --rm --privileged multiarch/qemu-user-static:register
muhlemmer marked this conversation as resolved.
Show resolved Hide resolved
docker-compose -f build.yml build \
--build-arg DISTRO=$DISTRO \
--build-arg ARCH=$ARCH \
--build-arg QEMU=$QEMU \
--parallel $@
6 changes: 6 additions & 0 deletions 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"
1 change: 1 addition & 0 deletions towncrier/newsfragments/985.feature
@@ -0,0 +1 @@
Add options to support different architectures builds
11 changes: 10 additions & 1 deletion 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 \
Expand Down
10 changes: 9 additions & 1 deletion 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 \
Expand Down