forked from Gelbpunkt/gateway-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |