Dockerfile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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:22.04 as build
  7. # For CI/CD purposes, we can pass a pre-run command to the build image
  8. ARG PRE_RUN_CMD=""
  9. ARG CRATES_IO_INDEX="sparse+https://rsproxy.cn/index/"
  10. ENV RUSTUP_DIST_SERVER="https://rsproxy.cn"
  11. ENV RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
  12. # 用于在CICD系统中执行自定义命令
  13. RUN $PRE_RUN_CMD
  14. RUN apt-get update -y && \
  15. DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
  16. g++ \
  17. curl \
  18. ca-certificates \
  19. libc6-dev \
  20. make \
  21. libssl-dev \
  22. pkg-config \
  23. git \
  24. cmake \
  25. zlib1g-dev
  26. RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
  27. --default-toolchain stable --profile minimal -y
  28. COPY . .
  29. RUN cp ./docker/cargo.config $HOME/.cargo/config
  30. RUN bash -c 'source $HOME/.cargo/env && cargo test --release --all'
  31. RUN bash -c 'source $HOME/.cargo/env && cargo build --release'
  32. ##################
  33. # Output image #
  34. ##################
  35. FROM ubuntu:22.04 AS binary
  36. RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
  37. ca-certificates
  38. RUN mkdir -p /opt/triagebot
  39. COPY --from=build /target/release/triagebot /usr/local/bin/
  40. COPY templates /opt/triagebot/templates
  41. WORKDIR /opt/triagebot
  42. ENV PORT=80
  43. CMD triagebot