Dockerfile.alpine 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # syntax=docker/dockerfile:1
  2. # This file was generated using a Jinja2 template.
  3. # Please make your changes in `Dockerfile.j2` and then `make` the individual Dockerfiles.
  4. # Using multistage build:
  5. # https://docs.docker.com/develop/develop-images/multistage-build/
  6. # https://whitfin.io/speeding-up-rust-docker-builds/
  7. ####################### VAULT BUILD IMAGE #######################
  8. # The web-vault digest specifies a particular web-vault build on Docker Hub.
  9. # Using the digest instead of the tag name provides better security,
  10. # as the digest of an image is immutable, whereas a tag name can later
  11. # be changed to point to a malicious image.
  12. #
  13. # To verify the current digest for a given tag name:
  14. # - From https://hub.docker.com/r/vaultwarden/web-vault/tags,
  15. # click the tag name to view the digest of the image it currently points to.
  16. # - From the command line:
  17. # $ docker pull vaultwarden/web-vault:v2.26.1
  18. # $ docker image inspect --format "{{.RepoDigests}}" vaultwarden/web-vault:v2.26.1
  19. # [vaultwarden/web-vault@sha256:4412f0790fc1b8c7c86fc07f7761cd37c554802738629e80c7aa35d8bf754f9f]
  20. #
  21. # - Conversely, to get the tag name from the digest:
  22. # $ docker image inspect --format "{{.RepoTags}}" vaultwarden/web-vault@sha256:4412f0790fc1b8c7c86fc07f7761cd37c554802738629e80c7aa35d8bf754f9f
  23. # [vaultwarden/web-vault:v2.26.1]
  24. #
  25. FROM vaultwarden/web-vault@sha256:4412f0790fc1b8c7c86fc07f7761cd37c554802738629e80c7aa35d8bf754f9f as vault
  26. ########################## BUILD IMAGE ##########################
  27. FROM blackdex/rust-musl:arm-musleabi-stable as build
  28. # Build time options to avoid dpkg warnings and help with reproducible builds.
  29. ENV DEBIAN_FRONTEND=noninteractive \
  30. LANG=C.UTF-8 \
  31. TZ=UTC \
  32. TERM=xterm-256color \
  33. CARGO_HOME="/root/.cargo" \
  34. USER="root"
  35. # Create CARGO_HOME folder and don't download rust docs
  36. RUN mkdir -pv "${CARGO_HOME}" \
  37. && rustup set profile minimal
  38. ENV RUSTFLAGS='-C link-arg=-s'
  39. # Creates a dummy project used to grab dependencies
  40. RUN USER=root cargo new --bin /app
  41. WORKDIR /app
  42. # Copies over *only* your manifests and build files
  43. COPY ./Cargo.* ./
  44. COPY ./rust-toolchain ./rust-toolchain
  45. COPY ./build.rs ./build.rs
  46. RUN rustup target add arm-unknown-linux-musleabi
  47. # Configure the DB ARG as late as possible to not invalidate the cached layers above
  48. ARG DB=sqlite,mysql,postgresql
  49. # Builds your dependencies and removes the
  50. # dummy project, except the target folder
  51. # This folder contains the compiled dependencies
  52. RUN cargo build --features ${DB} --release --target=arm-unknown-linux-musleabi \
  53. && find . -not -path "./target*" -delete
  54. # Copies the complete project
  55. # To avoid copying unneeded files, use .dockerignore
  56. COPY . .
  57. # Make sure that we actually build the project
  58. RUN touch src/main.rs
  59. # Builds again, this time it'll just be
  60. # your actual source files being built
  61. # hadolint ignore=DL3059
  62. RUN cargo build --features ${DB} --release --target=arm-unknown-linux-musleabi
  63. ######################## RUNTIME IMAGE ########################
  64. # Create a new stage with a minimal image
  65. # because we already have a binary built
  66. FROM balenalib/rpi-alpine:3.15
  67. ENV ROCKET_PROFILE="release" \
  68. ROCKET_ADDRESS=0.0.0.0 \
  69. ROCKET_PORT=80 \
  70. SSL_CERT_DIR=/etc/ssl/certs
  71. # hadolint ignore=DL3059
  72. RUN [ "cross-build-start" ]
  73. # Create data folder and Install needed libraries
  74. RUN mkdir /data \
  75. && apk add --no-cache \
  76. openssl \
  77. tzdata \
  78. curl \
  79. dumb-init \
  80. ca-certificates
  81. # hadolint ignore=DL3059
  82. RUN [ "cross-build-end" ]
  83. VOLUME /data
  84. EXPOSE 80
  85. EXPOSE 3012
  86. # Copies the files from the context (Rocket.toml file and web-vault)
  87. # and the binary from the "build" stage to the current stage
  88. WORKDIR /
  89. COPY --from=vault /web-vault ./web-vault
  90. COPY --from=build /app/target/arm-unknown-linux-musleabi/release/vaultwarden .
  91. COPY docker/healthcheck.sh /healthcheck.sh
  92. COPY docker/start.sh /start.sh
  93. HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"]
  94. # Configures the startup!
  95. # We should be able to remove the dumb-init now with Rocket 0.5
  96. # But the balenalib images have some issues with there entry.sh
  97. # See: https://github.com/balena-io-library/base-images/issues/735
  98. # Lets keep using dumb-init for now, since that is working fine.
  99. ENTRYPOINT ["/usr/bin/dumb-init", "--"]
  100. CMD ["/start.sh"]