2021-11-21 10:34:08 -07:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
FROM docker.io/rust:1.53-alpine AS builder
|
|
|
|
WORKDIR /usr/src/conduit
|
2020-07-23 14:58:08 -07:00
|
|
|
|
2021-11-21 10:34:08 -07:00
|
|
|
# Install required packages to build Conduit and it's dependencies
|
|
|
|
RUN apk add musl-dev
|
2020-07-23 14:58:08 -07:00
|
|
|
|
2021-11-21 10:34:08 -07:00
|
|
|
# == Build dependencies without our own code separately for caching ==
|
|
|
|
#
|
|
|
|
# Need a fake main.rs since Cargo refuses to build anything otherwise.
|
|
|
|
#
|
|
|
|
# See https://github.com/rust-lang/cargo/issues/2644 for a Cargo feature
|
|
|
|
# request that would allow just dependencies to be compiled, presumably
|
|
|
|
# regardless of whether source files are available.
|
|
|
|
RUN mkdir src && touch src/lib.rs && echo 'fn main() {}' > src/main.rs
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
RUN cargo build --release && rm -r src
|
|
|
|
|
|
|
|
# Copy over actual Conduit sources
|
|
|
|
COPY src src
|
|
|
|
|
|
|
|
# main.rs and lib.rs need their timestamp updated for this to work correctly since
|
|
|
|
# otherwise the build with the fake main.rs from above is newer than the
|
|
|
|
# source files (COPY preserves timestamps).
|
|
|
|
#
|
|
|
|
# Builds conduit and places the binary at /usr/src/conduit/target/release/conduit
|
|
|
|
RUN touch src/main.rs && touch src/lib.rs && cargo build --release
|
2020-07-23 14:58:08 -07:00
|
|
|
|
|
|
|
|
2021-03-16 01:14:11 -07:00
|
|
|
|
2021-11-21 10:34:08 -07:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
# Stuff below this line actually ends up in the resulting docker image
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
2021-12-15 03:14:20 -07:00
|
|
|
FROM docker.io/alpine:3.15.0 AS runner
|
2021-11-21 10:34:08 -07:00
|
|
|
|
|
|
|
# Standard port on which Conduit launches.
|
|
|
|
# You still need to map the port when using the docker command or docker-compose.
|
2021-07-06 01:40:57 -07:00
|
|
|
EXPOSE 6167
|
2020-07-23 14:58:08 -07:00
|
|
|
|
2021-11-21 10:34:08 -07:00
|
|
|
# Note from @jfowl: I would like to remove this in the future and just have the Docker version be configured with envs.
|
|
|
|
ENV CONDUIT_CONFIG="/srv/conduit/conduit.toml"
|
|
|
|
|
|
|
|
# Conduit needs:
|
|
|
|
# ca-certificates: for https
|
|
|
|
# libgcc: Apparently this is needed, even if I (@jfowl) don't know exactly why. But whatever, it's not that big.
|
|
|
|
RUN apk add --no-cache \
|
2021-12-15 03:14:20 -07:00
|
|
|
ca-certificates \
|
|
|
|
libgcc
|
2021-11-21 10:34:08 -07:00
|
|
|
|
|
|
|
|
|
|
|
# Created directory for the database and media files
|
2020-08-01 06:18:49 -07:00
|
|
|
RUN mkdir -p /srv/conduit/.local/share/conduit
|
2020-07-23 14:58:08 -07:00
|
|
|
|
2021-11-21 10:34:08 -07:00
|
|
|
# Test if Conduit is still alive, uses the same endpoint as Element
|
2021-11-25 15:36:44 -07:00
|
|
|
COPY ./docker/healthcheck.sh /srv/conduit/healthcheck.sh
|
2021-11-21 10:34:08 -07:00
|
|
|
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
|
|
|
|
|
|
|
|
# Copy over the actual Conduit binary from the builder stage
|
2021-11-25 15:36:44 -07:00
|
|
|
COPY --from=builder /usr/src/conduit/target/release/conduit /srv/conduit/conduit
|
2021-11-21 10:34:08 -07:00
|
|
|
|
|
|
|
# Improve security: Don't run stuff as root, that does not need to run as root:
|
2020-07-23 14:58:08 -07: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 06:18:49 -07:00
|
|
|
RUN chown -cR www-data:www-data /srv/conduit
|
2021-11-21 10:34:08 -07:00
|
|
|
RUN chmod +x /srv/conduit/healthcheck.sh
|
2020-07-23 14:58:08 -07:00
|
|
|
|
2021-11-21 10:34:08 -07:00
|
|
|
# Change user to www-data
|
2020-07-23 14:58:08 -07:00
|
|
|
USER www-data
|
2020-08-02 03:58:52 -07:00
|
|
|
# Set container home directory
|
2020-07-23 14:58:08 -07:00
|
|
|
WORKDIR /srv/conduit
|
2021-11-21 10:34:08 -07:00
|
|
|
|
|
|
|
# Run Conduit and print backtraces on panics
|
|
|
|
ENV RUST_BACKTRACE=1
|
|
|
|
ENTRYPOINT [ "/srv/conduit/conduit" ]
|