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

[PM-7068] - Use a distroless container image for bws #681

Merged
merged 3 commits into from
Apr 8, 2024
Merged
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
26 changes: 17 additions & 9 deletions crates/bws/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@ COPY . /app

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

# Bundle bws dependencies
RUN mkdir /lib-bws
RUN ldd /app/target/release/bws | tr -s '[:blank:]' '\n' | grep '^/' | xargs -I % cp % /lib-bws

# Make a HOME directory for the app stage
RUN mkdir -p /home/app

###############################################
# App stage #
###############################################
FROM debian:bookworm-slim
FROM scratch

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

# Set a HOME directory
COPY --from=build /home/app /home/app
ENV HOME=/home/app

# Copy built project from the build stage
WORKDIR /usr/local/bin
COPY --from=build /app/target/release/bws .
COPY --from=build /etc/ssl/certs /etc/ssl/certs

# Create a non-root user
RUN useradd -ms /bin/bash app

# Switch to the non-root user
USER app
# Copy certs
COPY --from=build /etc/ssl/certs /etc/ssl/certs

WORKDIR /home/app
# Copy bws dependencies
COPY --from=build /lib-bws /lib

ENTRYPOINT ["bws"]
Loading