Dockerfile.alpine 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # Build time options to avoid dpkg warnings and help with reproducible builds.
  22. ARG DEBIAN_FRONTEND=noninteractive
  23. ARG LANG=C.UTF-8
  24. ARG TZ=UTC
  25. ARG TERM=xterm-256color
  26. # Don't download rust docs
  27. RUN rustup set profile minimal
  28. ENV USER "root"
  29. # Install PostgreSQL package
  30. RUN apt-get update && apt-get install -y \
  31. --no-install-recommends \
  32. libpq-dev \
  33. && rm -rf /var/lib/apt/lists/*
  34. # Creates a dummy project used to grab dependencies
  35. RUN USER=root cargo new --bin /app
  36. WORKDIR /app
  37. # Copies over *only* your manifests and build files
  38. COPY ./Cargo.* ./
  39. COPY ./rust-toolchain ./rust-toolchain
  40. COPY ./build.rs ./build.rs
  41. RUN rustup target add x86_64-unknown-linux-musl
  42. # Builds your dependencies and removes the
  43. # dummy project, except the target folder
  44. # This folder contains the compiled dependencies
  45. RUN cargo build --features ${DB} --release
  46. RUN find . -not -path "./target*" -delete
  47. # Copies the complete project
  48. # To avoid copying unneeded files, use .dockerignore
  49. COPY . .
  50. # Make sure that we actually build the project
  51. RUN touch src/main.rs
  52. # Builds again, this time it'll just be
  53. # your actual source files being built
  54. RUN cargo build --features ${DB} --release
  55. ######################## RUNTIME IMAGE ########################
  56. # Create a new stage with a minimal image
  57. # because we already have a binary built
  58. FROM alpine:3.11
  59. ENV ROCKET_ENV "staging"
  60. ENV ROCKET_PORT=80
  61. ENV ROCKET_WORKERS=10
  62. ENV SSL_CERT_DIR=/etc/ssl/certs
  63. # Install needed libraries
  64. RUN apk add --no-cache \
  65. openssl \
  66. curl \
  67. postgresql-libs \
  68. ca-certificates
  69. RUN mkdir /data
  70. VOLUME /data
  71. EXPOSE 80
  72. EXPOSE 3012
  73. # Copies the files from the context (Rocket.toml file and web-vault)
  74. # and the binary from the "build" stage to the current stage
  75. COPY Rocket.toml .
  76. COPY --from=vault /web-vault ./web-vault
  77. COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs .
  78. COPY docker/healthcheck.sh ./healthcheck.sh
  79. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  80. # Configures the startup!
  81. WORKDIR /
  82. CMD ["/bitwarden_rs"]