Dockerfile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 sqlite as default for DB ARG for backward compatibility
  22. ARG DB=sqlite
  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 armhf 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 armhf \
  31. && apt-get update \
  32. && apt-get install -y \
  33. --no-install-recommends \
  34. libssl-dev:armhf \
  35. libc6-dev:armhf
  36. RUN apt-get update \
  37. && apt-get install -y \
  38. --no-install-recommends \
  39. gcc-arm-linux-gnueabihf \
  40. && mkdir -p ~/.cargo \
  41. && echo '[target.armv7-unknown-linux-gnueabihf]' >> ~/.cargo/config \
  42. && echo 'linker = "arm-linux-gnueabihf-gcc"' >> ~/.cargo/config
  43. ENV CARGO_HOME "/root/.cargo"
  44. ENV USER "root"
  45. # Creates a dummy project used to grab dependencies
  46. RUN USER=root cargo new --bin /app
  47. WORKDIR /app
  48. # Copies over *only* your manifests and build files
  49. COPY ./Cargo.* ./
  50. COPY ./rust-toolchain ./rust-toolchain
  51. COPY ./build.rs ./build.rs
  52. ENV CC_armv7_unknown_linux_gnueabihf="/usr/bin/arm-linux-gnueabihf-gcc"
  53. ENV CROSS_COMPILE="1"
  54. ENV OPENSSL_INCLUDE_DIR="/usr/include/arm-linux-gnueabihf"
  55. ENV OPENSSL_LIB_DIR="/usr/lib/arm-linux-gnueabihf"
  56. RUN rustup target add armv7-unknown-linux-gnueabihf
  57. # Builds your dependencies and removes the
  58. # dummy project, except the target folder
  59. # This folder contains the compiled dependencies
  60. RUN cargo build --features ${DB} --release
  61. RUN find . -not -path "./target*" -delete
  62. # Copies the complete project
  63. # To avoid copying unneeded files, use .dockerignore
  64. COPY . .
  65. # Make sure that we actually build the project
  66. RUN touch src/main.rs
  67. # Builds again, this time it'll just be
  68. # your actual source files being built
  69. RUN cargo build --features ${DB} --release --target=armv7-unknown-linux-gnueabihf
  70. ######################## RUNTIME IMAGE ########################
  71. # Create a new stage with a minimal image
  72. # because we already have a binary built
  73. FROM balenalib/armv7hf-debian:buster
  74. ENV ROCKET_ENV "staging"
  75. ENV ROCKET_PORT=80
  76. ENV ROCKET_WORKERS=10
  77. RUN [ "cross-build-start" ]
  78. # Install needed libraries
  79. RUN apt-get update && apt-get install -y \
  80. --no-install-recommends \
  81. openssl \
  82. ca-certificates \
  83. curl \
  84. sqlite3 \
  85. && rm -rf /var/lib/apt/lists/*
  86. RUN mkdir /data
  87. RUN [ "cross-build-end" ]
  88. VOLUME /data
  89. EXPOSE 80
  90. EXPOSE 3012
  91. # Copies the files from the context (Rocket.toml file and web-vault)
  92. # and the binary from the "build" stage to the current stage
  93. COPY Rocket.toml .
  94. COPY --from=vault /web-vault ./web-vault
  95. COPY --from=build /app/target/armv7-unknown-linux-gnueabihf/release/bitwarden_rs .
  96. COPY docker/healthcheck.sh ./healthcheck.sh
  97. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  98. # Configures the startup!
  99. WORKDIR /
  100. CMD ["/bitwarden_rs"]