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-01 15:18:49 +02:00
|
|
|
# Alpine build image to build Conduits statically compiled binary
|
|
|
|
FROM alpine:3.12 as builder
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2020-08-01 18:20:30 +02:00
|
|
|
# Specifies if the local project is build or if the git master branch
|
|
|
|
# is build.
|
|
|
|
ARG LOCAL=false
|
|
|
|
|
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-01 18:20:30 +02:00
|
|
|
# Build it from local files or from official git repository
|
|
|
|
RUN if [[ $LOCAL == "true" ]]; then \
|
|
|
|
cargo install --path . ; \
|
|
|
|
else \
|
|
|
|
cargo install --git "https://git.koesters.xyz/timo/conduit.git" ; \
|
|
|
|
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
|
|
|
|
ARG GIT_REF=HEAD
|
|
|
|
|
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} \
|
|
|
|
org.opencontainers.image.authors="Conduit Contributors, weasy@hotmail.de" \
|
|
|
|
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/" \
|
|
|
|
org.opencontainers.image.revision=$GIT_REF \
|
|
|
|
org.opencontainers.image.source="https://git.koesters.xyz/timo/conduit.git" \
|
|
|
|
org.opencontainers.image.documentation.="" \
|
|
|
|
org.opencontainers.image.licenses="AGPL-3.0" \
|
|
|
|
org.opencontainers.image.ref.name="" \
|
|
|
|
org.label-schema.docker.build="docker build . -t 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-07-23 23:58:08 +02:00
|
|
|
maintainer="weasy@hotmail.de"
|
|
|
|
|
|
|
|
|
|
|
|
EXPOSE 14004
|
|
|
|
|
|
|
|
# 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
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2020-08-01 15:18:49 +02:00
|
|
|
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
|
|
|
|
|
|
|
RUN apk add --no-cache \
|
2020-08-01 15:18:49 +02:00
|
|
|
ca-certificates \
|
|
|
|
libgcc
|
|
|
|
|
|
|
|
VOLUME ["/srv/conduit/.local/share/conduit"]
|
2020-07-23 23:58:08 +02:00
|
|
|
|
|
|
|
# Set user to www-data
|
|
|
|
USER www-data
|
|
|
|
WORKDIR /srv/conduit
|
|
|
|
ENTRYPOINT [ "/srv/conduit/conduit" ]
|