|
| 1 | +# syntax=docker/dockerfile:1.7 |
| 2 | + |
| 3 | +FROM --platform=$TARGETPLATFORM golang:alpine3.23 AS build |
| 4 | + |
| 5 | +ARG ENV_PROTONMAIL_BRIDGE_VERSION |
| 6 | +ARG ENV_PROTONMAIL_BRIDGE_COMMIT |
| 7 | +ARG TARGETPLATFORM |
| 8 | + |
| 9 | +# Install dependencies |
| 10 | +# hadolint ignore=DL3018 |
| 11 | +RUN set -eux; \ |
| 12 | + apk add --no-cache \ |
| 13 | + bash \ |
| 14 | + g++ \ |
| 15 | + git \ |
| 16 | + grep \ |
| 17 | + libcbor-dev \ |
| 18 | + libfido2-dev \ |
| 19 | + libsecret-dev \ |
| 20 | + make \ |
| 21 | + openssl-dev \ |
| 22 | + pkgconf \ |
| 23 | + sed |
| 24 | + |
| 25 | +WORKDIR /build/ |
| 26 | +RUN set -eux; \ |
| 27 | + : "${ENV_PROTONMAIL_BRIDGE_VERSION:?build arg ENV_PROTONMAIL_BRIDGE_VERSION is required}"; \ |
| 28 | + : "${ENV_PROTONMAIL_BRIDGE_COMMIT:?build arg ENV_PROTONMAIL_BRIDGE_COMMIT is required}"; \ |
| 29 | + git clone --depth 1 --single-branch --branch "$ENV_PROTONMAIL_BRIDGE_VERSION" https://github.com/ProtonMail/proton-bridge.git; \ |
| 30 | + actual_commit="$(git -C /build/proton-bridge rev-parse HEAD)"; \ |
| 31 | + if [ "${actual_commit}" != "${ENV_PROTONMAIL_BRIDGE_COMMIT}" ]; then \ |
| 32 | + echo "Expected commit ${ENV_PROTONMAIL_BRIDGE_COMMIT}, got ${actual_commit}" >&2; \ |
| 33 | + exit 1; \ |
| 34 | + fi; \ |
| 35 | + printf '%s\n' "$ENV_PROTONMAIL_BRIDGE_VERSION" > /build/BRIDGE_VERSION |
| 36 | +WORKDIR /build/proton-bridge/ |
| 37 | +RUN --mount=type=cache,target=/go/pkg/mod \ |
| 38 | + --mount=type=cache,target=/root/.cache/go-build \ |
| 39 | + set -eux; \ |
| 40 | + make build-nogui vault-editor |
| 41 | + |
| 42 | +# Working stage image |
| 43 | +FROM --platform=$TARGETPLATFORM alpine:3.23 |
| 44 | + |
| 45 | +# Define arguments and env variables |
| 46 | +ARG TARGETPLATFORM |
| 47 | +ARG ENV_PROTONMAIL_BRIDGE_VERSION |
| 48 | +ARG ENV_PROTONMAIL_BRIDGE_COMMIT |
| 49 | +ARG ENV_IMAGE_SOURCE=https://github.com/mgarratt/docker-images |
| 50 | +ARG ENV_IMAGE_REVISION=unknown |
| 51 | +# Indicate (NOT define) the ports/network interface really used by Proton bridge mail. |
| 52 | +# It should be 1025/tcp and 1143/tcp but on some k3s instances it could be 1026 and 1144 (why ?) |
| 53 | +# Launch `netstat -ltnp` on a running container to be sure. |
| 54 | +ARG ENV_BRIDGE_SMTP_PORT=1025 |
| 55 | +ARG ENV_BRIDGE_IMAP_PORT=1143 |
| 56 | +ARG ENV_BRIDGE_HOST=127.0.0.1 |
| 57 | +# Change ENV_CONTAINER_SMTP_PORT only if you have a docker port conflict on host network namespace. |
| 58 | +ARG ENV_CONTAINER_SMTP_PORT=1026 |
| 59 | +ARG ENV_CONTAINER_IMAP_PORT=1144 |
| 60 | +ENV PROTON_BRIDGE_SMTP_PORT=$ENV_BRIDGE_SMTP_PORT \ |
| 61 | + PROTON_BRIDGE_IMAP_PORT=$ENV_BRIDGE_IMAP_PORT \ |
| 62 | + PROTON_BRIDGE_HOST=$ENV_BRIDGE_HOST \ |
| 63 | + CONTAINER_SMTP_PORT=$ENV_CONTAINER_SMTP_PORT \ |
| 64 | + CONTAINER_IMAP_PORT=$ENV_CONTAINER_IMAP_PORT \ |
| 65 | + ENV_TARGET_PLATFORM=$TARGETPLATFORM |
| 66 | +LABEL org.opencontainers.image.source="$ENV_IMAGE_SOURCE" \ |
| 67 | + org.opencontainers.image.revision="$ENV_IMAGE_REVISION" \ |
| 68 | + org.opencontainers.image.version="$ENV_PROTONMAIL_BRIDGE_VERSION" \ |
| 69 | + org.opencontainers.image.upstream="https://github.com/ProtonMail/proton-bridge" \ |
| 70 | + org.opencontainers.image.upstream.revision="$ENV_PROTONMAIL_BRIDGE_COMMIT" \ |
| 71 | + org.opencontainers.image.title="proton-bridge" \ |
| 72 | + org.opencontainers.image.description="Headless Proton Mail Bridge with CLI tooling" |
| 73 | + |
| 74 | +# Install dependencies |
| 75 | +# hadolint ignore=DL3018 |
| 76 | +RUN set -eux; \ |
| 77 | + apk add --no-cache \ |
| 78 | + bash \ |
| 79 | + ca-certificates \ |
| 80 | + gpg \ |
| 81 | + gpg-agent \ |
| 82 | + gnupg-keyboxd \ |
| 83 | + libcbor \ |
| 84 | + libfido2 \ |
| 85 | + libsecret \ |
| 86 | + net-tools \ |
| 87 | + pass \ |
| 88 | + s6 \ |
| 89 | + socat |
| 90 | + |
| 91 | +RUN set -eux; \ |
| 92 | + addgroup -S bridge; \ |
| 93 | + adduser -S -G bridge -h /home/bridge bridge; \ |
| 94 | + mkdir -p /home/bridge /app; \ |
| 95 | + chown -R bridge:bridge /home/bridge /app |
| 96 | + |
| 97 | +# Copy executables made during previous stage |
| 98 | +WORKDIR /usr/bin/ |
| 99 | +COPY --from=build /build/proton-bridge/bridge /build/proton-bridge/proton-bridge /build/proton-bridge/vault-editor /usr/bin/ |
| 100 | + |
| 101 | +# Install needed scripts and files |
| 102 | +WORKDIR /app/ |
| 103 | +COPY --chmod=0755 entrypoint.sh /app/entrypoint.sh |
| 104 | +COPY --chmod=0755 healthcheck.sh /app/healthcheck.sh |
| 105 | +COPY GPGparams.txt /app/GPGparams.txt |
| 106 | +COPY LICENSE /app/licenses/LICENSE |
| 107 | +COPY NOTICE /app/licenses/NOTICE |
| 108 | +COPY --chmod=0755 services/.s6-finish-policy.sh /app/services/.s6-finish-policy.sh |
| 109 | +COPY --chmod=0755 services/bridge/run /app/services/bridge/run |
| 110 | +COPY --chmod=0755 services/bridge/finish /app/services/bridge/finish |
| 111 | +COPY --chmod=0755 services/gpg-agent/run /app/services/gpg-agent/run |
| 112 | +COPY --chmod=0755 services/gpg-agent/finish /app/services/gpg-agent/finish |
| 113 | +COPY --chmod=0755 services/socat-smtp/run /app/services/socat-smtp/run |
| 114 | +COPY --chmod=0755 services/socat-smtp/finish /app/services/socat-smtp/finish |
| 115 | +COPY --chmod=0755 services/socat-imap/run /app/services/socat-imap/run |
| 116 | +COPY --chmod=0755 services/socat-imap/finish /app/services/socat-imap/finish |
| 117 | +COPY --from=build /build/BRIDGE_VERSION /app/VERSION |
| 118 | +RUN set -eu; \ |
| 119 | + printf '%s\n' \ |
| 120 | + "upstream_source=https://github.com/ProtonMail/proton-bridge" \ |
| 121 | + "upstream_version=${ENV_PROTONMAIL_BRIDGE_VERSION}" \ |
| 122 | + "upstream_revision=${ENV_PROTONMAIL_BRIDGE_COMMIT}" \ |
| 123 | + "image_wrapper_source=${ENV_IMAGE_SOURCE}" \ |
| 124 | + "image_wrapper_revision=${ENV_IMAGE_REVISION}" \ |
| 125 | + > /app/CORRESPONDING_SOURCE |
| 126 | +RUN chown -R bridge:bridge /app |
| 127 | + |
| 128 | +# SMTP and IMAP ports are not exposed by default, so you could adjust them if necessary with ENV |
| 129 | +# variables CONTAINER_SMTP_PORT and CONTAINER_IMAP_PORT. |
| 130 | +# See README.md and/or compose.yaml file. |
| 131 | +# EXPOSE ${ENV_CONTAINER_SMTP_PORT}/tcp |
| 132 | +# EXPOSE ${ENV_CONTAINER_IMAP_PORT}/tcp |
| 133 | + |
| 134 | +# Volume to save pass and bridge configurations/data |
| 135 | +VOLUME /home/bridge |
| 136 | + |
| 137 | +HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=3 \ |
| 138 | + CMD ["/app/healthcheck.sh"] |
| 139 | + |
| 140 | +USER bridge:bridge |
| 141 | +ENTRYPOINT ["/app/entrypoint.sh"] |
0 commit comments