Dockerfile.aarch64 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.8.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 --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. RUN apt-get update \
  20. && apt-get install -y \
  21. gcc-aarch64-linux-gnu \
  22. && mkdir -p ~/.cargo \
  23. && echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config \
  24. && echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config
  25. ENV CARGO_HOME "/root/.cargo"
  26. ENV USER "root"
  27. WORKDIR /app
  28. # Prepare openssl arm64 libs
  29. RUN sed 's/^deb/deb-src/' /etc/apt/sources.list > \
  30. /etc/apt/sources.list.d/deb-src.list \
  31. && dpkg --add-architecture arm64 \
  32. && apt-get update \
  33. && apt-get install -y \
  34. libssl-dev:arm64 \
  35. libc6-dev:arm64
  36. ENV CC_aarch64_unknown_linux_gnu="/usr/bin/aarch64-linux-gnu-gcc"
  37. ENV CROSS_COMPILE="1"
  38. ENV OPENSSL_INCLUDE_DIR="/usr/include/aarch64-linux-gnu"
  39. ENV OPENSSL_LIB_DIR="/usr/lib/aarch64-linux-gnu"
  40. # Copies the complete project
  41. # To avoid copying unneeded files, use .dockerignore
  42. COPY . .
  43. # Build
  44. RUN rustup target add aarch64-unknown-linux-gnu
  45. RUN cargo build --release --target=aarch64-unknown-linux-gnu -v
  46. ######################## RUNTIME IMAGE ########################
  47. # Create a new stage with a minimal image
  48. # because we already have a binary built
  49. FROM balenalib/aarch64-debian:stretch
  50. ENV ROCKET_ENV "staging"
  51. ENV ROCKET_PORT=80
  52. ENV ROCKET_WORKERS=10
  53. RUN [ "cross-build-start" ]
  54. # Install needed libraries
  55. RUN apt-get update && apt-get install -y\
  56. openssl\
  57. ca-certificates\
  58. --no-install-recommends\
  59. && rm -rf /var/lib/apt/lists/*
  60. RUN mkdir /data
  61. RUN [ "cross-build-end" ]
  62. VOLUME /data
  63. EXPOSE 80
  64. # Copies the files from the context (env file and web-vault)
  65. # and the binary from the "build" stage to the current stage
  66. COPY .env .
  67. COPY Rocket.toml .
  68. COPY --from=vault /web-vault ./web-vault
  69. COPY --from=build /app/target/aarch64-unknown-linux-gnu/release/bitwarden_rs .
  70. # Configures the startup!
  71. CMD ./bitwarden_rs