Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi authored Jun 27, 2024
1 parent 08aa094 commit be60a85
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
FROM debian:latest AS builder

FROM docker.io/library/alpine:edge AS builder
ARG SIMD=1

# Step 1: Update and install dependencies
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl gcc g++ 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}"

RUN rustup component add rust-src --toolchain nightly-aarch64-unknown-linux-gnu
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

WORKDIR /build

# Step 4: Copy necessary files
COPY Cargo.toml Cargo.lock ./

# Step 5: Create dummy main.rs for initial build
RUN mkdir src/ && echo 'fn main() {}' > ./src/main.rs

# Step 6: Build the project
RUN cargo build --no-default-features --features no-simd --release;
RUN mkdir src/
RUN echo 'fn main() {}' > ./src/main.rs
RUN source $HOME/.cargo/env && \
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

# Step 8: Final build
RUN cargo build --no-default-features --features no-simd --release && \
ls -l target/release && \
RUN source $HOME/.cargo/env && \
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"]

0 comments on commit be60a85

Please sign in to comment.