Dockerfile.alpine 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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", "-eo", "pipefail", "-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 needed libraries
  25. RUN apt-get update && apt-get install -y \
  26. --no-install-recommends \
  27. libpq-dev \
  28. && rm -rf /var/lib/apt/lists/*
  29. WORKDIR /app
  30. # Copies the complete project
  31. # To avoid copying unneeded files, use .dockerignore
  32. COPY . .
  33. RUN rustup target add x86_64-unknown-linux-musl
  34. # Make sure that we actually build the project
  35. RUN touch src/main.rs
  36. # Build
  37. RUN cargo build --features ${DB} --release
  38. ######################## RUNTIME IMAGE ########################
  39. # Create a new stage with a minimal image
  40. # because we already have a binary built
  41. FROM alpine:3.11
  42. ENV ROCKET_ENV "staging"
  43. ENV ROCKET_PORT=80
  44. ENV ROCKET_WORKERS=10
  45. ENV SSL_CERT_DIR=/etc/ssl/certs
  46. # Install needed libraries
  47. RUN apk add --no-cache \
  48. openssl \
  49. postgresql-libs \
  50. curl \
  51. sqlite \
  52. ca-certificates
  53. RUN mkdir /data
  54. VOLUME /data
  55. EXPOSE 80
  56. EXPOSE 3012
  57. # Copies the files from the context (Rocket.toml file and web-vault)
  58. # and the binary from the "build" stage to the current stage
  59. COPY Rocket.toml .
  60. COPY --from=vault /web-vault ./web-vault
  61. COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs .
  62. COPY docker/healthcheck.sh ./healthcheck.sh
  63. HEALTHCHECK --interval=30s --timeout=3s CMD sh healthcheck.sh || exit 1
  64. # Configures the startup!
  65. WORKDIR /
  66. CMD ["/bitwarden_rs"]