Dockerfile 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Using multistage build:
  2. # https://docs.docker.com/develop/develop-images/multistage-build/
  3. # https://whitfin.io/speeding-up-rust-docker-builds/
  4. ####################### VAULT BUILD IMAGE #######################
  5. FROM alpine:3.10 as vault
  6. ENV VAULT_VERSION "v2.12.0"
  7. ENV URL "https://github.com/dani-garcia/bw_web_builds/releases/download/$VAULT_VERSION/bw_web_$VAULT_VERSION.tar.gz"
  8. RUN apk add --no-cache --upgrade \
  9. curl \
  10. tar
  11. RUN mkdir /web-vault
  12. WORKDIR /web-vault
  13. SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
  14. RUN curl -L $URL | tar xz
  15. RUN ls
  16. ########################## BUILD IMAGE ##########################
  17. # We need to use the Rust build image, because
  18. # we need the Rust compiler and Cargo tooling
  19. FROM rust:1.38 as build
  20. # set sqlite as default for DB ARG for backward comaptibility
  21. ARG DB=sqlite
  22. RUN apt-get update \
  23. && apt-get install -y \
  24. --no-install-recommends \
  25. gcc-arm-linux-gnueabihf \
  26. && mkdir -p ~/.cargo \
  27. && echo '[target.armv7-unknown-linux-gnueabihf]' >> ~/.cargo/config \
  28. && echo 'linker = "arm-linux-gnueabihf-gcc"' >> ~/.cargo/config
  29. ENV CARGO_HOME "/root/.cargo"
  30. ENV USER "root"
  31. WORKDIR /app
  32. # Prepare openssl armhf libs
  33. RUN sed 's/^deb/deb-src/' /etc/apt/sources.list > \
  34. /etc/apt/sources.list.d/deb-src.list \
  35. && dpkg --add-architecture armhf \
  36. && apt-get update \
  37. && apt-get install -y \
  38. --no-install-recommends \
  39. libssl-dev:armhf \
  40. libc6-dev:armhf
  41. ENV CC_armv7_unknown_linux_gnueabihf="/usr/bin/arm-linux-gnueabihf-gcc"
  42. ENV CROSS_COMPILE="1"
  43. ENV OPENSSL_INCLUDE_DIR="/usr/include/arm-linux-gnueabihf"
  44. ENV OPENSSL_LIB_DIR="/usr/lib/arm-linux-gnueabihf"
  45. # Copies the complete project
  46. # To avoid copying unneeded files, use .dockerignore
  47. COPY . .
  48. # Build
  49. RUN rustup target add armv7-unknown-linux-gnueabihf
  50. RUN cargo build --features ${DB} --release --target=armv7-unknown-linux-gnueabihf -v
  51. ######################## RUNTIME IMAGE ########################
  52. # Create a new stage with a minimal image
  53. # because we already have a binary built
  54. FROM balenalib/armv7hf-debian:buster
  55. ENV ROCKET_ENV "staging"
  56. ENV ROCKET_PORT=80
  57. ENV ROCKET_WORKERS=10
  58. RUN [ "cross-build-start" ]
  59. # Install needed libraries
  60. RUN apt-get update && apt-get install -y \
  61. --no-install-recommends \
  62. openssl \
  63. ca-certificates \
  64. curl \
  65. sqlite3 \
  66. && rm -rf /var/lib/apt/lists/*
  67. RUN mkdir /data
  68. RUN [ "cross-build-end" ]
  69. VOLUME /data
  70. EXPOSE 80
  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/armv7-unknown-linux-gnueabihf/release/bitwarden_rs .
  76. COPY docker/healthcheck.sh ./healthcheck.sh
  77. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  78. # Configures the startup!
  79. WORKDIR /
  80. CMD ["/bitwarden_rs"]