From 4c02d3be9486f145a321b2787e6d7494400cbc14 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Tue, 20 Feb 2024 08:40:53 -0300 Subject: [PATCH 1/3] Using multistage build --- Dockerfile | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b83f1c..9e9077d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,33 @@ +# First stage: Download and extract the Bitwarden CLI +FROM python:3.11.0-slim-bullseye as builder + +# Install dependencies for downloading and extracting Bitwarden CLI +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl jq unzip + +# Download and extract Bitwarden CLI +# Taken from https://github.com/tangowithfoxtrot/bw-docker/blob/main/Dockerfile#L7 +RUN export VER=$(curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/bitwarden/clients/releases | jq -r 'sort_by(.published_at) | reverse | .[].name | select( index("CLI") )' | sed 's:.*CLI v::' | head -n 1) && \ + curl -LO "https://github.com/bitwarden/clients/releases/download/cli-v${VER}/bw-linux-${VER}.zip" && \ + unzip *.zip && \ + chmod +x ./bw + +# Second stage: Build the final image FROM python:3.11.0-slim-bullseye +# Copy Bitwarden CLI from the builder stage +COPY --from=builder /bw /bin/bw + +# Set up the working directory WORKDIR /bitwarden-to-keepass + +# Copy the application files COPY . . -RUN apt-get update && \ - apt-get install -y unzip curl jq && \ - # Taken from https://github.com/tangowithfoxtrot/bw-docker/blob/main/Dockerfile#L7 - export VER=$(curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/bitwarden/clients/releases | jq -r 'sort_by(.published_at) | reverse | .[].name | select( index("CLI") )' | sed 's:.*CLI v::' | head -n 1) && \ - curl -LO "https://github.com/bitwarden/clients/releases/download/cli-v{$VER}/bw-linux-{$VER}.zip" && \ - unzip *.zip && chmod +x ./bw && \ - mv bw /bin/ && \ - pip install --no-cache-dir --upgrade pip && \ - pip install --no-cache-dir -r requirements.txt && \ - apt-get purge -y --auto-remove unzip curl jq && \ - apt-get clean && \ +# Install Python dependencies +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt + +# Clean up unnecessary files to reduce image size +RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* From 938af1ea36eb04f02e9327ef892ef151c9086aa9 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Tue, 20 Feb 2024 08:45:20 -0300 Subject: [PATCH 2/3] Using multistage to get the cli from another prebuilt image --- Dockerfile | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9e9077d..b61473a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,12 @@ -# First stage: Download and extract the Bitwarden CLI -FROM python:3.11.0-slim-bullseye as builder +FROM tangowithfoxtrot/bw-cli as builder -# Install dependencies for downloading and extracting Bitwarden CLI -RUN apt-get update && \ - apt-get install -y --no-install-recommends curl jq unzip - -# Download and extract Bitwarden CLI -# Taken from https://github.com/tangowithfoxtrot/bw-docker/blob/main/Dockerfile#L7 -RUN export VER=$(curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/bitwarden/clients/releases | jq -r 'sort_by(.published_at) | reverse | .[].name | select( index("CLI") )' | sed 's:.*CLI v::' | head -n 1) && \ - curl -LO "https://github.com/bitwarden/clients/releases/download/cli-v${VER}/bw-linux-${VER}.zip" && \ - unzip *.zip && \ - chmod +x ./bw - -# Second stage: Build the final image FROM python:3.11.0-slim-bullseye -# Copy Bitwarden CLI from the builder stage -COPY --from=builder /bw /bin/bw +COPY --from=builder /usr/local/bin/bw /bin/bw -# Set up the working directory WORKDIR /bitwarden-to-keepass -# Copy the application files COPY . . -# Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt - -# Clean up unnecessary files to reduce image size -RUN apt-get clean && \ - rm -rf /var/lib/apt/lists/* From 6595082d5016299dd4c41523d6a3c2a0da63874e Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Tue, 20 Feb 2024 09:20:47 -0300 Subject: [PATCH 3/3] Downloading the CLI directly from Bitwarden's site --- Dockerfile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b61473a..1f01dd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,17 @@ -FROM tangowithfoxtrot/bw-cli as builder - FROM python:3.11.0-slim-bullseye -COPY --from=builder /usr/local/bin/bw /bin/bw +RUN apt-get update && \ + apt-get install -y --no-install-recommends wget unzip && \ + wget -O "bw.zip" "https://vault.bitwarden.com/download/?app=cli&platform=linux" && \ + unzip bw.zip && \ + chmod +x ./bw && \ + mv ./bw /usr/local/bin/bw && \ + apt-get purge -y --auto-remove wget unzip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + rm -rf bw.zip WORKDIR /bitwarden-to-keepass - COPY . . RUN pip install --no-cache-dir --upgrade pip && \