Dockerfile.alpine 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 alpine:3.11 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. RUN apk add --no-cache --upgrade curl tar
  11. RUN mkdir /web-vault
  12. WORKDIR /web-vault
  13. SHELL ["/bin/ash", "-o", "nounset", "-o", "pipefail", "-o", "errexit", "-c"]
  14. RUN curl -L $URL | tar xz
  15. RUN ls
  16. ########################## BUILD IMAGE ##########################
  17. # Musl build image for statically compiled binary
  18. FROM clux/muslrust:nightly-2019-12-19 as build
  19. # set sqlite as default for DB ARG for backward compatibility
  20. ARG DB=sqlite
  21. # Build time options to avoid dpkg warnings and help with reproducible builds.
  22. ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 TZ=UTC TERM=xterm-256color
  23. # Don't download rust docs
  24. RUN rustup set profile minimal
  25. ENV USER "root"
  26. # Creates a dummy project used to grab dependencies
  27. RUN USER=root cargo new --bin /app
  28. WORKDIR /app
  29. # Copies over *only* your manifests and build files
  30. COPY ./Cargo.* ./
  31. COPY ./rust-toolchain ./rust-toolchain
  32. COPY ./build.rs ./build.rs
  33. RUN rustup target add x86_64-unknown-linux-musl
  34. # Builds your dependencies and removes the
  35. # dummy project, except the target folder
  36. # This folder contains the compiled dependencies
  37. RUN cargo build --features ${DB} --release
  38. RUN find . -not -path "./target*" -delete
  39. # Copies the complete project
  40. # To avoid copying unneeded files, use .dockerignore
  41. COPY . .
  42. # Make sure that we actually build the project
  43. RUN touch src/main.rs
  44. # Builds again, this time it'll just be
  45. # your actual source files being built
  46. RUN cargo build --features ${DB} --release
  47. ######################## RUNTIME IMAGE ########################
  48. # Create a new stage with a minimal image
  49. # because we already have a binary built
  50. FROM alpine:3.11
  51. ENV ROCKET_ENV "staging"
  52. ENV ROCKET_PORT=80
  53. ENV ROCKET_WORKERS=10
  54. ENV SSL_CERT_DIR=/etc/ssl/certs
  55. # Install needed libraries
  56. RUN apk add --no-cache \
  57. openssl \
  58. curl \
  59. sqlite \
  60. ca-certificates
  61. RUN mkdir /data
  62. VOLUME /data
  63. EXPOSE 80
  64. EXPOSE 3012
  65. # Copies the files from the context (Rocket.toml file and web-vault)
  66. # and the binary from the "build" stage to the current stage
  67. COPY Rocket.toml .
  68. COPY --from=vault /web-vault ./web-vault
  69. COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs .
  70. COPY docker/healthcheck.sh ./healthcheck.sh
  71. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  72. # Configures the startup!
  73. WORKDIR /
  74. CMD ["/bitwarden_rs"]