Dockerfile 3.0 KB

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