Dockerfile 3.1 KB

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