Dockerfile.alpine 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.13.2b
  12. # docker image inspect --format "{{.RepoDigests}}" bitwardenrs/web-vault:v2.13.2b
  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:f32c555a2bc3ee6bc0718319b1e8057c10ef889cf7231f0ff217af98486da554
  16. FROM bitwardenrs/web-vault@sha256:f32c555a2bc3ee6bc0718319b1e8057c10ef889cf7231f0ff217af98486da554 as vault
  17. ########################## BUILD IMAGE ##########################
  18. # Musl build image for statically compiled binary
  19. FROM clux/muslrust:nightly-2020-03-09 as build
  20. # set mysql backend
  21. ARG DB=mysql
  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. ENV RUSTFLAGS='-C link-arg=-s'
  28. # Install MySQL package
  29. RUN apt-get update && apt-get install -y \
  30. --no-install-recommends \
  31. libmysqlclient-dev \
  32. && rm -rf /var/lib/apt/lists/*
  33. # Creates a dummy project used to grab dependencies
  34. RUN USER=root cargo new --bin /app
  35. WORKDIR /app
  36. # Copies over *only* your manifests and build files
  37. COPY ./Cargo.* ./
  38. COPY ./rust-toolchain ./rust-toolchain
  39. COPY ./build.rs ./build.rs
  40. RUN rustup target add x86_64-unknown-linux-musl
  41. # Builds your dependencies and removes the
  42. # dummy project, except the target folder
  43. # This folder contains the compiled dependencies
  44. RUN cargo build --features ${DB} --release
  45. RUN find . -not -path "./target*" -delete
  46. # Copies the complete project
  47. # To avoid copying unneeded files, use .dockerignore
  48. COPY . .
  49. # Make sure that we actually build the project
  50. RUN touch src/main.rs
  51. # Builds again, this time it'll just be
  52. # your actual source files being built
  53. RUN cargo build --features ${DB} --release
  54. ######################## RUNTIME IMAGE ########################
  55. # Create a new stage with a minimal image
  56. # because we already have a binary built
  57. FROM alpine:3.11
  58. ENV ROCKET_ENV "staging"
  59. ENV ROCKET_PORT=80
  60. ENV ROCKET_WORKERS=10
  61. ENV SSL_CERT_DIR=/etc/ssl/certs
  62. # Install needed libraries
  63. RUN apk add --no-cache \
  64. openssl \
  65. curl \
  66. mariadb-connector-c \
  67. ca-certificates
  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/x86_64-unknown-linux-musl/release/bitwarden_rs .
  77. COPY docker/healthcheck.sh /healthcheck.sh
  78. HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
  79. # Configures the startup!
  80. WORKDIR /
  81. CMD ["/bitwarden_rs"]