# This Dockerfile is composed of two steps: the first one builds the release # binary, and then the binary is copied inside another, empty image. ################# # Build image # ################# FROM ubuntu:22.04 as build # For CI/CD purposes, we can pass a pre-run command to the build image ARG PRE_RUN_CMD="echo pre-run-cmd" ARG APT_REPO="cn.archive.ubuntu.com" ENV RUSTUP_DIST_SERVER="https://rsproxy.cn" ENV RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" # 用于在CICD系统中执行自定义命令 RUN $PRE_RUN_CMD RUN bash -c "sed -i 's/archive.ubuntu.com/${APT_REPO}/g' /etc/apt/sources.list" RUN apt-get update -y && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ g++ \ curl \ ca-certificates \ libc6-dev \ make \ libssl-dev \ pkg-config \ git \ cmake \ zlib1g-dev RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ --default-toolchain stable --profile minimal -y COPY . . RUN cp ./docker/cargo.confg $HOME/.cargo/config RUN bash -c 'source $HOME/.cargo/env && cargo test --release --all' RUN bash -c 'source $HOME/.cargo/env && cargo build --release' ################## # Output image # ################## FROM ubuntu:22.04 AS binary RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ ca-certificates RUN mkdir -p /opt/triagebot COPY --from=build /target/release/triagebot /usr/local/bin/ COPY templates /opt/triagebot/templates WORKDIR /opt/triagebot ENV PORT=80 CMD triagebot