Skip to content

Commit 32d3307

Browse files
authored
Merge pull request #3 from alegeay/dev
Dev
2 parents 49d6e26 + 899cf21 commit 32d3307

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

‎Dockerfile‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1-
# Étape 1 : Compilation avec nightly + build-std
1+
# Étape 1 : Compilation
22
FROM rust:1.83-alpine AS builder
33

4+
ARG TARGETARCH
5+
46
RUN apk add --no-cache musl-dev upx
57

6-
# Installer nightly et rust-src
7-
RUN rustup toolchain install nightly \
8-
&& rustup component add rust-src --toolchain nightly
8+
# Déterminer la target en fonction de l'architecture
9+
# Si TARGETARCH n'est pas défini (legacy builder), on détecte l'arch native
10+
RUN if [ -z "$TARGETARCH" ]; then \
11+
case "$(uname -m)" in \
12+
x86_64) TARGETARCH=amd64 ;; \
13+
aarch64) TARGETARCH=arm64 ;; \
14+
esac; \
15+
fi && \
16+
case "$TARGETARCH" in \
17+
amd64) echo "x86_64-unknown-linux-musl" > /tmp/rust_target ;; \
18+
arm64) echo "aarch64-unknown-linux-musl" > /tmp/rust_target ;; \
19+
*) echo "Unsupported arch: $TARGETARCH" && exit 1 ;; \
20+
esac && \
21+
rustup target add $(cat /tmp/rust_target)
922

1023
WORKDIR /app
1124

1225
# Cache des dépendances
1326
COPY Cargo.toml Cargo.lock* ./
14-
RUN mkdir src && echo "fn main() {}" > src/main.rs \
15-
&& RUSTFLAGS="-Zunstable-options -Cpanic=abort" cargo +nightly build --release \
16-
-Z build-std=std,panic_abort \
17-
--target x86_64-unknown-linux-musl \
27+
RUN RUST_TARGET=$(cat /tmp/rust_target) \
28+
&& mkdir src && echo "fn main() {}" > src/main.rs \
29+
&& cargo build --release --target $RUST_TARGET \
1830
&& rm -rf src
1931

20-
# Compilation du binaire avec build-std
32+
# Compilation du binaire
2133
COPY src ./src
22-
RUN touch src/main.rs \
23-
&& RUSTFLAGS="-Zunstable-options -Cpanic=abort" cargo +nightly build --release \
24-
-Z build-std=std,panic_abort \
25-
--target x86_64-unknown-linux-musl \
26-
&& strip target/x86_64-unknown-linux-musl/release/naolametric \
27-
&& upx --best --lzma target/x86_64-unknown-linux-musl/release/naolametric
34+
RUN RUST_TARGET=$(cat /tmp/rust_target) \
35+
&& touch src/main.rs \
36+
&& cargo build --release --target $RUST_TARGET \
37+
&& strip target/$RUST_TARGET/release/naolametric \
38+
&& upx --best --lzma target/$RUST_TARGET/release/naolametric \
39+
&& cp target/$RUST_TARGET/release/naolametric /naolametric-bin
2840

2941
# Étape 2 : Image scratch
3042
FROM scratch
3143

32-
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/naolametric /naolametric
44+
COPY --from=builder /naolametric-bin /naolametric
3345

3446
ENV PORT=8080
3547
EXPOSE 8080

0 commit comments

Comments
 (0)