Dockerfile 1.5 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 APT_REPO="cn.archive.ubuntu.com"
  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 bash -c "sed -i 's/archive.ubuntu.com/${APT_REPO}/g' /etc/apt/sources.list"
  15. RUN apt-get update -y && \
  16. DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
  17. g++ \
  18. curl \
  19. ca-certificates \
  20. libc6-dev \
  21. make \
  22. libssl-dev \
  23. pkg-config \
  24. git \
  25. cmake \
  26. zlib1g-dev
  27. RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
  28. --default-toolchain stable --profile minimal -y
  29. COPY . .
  30. RUN cp ./docker/cargo.confg $HOME/.cargo/config
  31. RUN bash -c 'source $HOME/.cargo/env && cargo test --release --all'
  32. RUN bash -c 'source $HOME/.cargo/env && cargo build --release'
  33. ##################
  34. # Output image #
  35. ##################
  36. FROM ubuntu:22.04 AS binary
  37. RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
  38. ca-certificates
  39. RUN mkdir -p /opt/triagebot
  40. COPY --from=build /target/release/triagebot /usr/local/bin/
  41. COPY templates /opt/triagebot/templates
  42. WORKDIR /opt/triagebot
  43. ENV PORT=80
  44. CMD triagebot