Dockerfile.alpine 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. # This hash is extracted from the docker web-vault builds and it's prefered over a simple tag because it's immutable.
  8. # It can be viewed in multiple ways:
  9. # - From the https://hub.docker.com/repository/docker/bitwardenrs/web-vault/tags page, click the tag name and the digest should be there.
  10. # - From the console, with the following commands:
  11. # docker pull bitwardenrs/web-vault:v2.12.0e
  12. # docker image inspect --format "{{.RepoDigests}}" bitwardenrs/web-vault:v2.12.0e
  13. #
  14. # - To do the opposite, and get the tag from the hash, you can do:
  15. # docker image inspect --format "{{.RepoTags}}" bitwardenrs/web-vault@sha256:61db9fab4dfc8259177fbcd25d239b88202c11f039a94c341ed0f828a9a23c9c
  16. FROM bitwardenrs/web-vault@sha256:61db9fab4dfc8259177fbcd25d239b88202c11f039a94c341ed0f828a9a23c9c as vault
  17. ########################## BUILD IMAGE ##########################
  18. # Musl build image for statically compiled binary
  19. FROM clux/muslrust:nightly-2019-12-19 as build
  20. # set postgresql backend
  21. ARG DB=postgresql
  22. # Build time options to avoid dpkg warnings and help with reproducible builds.
  23. ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 TZ=UTC TERM=xterm-256color
  24. # Don't download rust docs
  25. RUN rustup set profile minimal
  26. ENV USER "root"
  27. # Install PostgreSQL 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. RUN rustup target add x86_64-unknown-linux-musl
  40. # Builds your dependencies and removes the
  41. # dummy project, except the target folder
  42. # This folder contains the compiled dependencies
  43. RUN cargo build --features ${DB} --release
  44. RUN find . -not -path "./target*" -delete
  45. # Copies the complete project
  46. # To avoid copying unneeded files, use .dockerignore
  47. COPY . .
  48. # Make sure that we actually build the project
  49. RUN touch src/main.rs
  50. # Builds again, this time it'll just be
  51. # your actual source files being built
  52. RUN cargo build --features ${DB} --release
  53. ######################## RUNTIME IMAGE ########################
  54. # Create a new stage with a minimal image
  55. # because we already have a binary built
  56. FROM alpine:3.11
  57. ENV ROCKET_ENV "staging"
  58. ENV ROCKET_PORT=80
  59. ENV ROCKET_WORKERS=10
  60. ENV SSL_CERT_DIR=/etc/ssl/certs
  61. # Install needed libraries
  62. RUN apk add --no-cache \
  63. openssl \
  64. curl \
  65. postgresql-libs \
  66. ca-certificates
  67. RUN mkdir /data
  68. VOLUME /data
  69. EXPOSE 80
  70. EXPOSE 3012
  71. # Copies the files from the context (Rocket.toml file and web-vault)
  72. # and the binary from the "build" stage to the current stage
  73. COPY Rocket.toml .
  74. COPY --from=vault /web-vault ./web-vault
  75. COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs .
  76. COPY docker/healthcheck.sh /healthcheck.sh
  77. HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
  78. # Configures the startup!
  79. WORKDIR /
  80. CMD ["/bitwarden_rs"]