Browse Source

Bring Dockerfiles into sync

merge-requests/225/head
Jonas Zohren 4 years ago
parent
commit
ef9633bfda
No known key found for this signature in database
GPG Key ID: FE3ED5D90A175463
  1. 32
      Dockerfile
  2. 32
      docker/ci-binaries-packaging.Dockerfile

32
Dockerfile

@ -34,6 +34,13 @@ RUN touch src/main.rs && touch src/lib.rs && cargo build --release
# --------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------
FROM docker.io/alpine:3.14 AS runner FROM docker.io/alpine:3.14 AS runner
# Standard port on which Conduit launches.
# You still need to map the port when using the docker command or docker-compose.
EXPOSE 6167
# 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: # Conduit needs:
# ca-certificates: for https # ca-certificates: for https
# curl: for the container's healtcheck # curl: for the container's healtcheck
@ -43,17 +50,34 @@ RUN apk add --no-cache \
curl \ curl \
libgcc libgcc
# Created directory for the database and media files # Created directory for the database and media files
RUN mkdir -p /srv/conduit/.local/share/conduit RUN mkdir -p /srv/conduit/.local/share/conduit
# Test if Conduit is still alive, uses the same endpoint as Element
COPY ./docker/healthcheck.sh /srv/conduit/
HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
# Copy over the actual Conduit binary from the builder stage # Copy over the actual Conduit binary from the builder stage
COPY --from=builder /usr/src/conduit/target/release/conduit /srv/conduit/ COPY --from=builder /usr/src/conduit/target/release/conduit /srv/conduit/
# Note from @jfowl: I would like to remove this in the future and just have the Docker version be configured with envs. # Improve security: Don't run stuff as root, that does not need to run as root:
ENV CONDUIT_CONFIG="/srv/conduit/conduit.toml" # 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
# Not strictly needed, but documents the port. # Change ownership of Conduit files to www-data user and group
EXPOSE 6167 RUN chown -cR www-data:www-data /srv/conduit
RUN chmod +x /srv/conduit/healthcheck.sh
# Change user to www-data
USER www-data
# Set container home directory
WORKDIR /srv/conduit WORKDIR /srv/conduit
# Run Conduit and print backtraces on panics
ENV RUST_BACKTRACE=1
ENTRYPOINT [ "/srv/conduit/conduit" ] ENTRYPOINT [ "/srv/conduit/conduit" ]

32
docker/ci-binaries-packaging.Dockerfile

@ -8,20 +8,28 @@
# Credit's for the original Dockerfile: Weasy666. # Credit's for the original Dockerfile: Weasy666.
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
FROM alpine:3.14 FROM docker.io/alpine:3.14 AS runner
# Install packages needed to run Conduit # Standard port on which Conduit launches.
# You still need to map the port when using the docker command or docker-compose.
EXPOSE 6167
# 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
# curl: for the container's healtcheck
# 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 \ RUN apk add --no-cache \
ca-certificates \ ca-certificates \
curl \ curl \
libgcc libgcc
ARG CREATED ARG CREATED
ARG VERSION ARG VERSION
ARG GIT_REF ARG GIT_REF
ENV CONDUIT_CONFIG="/srv/conduit/conduit.toml"
# Labels according to https://github.com/opencontainers/image-spec/blob/master/annotations.md # Labels according to https://github.com/opencontainers/image-spec/blob/master/annotations.md
# including a custom label specifying the build command # including a custom label specifying the build command
LABEL org.opencontainers.image.created=${CREATED} \ LABEL org.opencontainers.image.created=${CREATED} \
@ -37,23 +45,21 @@ LABEL org.opencontainers.image.created=${CREATED} \
org.opencontainers.image.documentation="https://gitlab.com/famedly/conduit" \ org.opencontainers.image.documentation="https://gitlab.com/famedly/conduit" \
org.opencontainers.image.ref.name="" org.opencontainers.image.ref.name=""
# Standard port on which Conduit launches. You still need to map the port when using the docker command or docker-compose. # Created directory for the database and media files
EXPOSE 6167
# create data folder for database
RUN mkdir -p /srv/conduit/.local/share/conduit RUN mkdir -p /srv/conduit/.local/share/conduit
# Test if Conduit is still alive, uses the same endpoint as Element # Test if Conduit is still alive, uses the same endpoint as Element
COPY ./docker/healthcheck.sh /srv/conduit/ COPY ./docker/healthcheck.sh /srv/conduit/
HEALTHCHECK --start-period=5s --interval=20s CMD ./healthcheck.sh HEALTHCHECK --start-period=5s --interval=5s CMD ./healthcheck.sh
# Copy the Conduit binary into the image at the latest possible moment to maximise caching:
# depending on the target platform (e.g. "linux/arm/v7", "linux/arm64/v8", or "linux/amd64") # Depending on the target platform (e.g. "linux/arm/v7", "linux/arm64/v8", or "linux/amd64")
# copy the matching binary into this docker image # copy the matching binary into this docker image
ARG TARGETPLATFORM ARG TARGETPLATFORM
COPY ./$TARGETPLATFORM /srv/conduit/conduit COPY ./$TARGETPLATFORM /srv/conduit/conduit
# Improve security: Don't run stuff as root, that does not need to run as root:
# Add www-data user and group with UID 82, as used by alpine # Add www-data user and group with UID 82, as used by alpine
# https://git.alpinelinux.org/aports/tree/main/nginx/nginx.pre-install # https://git.alpinelinux.org/aports/tree/main/nginx/nginx.pre-install
RUN set -x ; \ RUN set -x ; \
@ -65,7 +71,7 @@ RUN set -x ; \
RUN chown -cR www-data:www-data /srv/conduit RUN chown -cR www-data:www-data /srv/conduit
RUN chmod +x /srv/conduit/healthcheck.sh RUN chmod +x /srv/conduit/healthcheck.sh
# Set user to www-data # Change user to www-data
USER www-data USER www-data
# Set container home directory # Set container home directory
WORKDIR /srv/conduit WORKDIR /srv/conduit

Loading…
Cancel
Save