From 18097ff808a3c002c4991c3591846c927ad67b0c Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Mon, 22 Jul 2024 02:27:12 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=94=EC=9D=B4=EB=84=88=EB=A6=AC=20?= =?UTF-8?q?=ED=81=AC=EA=B8=B0=20=EC=A1=B0=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- Dockerfile | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80f0d4e..b26c81a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ errno = { version = "*", default-features = false } panic = "abort" [profile.release] -#opt-level = 'z' # Optimize for size. +opt-level = 'z' # Optimize for size. lto = true # Enable Link Time Optimization codegen-units = 1 # Reduce number of codegen units to increase optimizations. panic = 'abort' # Abort on panic diff --git a/Dockerfile b/Dockerfile index 2d74ae2..66c8a5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,15 @@ ## ## Build ## -FROM rust:1-alpine3.19 AS build +FROM rust:1-alpine3.20 AS build LABEL org.opencontainers.image.authors="Sangbum Kim " # set the workdir and copy the source into it WORKDIR /app COPY . /app -ENV RUSTFLAGS='-C panic=abort -C link-arg=-s -C link-arg=-fuse-ld=lld' + +ENV RUSTFLAGS='-Cpanic=abort -Crelocation-model=static -Clink-args=-Wl,-x,-s,-fuse-ld=lld,--as-needed,--gc-sections,--no-gnu-unique,--nostdlib,--no-pie,--build-id=none,--no-eh-frame-hdr' RUN set -x && \ apk add --no-cache \ @@ -20,15 +21,19 @@ RUN set -x && \ musl-dev RUN set -x && \ - cargo build --release && \ - ls -alh target/release/init-wrapper + cargo build --release -- -C prefer-dynamic&& \ + objcopy -R .eh_frame -R .got.plt target/release/init-wrapper target/release/init-wrapper && \ + ls -alh target/release/init-wrapper && \ + readelf -W -S ./target/release/init-wrapper +# && \ +# ./target/release/init-wrapper # ldd target/release/init-wrapper && \ # && \ # ldd target/release/init-wrapper -# RUN --mount=type=bind,rw,source=.,target=/host \ -# cp -avf target/release/init-wrapper /host/init-wrapper && \ -# ./target/release/init-wrapper + RUN --mount=type=bind,rw,source=.,target=/host \ + cp -avf target/release/init-wrapper /host/init-wrapper && \ + ./target/release/init-wrapper FROM scratch