Dockerfile 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # This file was generated using a Jinja2 template.
  2. # Please make your changes in `Dockerfile.j2` and then `make` the individual Dockerfile's.
  3. # Using multistage build:
  4. # https://docs.docker.com/develop/develop-images/multistage-build/
  5. # https://whitfin.io/speeding-up-rust-docker-builds/
  6. ####################### VAULT BUILD IMAGE #######################
  7. # This hash is extracted from the docker web-vault builds and it's prefered over a simple tag because it's immutable.
  8. # It can be viewed in multiple ways:
  9. # - From the https://hub.docker.com/repository/docker/bitwardenrs/web-vault/tags page, click the tag name and the digest should be there.
  10. # - From the console, with the following commands:
  11. # docker pull bitwardenrs/web-vault:v2.13.2b
  12. # docker image inspect --format "{{.RepoDigests}}" bitwardenrs/web-vault:v2.13.2b
  13. #
  14. # - To do the opposite, and get the tag from the hash, you can do:
  15. # docker image inspect --format "{{.RepoTags}}" bitwardenrs/web-vault@sha256:f32c555a2bc3ee6bc0718319b1e8057c10ef889cf7231f0ff217af98486da554
  16. FROM bitwardenrs/web-vault@sha256:f32c555a2bc3ee6bc0718319b1e8057c10ef889cf7231f0ff217af98486da554 as vault
  17. ########################## BUILD IMAGE ##########################
  18. # We need to use the Rust build image, because
  19. # we need the Rust compiler and Cargo tooling
  20. FROM rust:1.40 as build
  21. # set postgresql backend
  22. ARG DB=postgresql
  23. # Build time options to avoid dpkg warnings and help with reproducible builds.
  24. ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 TZ=UTC TERM=xterm-256color
  25. # Don't download rust docs
  26. RUN rustup set profile minimal
  27. # Install PostgreSQL package
  28. RUN apt-get update && apt-get install -y \
  29. --no-install-recommends \
  30. libpq-dev \
  31. && rm -rf /var/lib/apt/lists/*
  32. # Creates a dummy project used to grab dependencies
  33. RUN USER=root cargo new --bin /app
  34. WORKDIR /app
  35. # Copies over *only* your manifests and build files
  36. COPY ./Cargo.* ./
  37. COPY ./rust-toolchain ./rust-toolchain
  38. COPY ./build.rs ./build.rs
  39. # Builds your dependencies and removes the
  40. # dummy project, except the target folder
  41. # This folder contains the compiled dependencies
  42. RUN cargo build --features ${DB} --release
  43. RUN find . -not -path "./target*" -delete
  44. # Copies the complete project
  45. # To avoid copying unneeded files, use .dockerignore
  46. COPY . .
  47. # Make sure that we actually build the project
  48. RUN touch src/main.rs
  49. # Builds again, this time it'll just be
  50. # your actual source files being built
  51. RUN cargo build --features ${DB} --release
  52. ######################## RUNTIME IMAGE ########################
  53. # Create a new stage with a minimal image
  54. # because we already have a binary built
  55. FROM debian:buster-slim
  56. ENV ROCKET_ENV "staging"
  57. ENV ROCKET_PORT=80
  58. ENV ROCKET_WORKERS=10
  59. # Install needed libraries
  60. RUN apt-get update && apt-get install -y \
  61. --no-install-recommends \
  62. openssl \
  63. ca-certificates \
  64. curl \
  65. libpq5 \
  66. && rm -rf /var/lib/apt/lists/*
  67. RUN mkdir /data
  68. VOLUME /data
  69. EXPOSE 80
  70. EXPOSE 3012
  71. # Copies the files from the context (Rocket.toml file and web-vault)
  72. # and the binary from the "build" stage to the current stage
  73. COPY Rocket.toml .
  74. COPY --from=vault /web-vault ./web-vault
  75. COPY --from=build app/target/release/bitwarden_rs .
  76. COPY docker/healthcheck.sh /healthcheck.sh
  77. HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
  78. # Configures the startup!
  79. WORKDIR /
  80. CMD ["/bitwarden_rs"]