Skip to content

Update Rust and convert to Alpine #1228

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 9 additions & 22 deletions crates/bws/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
###############################################
# Build stage #
###############################################
FROM --platform=$BUILDPLATFORM rust:1.81 AS build
FROM --platform=$BUILDPLATFORM rust:1.86.0-alpine3.21 AS build

# Docker buildx supplies the value for this arg
ARG TARGETPLATFORM

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Add dev libraries. Make a user and HOME directory for the app stage
RUN apk add --no-cache musl-dev && adduser -D app

# Copy required project files
WORKDIR /app/crates/bws
COPY . /app

# 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

# Make a user and HOME directory for the app stage
RUN useradd -m app
RUN cargo build --release --bin bws

###############################################
# App stage #
Expand All @@ -36,8 +25,10 @@ ARG TARGETPLATFORM
LABEL com.bitwarden.product="bitwarden"

# Set a HOME directory and copy the user file
COPY --from=build /home/app /home/app
# Must chown home folder, otherwise bws config file writing will cause permission errors in output
COPY --from=build --chown=app:app /home/app /home/app
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
ENV HOME=/home/app
WORKDIR /home/app

Expand All @@ -48,10 +39,6 @@ USER app
COPY --from=build /app/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
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

ENTRYPOINT ["bws"]
Loading