Dockerfile.alpine 2.9 KB

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