Skip to content

Commit 5fd0a41

Browse files
authored
Refactor Dockerfile to use multi-stage builds (#3)
1 parent 09ae12d commit 5fd0a41

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

Dockerfile

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
FROM debian:bookworm-slim
1+
# Build stage
2+
FROM node:20-bookworm AS builder
23

34
ARG BWDC_VERSION=2026.1.0
45

6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
git \
8+
python3 \
9+
make \
10+
g++ \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
WORKDIR /build
14+
15+
RUN git clone --depth 1 --branch v${BWDC_VERSION} \
16+
https://github.com/bitwarden/directory-connector.git .
17+
18+
RUN npm ci
19+
20+
RUN npm run build:cli:prod && npm run clean:dist:cli
21+
22+
# Determine arch and run pkg with correct target
23+
RUN PKG_ARCH=$(uname -m | sed 's/x86_64/x64/' | sed 's/aarch64/arm64/') && \
24+
npx pkg ./src-cli --targets linux-${PKG_ARCH} --output ./dist-cli/linux/bwdc
25+
26+
# Runtime stage
27+
FROM debian:bookworm-slim
28+
529
RUN apt-get update && apt-get install -y --no-install-recommends \
630
libsecret-1-0 \
7-
curl \
8-
unzip \
931
ca-certificates \
1032
&& rm -rf /var/lib/apt/lists/*
1133

12-
RUN curl -L "https://github.com/bitwarden/directory-connector/releases/download/v${BWDC_VERSION}/bwdc-linux-${BWDC_VERSION}.zip" -o /tmp/bwdc.zip && \
13-
unzip /tmp/bwdc.zip -d /usr/local/bin && \
14-
chmod +x /usr/local/bin/bwdc && \
15-
rm /tmp/bwdc.zip
34+
COPY --from=builder /build/dist-cli/linux/ /usr/local/bin/
35+
RUN chmod +x /usr/local/bin/bwdc
1636

1737
RUN useradd -r -s /bin/false bitwarden && \
18-
mkdir -p /home/bitwarden/.config/Bitwarden\ Directory\ Connector && \
38+
mkdir -p "/home/bitwarden/.config/Bitwarden Directory Connector" && \
1939
chown -R bitwarden:bitwarden /home/bitwarden
2040

2141
COPY entrypoint.sh /entrypoint.sh
@@ -24,5 +44,4 @@ RUN chmod +x /entrypoint.sh && sed -i 's/\r$//' /entrypoint.sh
2444
ENV BITWARDENCLI_CONNECTOR_PLAINTEXT_SECRETS=true
2545

2646
USER bitwarden
27-
2847
ENTRYPOINT ["/entrypoint.sh"]

0 commit comments

Comments
 (0)