A Matrix homeserver written in Rust https://conduit.rs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

99 lines
3.7 KiB

  1. # Using multistage build:
  2. # https://docs.docker.com/develop/develop-images/multistage-build/
  3. # https://whitfin.io/speeding-up-rust-docker-builds/
  4. ########################## BUILD IMAGE ##########################
  5. # Alpine build image to build Conduit's statically compiled binary
  6. FROM alpine:3.12 as builder
  7. # Specifies if the local project is build or if Conduit gets build
  8. # from the official git repository. Defaults to the git repo.
  9. ARG LOCAL=false
  10. # Specifies which revision/commit is build. Defaults to HEAD
  11. ARG GIT_REF=HEAD
  12. # Add 'edge'-repository to get Rust 1.45
  13. RUN sed -i \
  14. -e 's|v3\.12|edge|' \
  15. /etc/apk/repositories
  16. # Install packages needed for building all crates
  17. RUN apk add --no-cache \
  18. cargo \
  19. openssl-dev
  20. # Copy project files from current folder
  21. COPY . .
  22. # Build it from the copied local files or from the official git repository
  23. RUN if [[ $LOCAL == "true" ]]; then \
  24. cargo install --path . ; \
  25. else \
  26. cargo install --git "https://git.koesters.xyz/timo/conduit.git" --rev ${GIT_REF}; \
  27. fi
  28. ########################## RUNTIME IMAGE ##########################
  29. # Create new stage with a minimal image for the actual
  30. # runtime image/container
  31. FROM alpine:3.12
  32. ARG CREATED
  33. ARG VERSION
  34. ARG GIT_REF=HEAD
  35. # Labels according to https://github.com/opencontainers/image-spec/blob/master/annotations.md
  36. # including a custom label specifying the build command
  37. LABEL org.opencontainers.image.created=${CREATED} \
  38. org.opencontainers.image.authors="Conduit Contributors" \
  39. org.opencontainers.image.title="Conduit" \
  40. org.opencontainers.image.version=${VERSION} \
  41. org.opencontainers.image.vendor="Conduit Contributors" \
  42. org.opencontainers.image.description="A Matrix homeserver written in Rust" \
  43. org.opencontainers.image.url="https://conduit.rs/" \
  44. org.opencontainers.image.revision=${GIT_REF} \
  45. org.opencontainers.image.source="https://git.koesters.xyz/timo/conduit.git" \
  46. org.opencontainers.image.licenses="AGPL-3.0-only" \
  47. org.opencontainers.image.documentation="" \
  48. org.opencontainers.image.ref.name="" \
  49. org.label-schema.docker.build="docker build . -t matrixconduit/matrix-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)" \
  50. maintainer="Weasy666"
  51. # Standard port on which Rocket launches
  52. EXPOSE 8000
  53. # Copy config files from context and the binary from
  54. # the "builder" stage to the current stage into folder
  55. # /srv/conduit and create data folder for database
  56. RUN mkdir -p /srv/conduit/.local/share/conduit
  57. COPY --from=builder /root/.cargo/bin/conduit /srv/conduit/
  58. # Add www-data user and group with UID 82, as used by alpine
  59. # https://git.alpinelinux.org/aports/tree/main/nginx/nginx.pre-install
  60. RUN set -x ; \
  61. addgroup -Sg 82 www-data 2>/dev/null ; \
  62. adduser -S -D -H -h /srv/conduit -G www-data -g www-data www-data 2>/dev/null ; \
  63. addgroup www-data www-data 2>/dev/null && exit 0 ; exit 1
  64. # Change ownership of Conduit files to www-data user and group
  65. RUN chown -cR www-data:www-data /srv/conduit
  66. # Install packages needed to run Conduit
  67. RUN apk add --no-cache \
  68. ca-certificates \
  69. curl \
  70. libgcc
  71. # Create a volume for the database, to persist its contents
  72. VOLUME ["/srv/conduit/.local/share/conduit"]
  73. # Test if Conduit is still alive, uses the same endpoint as Element
  74. HEALTHCHECK --start-period=2s CMD curl --fail -s http://localhost:8000/_matrix/client/versions || curl -k --fail -s https://localhost:8000/_matrix/client/versions || exit 1
  75. # Set user to www-data
  76. USER www-data
  77. # Set container home directory
  78. WORKDIR /srv/conduit
  79. # Run Conduit
  80. ENTRYPOINT [ "/srv/conduit/conduit" ]