Dockerfile 1.6 KB

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