Dockerfile 2.7 KB

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