Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cross-compiled bin not working without emulation on host #1176

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions crates/bws/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###############################################
# Build stage #
###############################################
FROM --platform=$BUILDPLATFORM rust:1.81 AS build
FROM rust:1.81 AS build

# Docker buildx supplies the value for this arg
ARG TARGETPLATFORM
Expand All @@ -13,16 +13,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Copy required project files
COPY . /app

# Set required args for build
ENV CARGO_TARGET_DIR='./target'
ENV RUSTFLAGS='-C target-feature=+crt-static'

# Build project
WORKDIR /app/crates/bws
RUN cargo build --release --bin bws

# Bundle bws dependencies
RUN mkdir /lib-bws
RUN mkdir /lib64-bws

RUN ldd /app/target/release/bws | tr -s '[:blank:]' '\n' | grep '^/lib' | xargs -I % cp % /lib-bws
RUN ldd /app/target/release/bws | tr -s '[:blank:]' '\n' | grep '^/lib64' | xargs -I % cp % /lib64-bws
RUN <<EOF
# Explicit target args are required: https://github.com/rust-lang/rust/issues/78210#issuecomment-714776007
case "$TARGETPLATFORM" in
*"linux/amd64"*)
cargo build --release --bin bws --target x86_64-unknown-linux-gnu
mv ./target/x86_64-unknown-linux-gnu/release/bws ./target/release/bws;;
*"linux/arm64"*)
cargo build --release --bin bws --target aarch64-unknown-linux-gnu
mv ./target/aarch64-unknown-linux-gnu/release/bws ./target/release/bws;;
*)
echo "Unsupported target platform: $TARGETPLATFORM";
exit 1;;
esac
EOF

# Make a user and HOME directory for the app stage
RUN useradd -m app
Expand All @@ -32,7 +42,6 @@ RUN useradd -m app
###############################################
FROM scratch

ARG TARGETPLATFORM
LABEL com.bitwarden.product="bitwarden"

# Set a HOME directory and copy the user file
Expand All @@ -45,13 +54,9 @@ WORKDIR /home/app
USER app

# Copy built project from the build stage
COPY --from=build /app/target/release/bws /bin/bws
COPY --from=build /app/crates/bws/target/release/bws /bin/bws

# Copy certs
COPY --from=build /etc/ssl/certs /etc/ssl/certs

# Copy bws dependencies
COPY --from=build /lib-bws /lib
COPY --from=build /lib64-bws /lib64

ENTRYPOINT ["bws"]
Loading