2021-11-21 17:34:08 +00:00
|
|
|
# syntax=docker/dockerfile:1
|
2024-01-12 02:30:32 +00:00
|
|
|
FROM docker.io/rust:1.74.1-bullseye AS base
|
2023-06-10 15:35:22 +00:00
|
|
|
|
|
|
|
FROM base AS builder
|
2021-11-21 17:34:08 +00:00
|
|
|
WORKDIR /usr/src/conduit
|
2020-07-23 21:58:08 +00:00
|
|
|
|
2021-11-21 17:34:08 +00:00
|
|
|
# Install required packages to build Conduit and it's dependencies
|
2022-02-16 14:04:32 +00:00
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get -y --no-install-recommends install libclang-dev=1:11.0-51+nmu5
|
2020-07-23 21:58:08 +00:00
|
|
|
|
2021-11-21 17:34:08 +00: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 21:58:08 +00:00
|
|
|
|
2022-10-29 12:32:22 +00:00
|
|
|
|
|
|
|
# ONLY USEFUL FOR CI: target stage to extract build artifacts
|
|
|
|
FROM scratch AS builder-result
|
|
|
|
COPY --from=builder /usr/src/conduit/target/release/conduit /conduit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
# Build cargo-deb, a tool to package up rust binaries into .deb packages for Debian/Ubuntu based systems:
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
2023-06-10 15:35:22 +00:00
|
|
|
FROM base AS build-cargo-deb
|
2022-10-29 12:32:22 +00:00
|
|
|
|
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends \
|
|
|
|
dpkg \
|
|
|
|
dpkg-dev \
|
|
|
|
liblzma-dev
|
|
|
|
|
|
|
|
RUN cargo install cargo-deb
|
|
|
|
# => binary is in /usr/local/cargo/bin/cargo-deb
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
# Package conduit build-result into a .deb package:
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
FROM builder AS packager
|
|
|
|
WORKDIR /usr/src/conduit
|
|
|
|
|
|
|
|
COPY ./LICENSE ./LICENSE
|
|
|
|
COPY ./README.md ./README.md
|
2023-05-21 20:41:08 +00:00
|
|
|
COPY debian ./debian
|
2022-10-29 12:32:22 +00:00
|
|
|
COPY --from=build-cargo-deb /usr/local/cargo/bin/cargo-deb /usr/local/cargo/bin/cargo-deb
|
|
|
|
|
|
|
|
# --no-build makes cargo-deb reuse already compiled project
|
|
|
|
RUN cargo deb --no-build
|
|
|
|
# => Package is in /usr/src/conduit/target/debian/<project_name>_<version>_<arch>.deb
|
|
|
|
|
|
|
|
|
|
|
|
# ONLY USEFUL FOR CI: target stage to extract build artifacts
|
|
|
|
FROM scratch AS packager-result
|
|
|
|
COPY --from=packager /usr/src/conduit/target/debian/*.deb /conduit.deb
|
|
|
|
|
|
|
|
|
2021-11-21 17:34:08 +00:00
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
# Stuff below this line actually ends up in the resulting docker image
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------
|
2022-02-02 13:07:35 +00:00
|
|
|
FROM docker.io/debian:bullseye-slim AS runner
|
2021-11-21 17:34:08 +00: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 08:40:57 +00:00
|
|
|
EXPOSE 6167
|
2020-07-23 21:58:08 +00:00
|
|
|
|
2022-06-25 21:59:49 +00:00
|
|
|
ARG DEFAULT_DB_PATH=/var/lib/matrix-conduit
|
|
|
|
|
2022-02-13 12:25:19 +00:00
|
|
|
ENV CONDUIT_PORT=6167 \
|
2022-02-13 12:38:13 +00:00
|
|
|
CONDUIT_ADDRESS="0.0.0.0" \
|
2022-06-25 21:59:49 +00:00
|
|
|
CONDUIT_DATABASE_PATH=${DEFAULT_DB_PATH} \
|
2022-02-16 13:04:45 +00:00
|
|
|
CONDUIT_CONFIG=''
|
|
|
|
# └─> Set no config file to do all configuration with env vars
|
2021-11-21 17:34:08 +00:00
|
|
|
|
|
|
|
# Conduit needs:
|
2022-10-29 12:32:22 +00:00
|
|
|
# dpkg: to install conduit.deb
|
2021-11-21 17:34:08 +00:00
|
|
|
# ca-certificates: for https
|
2022-02-02 13:07:35 +00:00
|
|
|
# iproute2 & wget: for the healthcheck script
|
2022-02-16 14:04:32 +00:00
|
|
|
RUN apt-get update && apt-get -y --no-install-recommends install \
|
2022-10-29 12:32:22 +00:00
|
|
|
dpkg \
|
2021-12-15 10:14:20 +00:00
|
|
|
ca-certificates \
|
2022-02-02 13:07:35 +00:00
|
|
|
iproute2 \
|
2022-02-02 13:35:15 +00:00
|
|
|
wget \
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
2021-11-21 17:34:08 +00:00
|
|
|
|
|
|
|
# Test if Conduit is still alive, uses the same endpoint as Element
|
2021-11-25 22:36:44 +00:00
|
|
|
COPY ./docker/healthcheck.sh /srv/conduit/healthcheck.sh
|
2021-11-21 17:34:08 +00:00
|
|
|
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
|
|
|
|
|
2022-10-29 12:32:22 +00:00
|
|
|
# Install conduit.deb:
|
|
|
|
COPY --from=packager /usr/src/conduit/target/debian/*.deb /srv/conduit/
|
|
|
|
RUN dpkg -i /srv/conduit/*.deb
|
2021-11-21 17:34:08 +00:00
|
|
|
|
2022-02-02 13:07:35 +00:00
|
|
|
# Improve security: Don't run stuff as root, that does not need to run as root
|
2022-02-16 14:04:32 +00:00
|
|
|
# Most distros also use 1000:1000 for the first real user, so this should resolve volume mounting problems.
|
|
|
|
ARG USER_ID=1000
|
|
|
|
ARG GROUP_ID=1000
|
2020-07-23 21:58:08 +00:00
|
|
|
RUN set -x ; \
|
2022-02-16 14:04:32 +00:00
|
|
|
groupadd -r -g ${GROUP_ID} conduit ; \
|
|
|
|
useradd -l -r -M -d /srv/conduit -o -u ${USER_ID} -g conduit conduit && exit 0 ; exit 1
|
2020-07-23 21:58:08 +00:00
|
|
|
|
2022-06-25 21:59:49 +00:00
|
|
|
# Create database directory, change ownership of Conduit files to conduit user and group and make the healthcheck executable:
|
2022-02-02 13:07:35 +00:00
|
|
|
RUN chown -cR conduit:conduit /srv/conduit && \
|
2022-06-25 21:59:49 +00:00
|
|
|
chmod +x /srv/conduit/healthcheck.sh && \
|
|
|
|
mkdir -p ${DEFAULT_DB_PATH} && \
|
|
|
|
chown -cR conduit:conduit ${DEFAULT_DB_PATH}
|
2022-10-29 12:32:22 +00:00
|
|
|
|
2022-02-02 13:07:35 +00:00
|
|
|
# Change user to conduit, no root permissions afterwards:
|
|
|
|
USER conduit
|
2020-08-02 10:58:52 +00:00
|
|
|
# Set container home directory
|
2020-07-23 21:58:08 +00:00
|
|
|
WORKDIR /srv/conduit
|
2021-11-21 17:34:08 +00:00
|
|
|
|
|
|
|
# Run Conduit and print backtraces on panics
|
|
|
|
ENV RUST_BACKTRACE=1
|
2022-10-29 12:32:22 +00:00
|
|
|
ENTRYPOINT [ "/usr/sbin/matrix-conduit" ]
|