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-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
|
|
|
|
ARG GIT_REF=HEAD
|
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 \
|
2020-08-02 12:58:52 +02:00
|
|
|
cargo install --git "https://git.koesters.xyz/timo/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
|
|
|
|
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} \
|
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/" \
|
|
|
|
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="" \
|
2020-08-02 12:58:52 +02:00
|
|
|
org.label-schema.docker.build="docker build . -t conduit_homeserver: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)" \
|
|
|
|
maintainer="Weasy666"
|
2020-07-23 23:58:08 +02:00
|
|
|
|
2020-08-02 12:58:52 +02:00
|
|
|
# Standard port on which Rocket launches
|
|
|
|
EXPOSE 8000
|
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 \
|
|
|
|
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
|
|
|
|
|
|
|
# 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" ]
|