Dockerfile.alpine 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.11 as vault
  6. ENV VAULT_VERSION "v2.12.0b"
  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", "-o", "nounset", "-o", "pipefail", "-o", "errexit", "-c"]
  14. RUN curl -L $URL | tar xz
  15. RUN ls
  16. ########################## BUILD IMAGE ##########################
  17. # Musl build image for statically compiled binary
  18. FROM clux/muslrust:nightly-2019-12-19 as build
  19. # set postgresql backend
  20. ARG DB=postgresql
  21. # Don't download rust docs
  22. RUN rustup set profile minimal
  23. ENV USER "root"
  24. # Install PostgreSQL package
  25. RUN apt-get update && apt-get install -y \
  26. --no-install-recommends \
  27. libpq-dev \
  28. && rm -rf /var/lib/apt/lists/*
  29. # Creates a dummy project used to grab dependencies
  30. RUN USER=root cargo new --bin /app
  31. WORKDIR /app
  32. # Copies over *only* your manifests and build files
  33. COPY ./Cargo.* ./
  34. COPY ./rust-toolchain ./rust-toolchain
  35. COPY ./build.rs ./build.rs
  36. RUN rustup target add x86_64-unknown-linux-musl
  37. # Builds your dependencies and removes the
  38. # dummy project, except the target folder
  39. # This folder contains the compiled dependencies
  40. RUN cargo build --features ${DB} --release
  41. RUN find . -not -path "./target*" -delete
  42. # Copies the complete project
  43. # To avoid copying unneeded files, use .dockerignore
  44. COPY . .
  45. # Make sure that we actually build the project
  46. RUN touch src/main.rs
  47. # Builds again, this time it'll just be
  48. # your actual source files being built
  49. RUN cargo build --features ${DB} --release
  50. ######################## RUNTIME IMAGE ########################
  51. # Create a new stage with a minimal image
  52. # because we already have a binary built
  53. FROM alpine:3.11
  54. ENV ROCKET_ENV "staging"
  55. ENV ROCKET_PORT=80
  56. ENV ROCKET_WORKERS=10
  57. ENV SSL_CERT_DIR=/etc/ssl/certs
  58. # Install needed libraries
  59. RUN apk add --no-cache \
  60. openssl \
  61. curl \
  62. postgresql-libs \
  63. ca-certificates
  64. RUN mkdir /data
  65. VOLUME /data
  66. EXPOSE 80
  67. EXPOSE 3012
  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/x86_64-unknown-linux-musl/release/bitwarden_rs .
  73. COPY docker/healthcheck.sh ./healthcheck.sh
  74. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  75. # Configures the startup!
  76. WORKDIR /
  77. CMD ["/bitwarden_rs"]