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

container: bw-cli #11

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 19 additions & 11 deletions .github/scripts/generate_matrix.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,27 @@ async function generateMatrix() {
}
}
}
console.log(`Job matrix: ${JSON.stringify({ include: matrix }, null, 2)}`)

fs.writeFile('matrix.json', JSON.stringify({ include: matrix }, null, 0), err => {
if (err) {
console.log("Failed to write matrix to file.")
console.error(err);
} else {
console.log("Matrix dumped to file successfully.")
}
});

return matrix;
}

generateMatrix().catch(error => {
const matrixFile = 'matrix.json';
let matrixString = ""
const jobMatrix = await generateMatrix().catch(error => {
console.error('Error generating matrix:', error);
process.exit(1);
});

if (jobMatrix.length > 0) {
matrixString = JSON.stringify({ include: jobMatrix }, null, 0)
}

console.log(`Job matrix: ${matrixString}`)
fs.writeFile(matrixFile, matrixString, err => {
if (err) {
console.log("Failed to write matrix to file.")
console.error(err);
} else {
console.log("Matrix dumped to file successfully.")
}
});
4 changes: 2 additions & 2 deletions .github/workflows/docker-cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
echo "matrix=${matrix}" | tee $GITHUB_OUTPUT

cleanup-tagged-images:
if: needs.generate-matrix.outputs.matrix != ''
name: "${{ matrix.job_name }}"
runs-on: ubuntu-latest
needs: generate-matrix
if: ${{ fromJson(needs.generate-matrix.outputs.matrix)['include'].length > 0 }}
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
Expand All @@ -68,12 +68,12 @@ jobs:
match_regex: '^pr-(\d+)$|^(\d+)$'

cleanup-untagged-images:
if: needs.generate-matrix.outputs.matrix != ''
name: "${{ matrix.job_name }}"
runs-on: ubuntu-latest
needs:
- generate-matrix
- cleanup-tagged-images
if: ${{ fromJson(needs.generate-matrix.outputs.matrix)['include'].length > 0 }}
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
name: ${{ matrix.job_name }}
needs: generate-matrix
uses: mirceanton/reusable-workflows/.github/workflows/docker-release.yaml@main
if: ${{ fromJson(needs.generate-matrix.outputs.matrix)['include'].length > 0 }}
if: needs.generate-matrix.outputs.matrix != ''
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
secrets: inherit
Expand Down
47 changes: 47 additions & 0 deletions containers/bw-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ARG VERSION=2024.8.1

# =================================================================================================
# BUILDER STAGE
# =================================================================================================
FROM mcr.microsoft.com/devcontainers/javascript-node:20-bookworm AS build

ARG VERSION
RUN echo "Building Bitwarden CLI v${VERSION}"

ARG TARGETARCH
RUN if [[ "$TARGETARCH" == "amd64" ]]; then export ARCH="x64"; fi
RUN if [[ "$TARGETARCH" == "arm64" ]]; then export ARCH="arm64"; fi
RUN if [[ "$ARCH" == "" ]]; then echo "Unsupported architecture: $TARGETARCH" && exit 1; fi
RUN echo "Building for arch ${ARCH}"

ARG TARGETOS
RUN echo "Building for os ${TARGETOS}"

# Install dependencies
RUN npm install -g pkg

# Clone the github repository
WORKDIR /app
RUN git clone https://github.com/bitwarden/clients
WORKDIR /app/clients
RUN git checkout cli-v${VERSION}

# Install dependencies
RUN npm install
WORKDIR /app/clients/apps/cli
RUN npm install

# Build the binary
RUN npm run build:oss

# Package the binary
RUN pkg . --targets node18-${TARGETOS}-${ARCH} --output=/bw

# =================================================================================================
# PRODUCTION STAGE
# =================================================================================================
FROM scratch
USER 8675:8675
COPY --from=build /bw /bw
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/bw"]