Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi authored Jun 27, 2024
1 parent ad48029 commit b4a7816
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,47 @@ 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; \
fi && \
cp target/release/gateway-proxy /gateway-proxy && \
strip /gateway-proxy

# Final stage
FROM scratch

COPY --from=builder /gateway-proxy /gateway-proxy

CMD ["./gateway-proxy"]
CMD ["./gateway-proxy"]

0 comments on commit b4a7816

Please sign in to comment.