Dockerfile 2.5 KB

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