Dockerfile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # This Dockerfile is composed of two steps: the first one builds the release
  2. # binary, and then the binary is copied inside another, empty image.
  3. #################
  4. # Build image #
  5. #################
  6. FROM ubuntu:bionic AS build
  7. RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
  8. ca-certificates \
  9. curl \
  10. build-essential \
  11. pkg-config \
  12. libssl-dev
  13. RUN curl https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init >/tmp/rustup-init && \
  14. chmod +x /tmp/rustup-init && \
  15. /tmp/rustup-init -y --no-modify-path --default-toolchain stable
  16. ENV PATH=/root/.cargo/bin:$PATH
  17. # Build the dependencies in a separate step to avoid rebuilding all of them
  18. # every time the source code changes. This takes advantage of Docker's layer
  19. # caching, and it works by copying the Cargo.{toml,lock} with dummy source code
  20. # and doing a full build with it.
  21. WORKDIR /tmp/source
  22. COPY Cargo.lock Cargo.toml /tmp/source/
  23. COPY parser/Cargo.toml /tmp/source/parser/Cargo.toml
  24. RUN mkdir -p /tmp/source/src /tmp/source/parser/src && \
  25. echo "fn main() {}" > /tmp/source/src/main.rs && \
  26. touch /tmp/source/parser/src/lib.rs
  27. RUN cargo fetch
  28. RUN cargo build --release
  29. # Dependencies are now cached, copy the actual source code and do another full
  30. # build. The touch on all the .rs files is needed, otherwise cargo assumes the
  31. # source code didn't change thanks to mtime weirdness.
  32. RUN rm -rf /tmp/source/src /tmp/source/parser/src
  33. COPY src /tmp/source/src
  34. COPY parser/src /tmp/source/parser/src
  35. RUN find -name "*.rs" -exec touch {} \; && cargo build --release
  36. ##################
  37. # Output image #
  38. ##################
  39. FROM ubuntu:bionic AS binary
  40. RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
  41. ca-certificates
  42. COPY --from=build /tmp/source/target/release/triagebot /usr/local/bin/
  43. ENV PORT=80
  44. CMD triagebot