Dockerfile 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.12.0e
  12. # docker image inspect --format "{{.RepoDigests}}" bitwardenrs/web-vault:v2.12.0e
  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:ce56b3f5e538351411785ac45e9b4b913259c3508b1323d62e8fa0f30717dd1c
  16. FROM bitwardenrs/web-vault@sha256:ce56b3f5e538351411785ac45e9b4b913259c3508b1323d62e8fa0f30717dd1c 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 sqlite as default for DB ARG for backward compatibility
  22. ARG DB=sqlite
  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. # Creates a dummy project used to grab dependencies
  28. RUN USER=root cargo new --bin /app
  29. WORKDIR /app
  30. # Copies over *only* your manifests and build files
  31. COPY ./Cargo.* ./
  32. COPY ./rust-toolchain ./rust-toolchain
  33. COPY ./build.rs ./build.rs
  34. # Builds your dependencies and removes the
  35. # dummy project, except the target folder
  36. # This folder contains the compiled dependencies
  37. RUN cargo build --features ${DB} --release
  38. RUN find . -not -path "./target*" -delete
  39. # Copies the complete project
  40. # To avoid copying unneeded files, use .dockerignore
  41. COPY . .
  42. # Make sure that we actually build the project
  43. RUN touch src/main.rs
  44. # Builds again, this time it'll just be
  45. # your actual source files being built
  46. RUN cargo build --features ${DB} --release
  47. ######################## RUNTIME IMAGE ########################
  48. # Create a new stage with a minimal image
  49. # because we already have a binary built
  50. FROM debian:buster-slim
  51. ENV ROCKET_ENV "staging"
  52. ENV ROCKET_PORT=80
  53. ENV ROCKET_WORKERS=10
  54. # Install needed libraries
  55. RUN apt-get update && apt-get install -y \
  56. --no-install-recommends \
  57. openssl \
  58. ca-certificates \
  59. curl \
  60. sqlite3 \
  61. && rm -rf /var/lib/apt/lists/*
  62. RUN mkdir /data
  63. VOLUME /data
  64. EXPOSE 80
  65. EXPOSE 3012
  66. # Copies the files from the context (Rocket.toml file and web-vault)
  67. # and the binary from the "build" stage to the current stage
  68. COPY Rocket.toml .
  69. COPY --from=vault /web-vault ./web-vault
  70. COPY --from=build app/target/release/bitwarden_rs .
  71. COPY docker/healthcheck.sh ./healthcheck.sh
  72. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  73. # Configures the startup!
  74. WORKDIR /
  75. CMD ["/bitwarden_rs"]