2020-07-23 23:58:08 +02:00
|
|
|
# Using multistage build:
|
|
|
|
# https://docs.docker.com/develop/develop-images/multistage-build/
|
|
|
|
# https://whitfin.io/speeding-up-rust-docker-builds/
|
|
|
|
|
|
|
|
|
|
|
|
########################## BUILD IMAGE ##########################
|
2020-08-04 22:04:27 +02:00
|
|
|
# Alpine build image to build Conduit's statically compiled binary
|
2020-08-01 15:18:49 +02:00
|
|
|
FROM alpine:3.12 as builder
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2020-08-02 12:58:52 +02:00
|
|
|
# Specifies if the local project is build or if Conduit gets build
|
|
|
|
# from the official git repository. Defaults to the git repo.
|
2020-08-01 18:20:30 +02:00
|
|
|
ARG LOCAL=false
|
2020-08-02 12:58:52 +02:00
|
|
|
# Specifies which revision/commit is build. Defaults to HEAD
|
2020-10-18 23:06:08 +02:00
|
|
|
ARG GIT_REF=origin/master
|
2020-08-01 18:20:30 +02:00
|
|
|
|
2020-08-01 15:18:49 +02:00
|
|
|
# Add 'edge'-repository to get Rust 1.45
|
|
|
|
RUN sed -i \
|
|
|
|
-e 's|v3\.12|edge|' \
|
|
|
|
/etc/apk/repositories
|
2020-07-23 23:58:08 +02:00
|
|
|
|
|
|
|
# Install packages needed for building all crates
|
|
|
|
RUN apk add --no-cache \
|
2020-08-01 15:18:49 +02:00
|
|
|
cargo \
|
|
|
|
openssl-dev
|
|
|
|
|
2020-08-01 18:20:30 +02:00
|
|
|
|
|
|
|
# Copy project files from current folder
|
2020-07-23 23:58:08 +02:00
|
|
|
COPY . .
|
2020-08-02 12:58:52 +02:00
|
|
|
# Build it from the copied local files or from the official git repository
|
2020-08-01 18:20:30 +02:00
|
|
|
RUN if [[ $LOCAL == "true" ]]; then \
|
|
|
|
cargo install --path . ; \
|
|
|
|
else \
|
2021-03-12 18:26:23 +01:00
|
|
|
cargo install --git "https://gitlab.com/famedly/conduit.git" --rev ${GIT_REF}; \
|
2020-08-01 18:20:30 +02:00
|
|
|
fi
|
2020-07-23 23:58:08 +02:00
|
|
|
|
|
|
|
########################## RUNTIME IMAGE ##########################
|
|
|
|
# Create new stage with a minimal image for the actual
|
|
|
|
# runtime image/container
|
|
|
|
FROM alpine:3.12
|
|
|
|
|
2020-07-27 18:10:34 +02:00
|
|
|
ARG CREATED
|
2020-07-23 23:58:08 +02:00
|
|
|
ARG VERSION
|
2021-03-12 18:26:23 +01:00
|
|
|
ARG GIT_REF=origin/master
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2021-03-16 09:14:11 +01:00
|
|
|
ENV CONDUIT_CONFIG="/srv/conduit/conduit.toml"
|
|
|
|
|
2020-07-27 18:10:34 +02:00
|
|
|
# Labels according to https://github.com/opencontainers/image-spec/blob/master/annotations.md
|
|
|
|
# including a custom label specifying the build command
|
|
|
|
LABEL org.opencontainers.image.created=${CREATED} \
|
2020-08-02 12:58:52 +02:00
|
|
|
org.opencontainers.image.authors="Conduit Contributors" \
|
2020-07-27 18:10:34 +02:00
|
|
|
org.opencontainers.image.title="Conduit" \
|
|
|
|
org.opencontainers.image.version=${VERSION} \
|
|
|
|
org.opencontainers.image.vendor="Conduit Contributors" \
|
|
|
|
org.opencontainers.image.description="A Matrix homeserver written in Rust" \
|
|
|
|
org.opencontainers.image.url="https://conduit.rs/" \
|
2020-08-04 22:04:27 +02:00
|
|
|
org.opencontainers.image.revision=${GIT_REF} \
|
2021-03-12 18:26:23 +01:00
|
|
|
org.opencontainers.image.source="https://gitlab.com/famedly/conduit.git" \
|
2020-08-24 11:32:15 +02:00
|
|
|
org.opencontainers.image.licenses="Apache-2.0" \
|
2020-08-24 23:30:39 +02:00
|
|
|
org.opencontainers.image.documentation="" \
|
2020-07-27 18:10:34 +02:00
|
|
|
org.opencontainers.image.ref.name="" \
|
2020-08-24 23:30:39 +02:00
|
|
|
org.label-schema.docker.build="docker build . -t matrixconduit/matrix-conduit:latest --build-arg CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ') --build-arg VERSION=$(grep -m1 -o '[0-9].[0-9].[0-9]' Cargo.toml)" \
|
2020-08-02 12:58:52 +02:00
|
|
|
maintainer="Weasy666"
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2021-07-06 10:40:57 +02:00
|
|
|
# Standard port on which Conduit launches. You still need to map the port when using the docker command or docker-compose.
|
|
|
|
EXPOSE 6167
|
2020-07-23 23:58:08 +02:00
|
|
|
|
|
|
|
# Copy config files from context and the binary from
|
|
|
|
# the "builder" stage to the current stage into folder
|
|
|
|
# /srv/conduit and create data folder for database
|
2020-08-01 15:18:49 +02:00
|
|
|
RUN mkdir -p /srv/conduit/.local/share/conduit
|
|
|
|
COPY --from=builder /root/.cargo/bin/conduit /srv/conduit/
|
2020-07-23 23:58:08 +02:00
|
|
|
|
|
|
|
# Add www-data user and group with UID 82, as used by alpine
|
|
|
|
# https://git.alpinelinux.org/aports/tree/main/nginx/nginx.pre-install
|
|
|
|
RUN set -x ; \
|
|
|
|
addgroup -Sg 82 www-data 2>/dev/null ; \
|
|
|
|
adduser -S -D -H -h /srv/conduit -G www-data -g www-data www-data 2>/dev/null ; \
|
|
|
|
addgroup www-data www-data 2>/dev/null && exit 0 ; exit 1
|
|
|
|
|
|
|
|
# Change ownership of Conduit files to www-data user and group
|
2020-08-01 15:18:49 +02:00
|
|
|
RUN chown -cR www-data:www-data /srv/conduit
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2020-08-02 12:58:52 +02:00
|
|
|
# Install packages needed to run Conduit
|
2020-07-23 23:58:08 +02:00
|
|
|
RUN apk add --no-cache \
|
2020-08-01 15:18:49 +02:00
|
|
|
ca-certificates \
|
2020-08-24 23:30:39 +02:00
|
|
|
curl \
|
2020-08-01 15:18:49 +02:00
|
|
|
libgcc
|
|
|
|
|
2020-08-02 12:58:52 +02:00
|
|
|
# Create a volume for the database, to persist its contents
|
2020-08-01 15:18:49 +02:00
|
|
|
VOLUME ["/srv/conduit/.local/share/conduit"]
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2020-08-24 23:30:39 +02:00
|
|
|
# Test if Conduit is still alive, uses the same endpoint as Element
|
2021-07-06 10:40:57 +02:00
|
|
|
HEALTHCHECK --start-period=5s \
|
|
|
|
CMD curl --fail -s "http://localhost:$(grep -m1 -o 'port\s=\s[0-9]*' conduit.toml | grep -m1 -o '[0-9]*')/_matrix/client/versions" || \
|
|
|
|
curl -k --fail -s "https://localhost:$(grep -m1 -o 'port\s=\s[0-9]*' conduit.toml | grep -m1 -o '[0-9]*')/_matrix/client/versions" || \
|
|
|
|
exit 1
|
2020-08-24 23:30:39 +02:00
|
|
|
|
2020-07-23 23:58:08 +02:00
|
|
|
# Set user to www-data
|
|
|
|
USER www-data
|
2020-08-02 12:58:52 +02:00
|
|
|
# Set container home directory
|
2020-07-23 23:58:08 +02:00
|
|
|
WORKDIR /srv/conduit
|
2020-08-02 12:58:52 +02:00
|
|
|
# Run Conduit
|
2020-07-23 23:58:08 +02:00
|
|
|
ENTRYPOINT [ "/srv/conduit/conduit" ]
|