Dockerfile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Using multistage build:
  2. # https://docs.docker.com/develop/develop-images/multistage-build/
  3. # https://whitfin.io/speeding-up-rust-docker-builds/
  4. ####################### VAULT BUILD IMAGE #######################
  5. FROM rust:1.40 as vault
  6. ENV VAULT_VERSION "v2.12.0b"
  7. ENV URL "https://github.com/dani-garcia/bw_web_builds/releases/download/$VAULT_VERSION/bw_web_$VAULT_VERSION.tar.gz"
  8. # Build time options to avoid dpkg warnings and help with reproducible builds.
  9. ARG DEBIAN_FRONTEND=noninteractive
  10. ARG LANG=C.UTF-8
  11. ARG TZ=UTC
  12. ARG TERM=xterm-256color
  13. RUN apt-get update \
  14. && apt-get install -y \
  15. --no-install-recommends \
  16. curl \
  17. tar
  18. RUN mkdir /web-vault
  19. WORKDIR /web-vault
  20. SHELL ["/bin/bash", "-o", "nounset", "-o", "pipefail", "-o", "errexit", "-c"]
  21. RUN curl -L $URL | tar xz
  22. RUN ls
  23. ########################## BUILD IMAGE ##########################
  24. # We need to use the Rust build image, because
  25. # we need the Rust compiler and Cargo tooling
  26. FROM rust:1.40 as build
  27. # set postgresql backend
  28. ARG DB=postgresql
  29. # Build time options to avoid dpkg warnings and help with reproducible builds.
  30. ARG DEBIAN_FRONTEND=noninteractive
  31. ARG LANG=C.UTF-8
  32. ARG TZ=UTC
  33. ARG TERM=xterm-256color
  34. # Don't download rust docs
  35. RUN rustup set profile minimal
  36. # Install PostgreSQL package
  37. RUN apt-get update && apt-get install -y \
  38. --no-install-recommends \
  39. libpq-dev \
  40. && rm -rf /var/lib/apt/lists/*
  41. # Creates a dummy project used to grab dependencies
  42. RUN USER=root cargo new --bin /app
  43. WORKDIR /app
  44. # Copies over *only* your manifests and build files
  45. COPY ./Cargo.* ./
  46. COPY ./rust-toolchain ./rust-toolchain
  47. COPY ./build.rs ./build.rs
  48. # Builds your dependencies and removes the
  49. # dummy project, except the target folder
  50. # This folder contains the compiled dependencies
  51. RUN cargo build --features ${DB} --release
  52. RUN find . -not -path "./target*" -delete
  53. # Copies the complete project
  54. # To avoid copying unneeded files, use .dockerignore
  55. COPY . .
  56. # Make sure that we actually build the project
  57. RUN touch src/main.rs
  58. # Builds again, this time it'll just be
  59. # your actual source files being built
  60. RUN cargo build --features ${DB} --release
  61. ######################## RUNTIME IMAGE ########################
  62. # Create a new stage with a minimal image
  63. # because we already have a binary built
  64. FROM debian:buster-slim
  65. ENV ROCKET_ENV "staging"
  66. ENV ROCKET_PORT=80
  67. ENV ROCKET_WORKERS=10
  68. # Install needed libraries
  69. RUN apt-get update && apt-get install -y \
  70. --no-install-recommends \
  71. openssl \
  72. ca-certificates \
  73. curl \
  74. libpq5 \
  75. && rm -rf /var/lib/apt/lists/*
  76. RUN mkdir /data
  77. VOLUME /data
  78. EXPOSE 80
  79. EXPOSE 3012
  80. # Copies the files from the context (Rocket.toml file and web-vault)
  81. # and the binary from the "build" stage to the current stage
  82. COPY Rocket.toml .
  83. COPY --from=vault /web-vault ./web-vault
  84. COPY --from=build app/target/release/bitwarden_rs .
  85. COPY docker/healthcheck.sh ./healthcheck.sh
  86. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  87. # Configures the startup!
  88. WORKDIR /
  89. CMD ["/bitwarden_rs"]