Browse Source

Add CLIENT_BRANCH build argument to Dockerfile and workflow

Co-authored-by: mimartin12 <77340197+mimartin12@users.noreply.github.com>
copilot/fix-f020dc52-a8c0-41f7-a28c-c4f2c56f1ada
copilot-swe-agent[bot] 3 months ago
parent
commit
21cf793e15
  1. 17
      .github/workflows/build-unified.yml
  2. 66
      docker-unified/Dockerfile

17
.github/workflows/build-unified.yml

@ -11,6 +11,10 @@ on: @@ -11,6 +11,10 @@ on:
description: "Server branch name to deploy (examples: 'main', 'rc', 'feature/sm')"
type: string
default: main
client_branch:
description: "Client branch name to deploy (examples: 'main', 'rc', 'feature/name') - defaults to 'main' which uses latest release"
type: string
default: main
use_latest_core_version:
description: "Use the latest core version from versions.json instead of branch"
type: boolean
@ -57,6 +61,17 @@ jobs: @@ -57,6 +61,17 @@ jobs:
echo "ref_type=branch" >> $GITHUB_OUTPUT
fi
- name: Get client branch to use
id: client-branch-name
env:
CLIENT_BRANCH: ${{ inputs.client_branch }}
run: |
if [[ -z "${CLIENT_BRANCH}" ]]; then
echo "client_ref=main" >> $GITHUB_OUTPUT
else
echo "client_ref=${CLIENT_BRANCH#refs/heads/}" >> $GITHUB_OUTPUT
fi
- name: Check Branch to Publish
env:
PUBLISH_BRANCHES: "main,rc,hotfix-rc"
@ -171,6 +186,8 @@ jobs: @@ -171,6 +186,8 @@ jobs:
linux/arm64/v8
push: true
tags: ${{ steps.tag-list.outputs.tags }}
build-args: |
CLIENT_BRANCH=${{ steps.client-branch-name.outputs.client_ref }}
- name: Install Cosign
if: env.is_publish_branch == 'true'

66
docker-unified/Dockerfile

@ -4,31 +4,63 @@ @@ -4,31 +4,63 @@
###############################################
FROM --platform=$BUILDPLATFORM alpine:3.21 AS web-setup
# Build argument for client branch - defaults to 'main' for branch builds
ARG CLIENT_BRANCH=main
# Add packages
RUN apk add --no-cache \
curl \
jq \
unzip \
git
git \
nodejs \
npm
WORKDIR /tmp
# Grab last tag/release of the 'web' client
RUN git ls-remote --tags https://github.com/bitwarden/clients.git | grep refs/tags/web | cut -d/ -f3 | sort -Vr | head -1 > tag.txt
RUN cat tag.txt
# Extract the version of the 'web' client
RUN cat tag.txt | grep -o -E "[0-9]{4}\.[0-9]{1,2}\.[0-9]+" > version.txt
# Download the built release artifact for the 'web' client
RUN TAG=$(cat tag.txt) \
&& VERSION=$(cat version.txt) \
&& curl --proto "=https" -L https://github.com/bitwarden/clients/releases/download/$TAG/web-$VERSION-selfhosted-COMMERCIAL.zip -O
# Unzip the 'web' client to /tmp/build
RUN VERSION=$(cat version.txt) \
&& unzip web-$VERSION-selfhosted-COMMERCIAL.zip
# Check if CLIENT_BRANCH looks like a release tag (starts with 'web-v' and contains version pattern)
# If it's a release tag, download the pre-built artifact; otherwise build from source
RUN if echo "$CLIENT_BRANCH" | grep -q "^web-v[0-9]\{4\}\.[0-9]\{1,2\}\.[0-9]\+"; then \
echo "Using release tag: $CLIENT_BRANCH" \
&& echo "$CLIENT_BRANCH" > tag.txt \
&& cat tag.txt | grep -o -E "[0-9]{4}\.[0-9]{1,2}\.[0-9]+" > version.txt \
&& echo "release" > build_mode.txt; \
elif [ "$CLIENT_BRANCH" = "main" ]; then \
echo "Using main branch - getting latest release" \
&& git ls-remote --tags https://github.com/bitwarden/clients.git | grep refs/tags/web | cut -d/ -f3 | sort -Vr | head -1 > tag.txt \
&& cat tag.txt \
&& cat tag.txt | grep -o -E "[0-9]{4}\.[0-9]{1,2}\.[0-9]+" > version.txt \
&& echo "release" > build_mode.txt; \
else \
echo "Building from branch: $CLIENT_BRANCH" \
&& echo "$CLIENT_BRANCH" > branch.txt \
&& echo "branch" > build_mode.txt; \
fi
# Download release artifact if in release mode
RUN if [ "$(cat build_mode.txt)" = "release" ]; then \
TAG=$(cat tag.txt) \
&& VERSION=$(cat version.txt) \
&& echo "Downloading release artifact for $TAG" \
&& curl --proto "=https" -L https://github.com/bitwarden/clients/releases/download/$TAG/web-$VERSION-selfhosted-COMMERCIAL.zip -O \
&& unzip web-$VERSION-selfhosted-COMMERCIAL.zip; \
fi
# Build from source if in branch mode
RUN if [ "$(cat build_mode.txt)" = "branch" ]; then \
BRANCH=$(cat branch.txt) \
&& echo "Cloning and building from branch: $BRANCH" \
&& git clone --depth 1 --branch "$BRANCH" https://github.com/bitwarden/clients.git \
&& cd clients \
&& npm ci \
&& cd apps/web \
&& npm run build:bit:selfhost:prod \
&& mkdir -p /tmp/build \
&& cp -r build/* /tmp/build/; \
fi
# Ensure build directory exists for the copy step in final stage
RUN if [ ! -d "/tmp/build" ]; then mkdir -p /tmp/build; fi
###############################################
# Build stage #

Loading…
Cancel
Save