-
Notifications
You must be signed in to change notification settings - Fork 17
/
Dockerfile
44 lines (34 loc) · 1.41 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# I will only support x86_64 hosts because this allows for best hardware optimizations.
# Compiling a Dockerfile for aarch64 should work but I won't support it myself.
ARG TARGET_CPU="haswell"
FROM docker.io/library/alpine:edge AS builder
ARG TARGET_CPU
ENV RUST_TARGET "x86_64-unknown-linux-musl"
ENV RUSTFLAGS "-Lnative=/usr/lib -C target-cpu=${TARGET_CPU}"
RUN apk upgrade && \
apk add curl gcc g++ musl-dev cmake make && \
curl -sSf https://sh.rustup.rs | sh -s -- --profile minimal --component rust-src --default-toolchain nightly -y
WORKDIR /build
COPY Cargo.toml Cargo.lock ./
COPY .cargo ./.cargo/
RUN mkdir src/
RUN echo 'fn main() {}' > ./src/main.rs
RUN source $HOME/.cargo/env && \
if [ "$TARGET_CPU" == 'x86-64' ]; then \
cargo build --release --target="$RUST_TARGET" --no-default-features --features no-simd; \
else \
cargo build --release --target="$RUST_TARGET"; \
fi
RUN rm -f target/$RUST_TARGET/release/deps/gateway_proxy*
COPY ./src ./src
RUN source $HOME/.cargo/env && \
if [ "$TARGET_CPU" == 'x86-64' ]; then \
cargo build --release --target="$RUST_TARGET" --no-default-features --features no-simd; \
else \
cargo build --release --target="$RUST_TARGET"; \
fi && \
cp target/$RUST_TARGET/release/gateway-proxy /gateway-proxy && \
strip /gateway-proxy
FROM scratch
COPY --from=builder /gateway-proxy /gateway-proxy
CMD ["./gateway-proxy"]