Dockerfile.alpine 2.1 KB

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