Dockerfile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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:feb3f46d15738191b9043be4cdb1be2c0078ed411e7b7be73a2f4fcbca01e13c
  16. FROM bitwardenrs/web-vault@sha256:feb3f46d15738191b9043be4cdb1be2c0078ed411e7b7be73a2f4fcbca01e13c as vault
  17. ########################## BUILD IMAGE ##########################
  18. # We need to use the Rust build image, because
  19. # we need the Rust compiler and Cargo tooling
  20. FROM rust:1.40 as build
  21. # set mysql backend
  22. ARG DB=mysql
  23. # Build time options to avoid dpkg warnings and help with reproducible builds.
  24. ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 TZ=UTC TERM=xterm-256color
  25. # Don't download rust docs
  26. RUN rustup set profile minimal
  27. # Install required build libs for armel architecture.
  28. RUN sed 's/^deb/deb-src/' /etc/apt/sources.list > \
  29. /etc/apt/sources.list.d/deb-src.list \
  30. && dpkg --add-architecture armel \
  31. && apt-get update \
  32. && apt-get install -y \
  33. --no-install-recommends \
  34. libssl-dev:armel \
  35. libc6-dev:armel
  36. RUN apt-get update \
  37. && apt-get install -y \
  38. --no-install-recommends \
  39. gcc-arm-linux-gnueabi \
  40. && mkdir -p ~/.cargo \
  41. && echo '[target.arm-unknown-linux-gnueabi]' >> ~/.cargo/config \
  42. && echo 'linker = "arm-linux-gnueabi-gcc"' >> ~/.cargo/config
  43. ENV CARGO_HOME "/root/.cargo"
  44. ENV USER "root"
  45. # Install MySQL package
  46. RUN apt-get update && apt-get install -y \
  47. --no-install-recommends \
  48. libmariadb-dev:armel \
  49. && rm -rf /var/lib/apt/lists/*
  50. # Creates a dummy project used to grab dependencies
  51. RUN USER=root cargo new --bin /app
  52. WORKDIR /app
  53. # Copies over *only* your manifests and build files
  54. COPY ./Cargo.* ./
  55. COPY ./rust-toolchain ./rust-toolchain
  56. COPY ./build.rs ./build.rs
  57. ENV CC_arm_unknown_linux_gnueabi="/usr/bin/arm-linux-gnueabi-gcc"
  58. ENV CROSS_COMPILE="1"
  59. ENV OPENSSL_INCLUDE_DIR="/usr/include/arm-linux-gnueabi"
  60. ENV OPENSSL_LIB_DIR="/usr/lib/arm-linux-gnueabi"
  61. RUN rustup target add arm-unknown-linux-gnueabi
  62. # Builds your dependencies and removes the
  63. # dummy project, except the target folder
  64. # This folder contains the compiled dependencies
  65. RUN cargo build --features ${DB} --release
  66. RUN find . -not -path "./target*" -delete
  67. # Copies the complete project
  68. # To avoid copying unneeded files, use .dockerignore
  69. COPY . .
  70. # Make sure that we actually build the project
  71. RUN touch src/main.rs
  72. # Builds again, this time it'll just be
  73. # your actual source files being built
  74. RUN cargo build --features ${DB} --release --target=arm-unknown-linux-gnueabi
  75. ######################## RUNTIME IMAGE ########################
  76. # Create a new stage with a minimal image
  77. # because we already have a binary built
  78. FROM balenalib/rpi-debian:buster
  79. ENV ROCKET_ENV "staging"
  80. ENV ROCKET_PORT=80
  81. ENV ROCKET_WORKERS=10
  82. RUN [ "cross-build-start" ]
  83. # Install needed libraries
  84. RUN apt-get update && apt-get install -y \
  85. --no-install-recommends \
  86. openssl \
  87. ca-certificates \
  88. curl \
  89. libmariadbclient-dev \
  90. && rm -rf /var/lib/apt/lists/*
  91. RUN mkdir /data
  92. RUN [ "cross-build-end" ]
  93. VOLUME /data
  94. EXPOSE 80
  95. EXPOSE 3012
  96. # Copies the files from the context (Rocket.toml file and web-vault)
  97. # and the binary from the "build" stage to the current stage
  98. COPY Rocket.toml .
  99. COPY --from=vault /web-vault ./web-vault
  100. COPY --from=build /app/target/arm-unknown-linux-gnueabi/release/bitwarden_rs .
  101. COPY docker/healthcheck.sh ./healthcheck.sh
  102. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  103. # Configures the startup!
  104. WORKDIR /
  105. CMD ["/bitwarden_rs"]