Dockerfile 2.7 KB

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