From b4a78169cab4fe16a625d175b1df1a3d13c6cb5a Mon Sep 17 00:00:00 2001 From: KagChi <59391215+KagChi@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:30:19 +0000 Subject: [PATCH] chore: update --- Dockerfile | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index e8898c8..fe9f455 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,29 +2,38 @@ FROM alpine:latest AS builder ARG SIMD=1 -RUN apk upgrade && \ - apk add curl gcc g++ musl-dev cmake make && \ - curl -sSf https://sh.rustup.rs | sh -s -- --profile minimal --default-toolchain nightly -y +# Step 1: Update and install dependencies +RUN apk update && apk upgrade && \ + apk add curl gcc g++ musl-dev cmake make + +# Step 2: Install Rust +RUN curl -sSf https://sh.rustup.rs | sh -s -- --profile minimal --default-toolchain nightly -y + +# Step 3: Set environment variables +ENV PATH="/root/.cargo/bin:${PATH}" WORKDIR /build +# Step 4: Copy necessary files COPY Cargo.toml Cargo.lock ./ COPY .cargo ./.cargo/ -RUN mkdir src/ -RUN echo 'fn main() {}' > ./src/main.rs -RUN source $HOME/.cargo/env && \ - if [ "$SIMD" == '0' ]; then \ +# Step 5: Create dummy main.rs for initial build +RUN mkdir src/ && echo 'fn main() {}' > ./src/main.rs + +# Step 6: Build the project +RUN if [ "$SIMD" == '0' ]; then \ cargo build --release --no-default-features --features no-simd; \ else \ cargo build --release; \ fi +# Step 7: Clean up and prepare for the final build RUN rm -f target/release/deps/gateway_proxy* COPY ./src ./src -RUN source $HOME/.cargo/env && \ - if [ "$TARGET_CPU" == 'x86-64' ]; then \ +# Step 8: Final build +RUN if [ "$TARGET_CPU" == 'x86-64' ]; then \ cargo build --release --no-default-features --features no-simd; \ else \ cargo build --release; \ @@ -32,8 +41,8 @@ RUN source $HOME/.cargo/env && \ cp target/release/gateway-proxy /gateway-proxy && \ strip /gateway-proxy +# Final stage FROM scratch - COPY --from=builder /gateway-proxy /gateway-proxy -CMD ["./gateway-proxy"] \ No newline at end of file +CMD ["./gateway-proxy"]