Dockerfile.alpine 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 as vault
  6. ENV VAULT_VERSION "v2.10.1"
  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 --update-cache --upgrade \
  9. curl \
  10. tar
  11. RUN mkdir /web-vault
  12. WORKDIR /web-vault
  13. RUN curl -L $URL | tar xz
  14. RUN ls
  15. ########################## BUILD IMAGE ##########################
  16. # Musl build image for statically compiled binary
  17. FROM clux/muslrust:nightly-2018-12-01 as build
  18. # set mysql backend
  19. ARG DB=mysql
  20. ENV USER "root"
  21. # Install needed libraries
  22. RUN apt-get update && apt-get install -y\
  23. libmysqlclient-dev\
  24. --no-install-recommends\
  25. && rm -rf /var/lib/apt/lists/*
  26. WORKDIR /app
  27. # Copies the complete project
  28. # To avoid copying unneeded files, use .dockerignore
  29. COPY . .
  30. RUN rustup target add x86_64-unknown-linux-musl
  31. # Make sure that we actually build the project
  32. RUN touch src/main.rs
  33. # Build
  34. RUN cargo build --features ${DB} --release
  35. ######################## RUNTIME IMAGE ########################
  36. # Create a new stage with a minimal image
  37. # because we already have a binary built
  38. FROM alpine:3.9
  39. ENV ROCKET_ENV "staging"
  40. ENV ROCKET_PORT=80
  41. ENV ROCKET_WORKERS=10
  42. ENV SSL_CERT_DIR=/etc/ssl/certs
  43. # Install needed libraries
  44. RUN apk add \
  45. openssl \
  46. mariadb-connector-c \
  47. ca-certificates \
  48. && rm /var/cache/apk/*
  49. RUN mkdir /data
  50. VOLUME /data
  51. EXPOSE 80
  52. EXPOSE 3012
  53. # Copies the files from the context (Rocket.toml file and web-vault)
  54. # and the binary from the "build" stage to the current stage
  55. COPY Rocket.toml .
  56. COPY --from=vault /web-vault ./web-vault
  57. COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs .
  58. # Configures the startup!
  59. CMD ./bitwarden_rs