Dockerfile.alpine 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.10 as vault
  6. ENV VAULT_VERSION "v2.12.0"
  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-10-19 as build
  19. # set mysql backend
  20. ARG DB=postgresql
  21. ENV USER "root"
  22. # Install needed libraries
  23. RUN apt-get update && apt-get install -y \
  24. --no-install-recommends \
  25. libpq-dev \
  26. && rm -rf /var/lib/apt/lists/*
  27. WORKDIR /app
  28. # Copies the complete project
  29. # To avoid copying unneeded files, use .dockerignore
  30. COPY . .
  31. RUN rustup self update
  32. RUN rustup set profile minimal
  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.10
  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. CMD ["./bitwarden_rs"]