Dockerfile 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 as vault
  6. ENV VAULT_VERSION "v2.10.1"
  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 --update-cache --upgrade \
  9. curl \
  10. tar
  11. RUN mkdir /web-vault
  12. WORKDIR /web-vault
  13. RUN curl -L $URL | tar xz
  14. RUN ls
  15. ########################## BUILD IMAGE ##########################
  16. # We need to use the Rust build image, because
  17. # we need the Rust compiler and Cargo tooling
  18. FROM rust as build
  19. # set mysql backend
  20. ARG DB=mysql
  21. RUN apt-get update \
  22. && apt-get install -y \
  23. gcc-arm-linux-gnueabi \
  24. && mkdir -p ~/.cargo \
  25. && echo '[target.arm-unknown-linux-gnueabi]' >> ~/.cargo/config \
  26. && echo 'linker = "arm-linux-gnueabi-gcc"' >> ~/.cargo/config
  27. ENV CARGO_HOME "/root/.cargo"
  28. ENV USER "root"
  29. WORKDIR /app
  30. # Prepare openssl armel libs
  31. RUN sed 's/^deb/deb-src/' /etc/apt/sources.list > \
  32. /etc/apt/sources.list.d/deb-src.list \
  33. && dpkg --add-architecture armel \
  34. && apt-get update \
  35. && apt-get install -y \
  36. libssl-dev:armel \
  37. libc6-dev:armel \
  38. libmariadb-dev:armel
  39. ENV CC_arm_unknown_linux_gnueabi="/usr/bin/arm-linux-gnueabi-gcc"
  40. ENV CROSS_COMPILE="1"
  41. ENV OPENSSL_INCLUDE_DIR="/usr/include/arm-linux-gnueabi"
  42. ENV OPENSSL_LIB_DIR="/usr/lib/arm-linux-gnueabi"
  43. # Copies the complete project
  44. # To avoid copying unneeded files, use .dockerignore
  45. COPY . .
  46. # Build
  47. RUN rustup target add arm-unknown-linux-gnueabi
  48. RUN cargo build --features ${DB} --release --target=arm-unknown-linux-gnueabi -v
  49. ######################## RUNTIME IMAGE ########################
  50. # Create a new stage with a minimal image
  51. # because we already have a binary built
  52. FROM balenalib/rpi-debian:stretch
  53. ENV ROCKET_ENV "staging"
  54. ENV ROCKET_PORT=80
  55. ENV ROCKET_WORKERS=10
  56. RUN [ "cross-build-start" ]
  57. # Install needed libraries
  58. RUN apt-get update && apt-get install -y\
  59. openssl\
  60. ca-certificates\
  61. libmariadbclient-dev\
  62. --no-install-recommends\
  63. && rm -rf /var/lib/apt/lists/*
  64. RUN mkdir /data
  65. RUN [ "cross-build-end" ]
  66. VOLUME /data
  67. EXPOSE 80
  68. # Copies the files from the context (Rocket.toml file and web-vault)
  69. # and the binary from the "build" stage to the current stage
  70. COPY Rocket.toml .
  71. COPY --from=vault /web-vault ./web-vault
  72. COPY --from=build /app/target/arm-unknown-linux-gnueabi/release/bitwarden_rs .
  73. # Configures the startup!
  74. CMD ./bitwarden_rs