Dockerfile.alpine 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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:feb3f46d15738191b9043be4cdb1be2c0078ed411e7b7be73a2f4fcbca01e13c
  16. FROM bitwardenrs/web-vault@sha256:feb3f46d15738191b9043be4cdb1be2c0078ed411e7b7be73a2f4fcbca01e13c as vault
  17. ########################## BUILD IMAGE ##########################
  18. # Musl build image for statically compiled binary
  19. FROM clux/muslrust:nightly-2019-12-19 as build
  20. # set sqlite as default for DB ARG for backward compatibility
  21. ARG DB=sqlite
  22. # Build time options to avoid dpkg warnings and help with reproducible builds.
  23. ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 TZ=UTC TERM=xterm-256color
  24. # Don't download rust docs
  25. RUN rustup set profile minimal
  26. ENV USER "root"
  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. RUN rustup target add x86_64-unknown-linux-musl
  35. # Builds your dependencies and removes the
  36. # dummy project, except the target folder
  37. # This folder contains the compiled dependencies
  38. RUN cargo build --features ${DB} --release
  39. RUN find . -not -path "./target*" -delete
  40. # Copies the complete project
  41. # To avoid copying unneeded files, use .dockerignore
  42. COPY . .
  43. # Make sure that we actually build the project
  44. RUN touch src/main.rs
  45. # Builds again, this time it'll just be
  46. # your actual source files being built
  47. RUN cargo build --features ${DB} --release
  48. ######################## RUNTIME IMAGE ########################
  49. # Create a new stage with a minimal image
  50. # because we already have a binary built
  51. FROM alpine:3.11
  52. ENV ROCKET_ENV "staging"
  53. ENV ROCKET_PORT=80
  54. ENV ROCKET_WORKERS=10
  55. ENV SSL_CERT_DIR=/etc/ssl/certs
  56. # Install needed libraries
  57. RUN apk add --no-cache \
  58. openssl \
  59. curl \
  60. sqlite \
  61. ca-certificates
  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/x86_64-unknown-linux-musl/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"]