Skip to content

Commit 9670561

Browse files
authored
[BRE-1004] Add GHCR Support to Build/Publish workflows (#7263) (#7314)
(cherry picked from commit 7f2bde3)
1 parent ccf6c6e commit 9670561

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
name: Build
22

33
on:
4-
workflow_dispatch:
4+
pull_request:
5+
types: [opened, synchronize]
56
push:
67
branches:
78
- "main"
89
- "rc"
910
- "hotfix-rc"
10-
pull_request:
11-
types: [opened, synchronize]
1211
workflow_call:
13-
inputs: {}
12+
workflow_dispatch:
1413

1514
permissions:
1615
contents: read
1716

1817
env:
1918
_AZ_REGISTRY: "bitwardenprod.azurecr.io"
19+
_GHCR_REGISTRY: "ghcr.io/bitwarden"
2020
_GITHUB_PR_REPO_NAME: ${{ github.event.pull_request.head.repo.full_name }}
2121

2222
jobs:
@@ -45,6 +45,7 @@ jobs:
4545
permissions:
4646
security-events: write
4747
id-token: write
48+
packages: write
4849
timeout-minutes: 45
4950
strategy:
5051
fail-fast: false
@@ -177,15 +178,22 @@ jobs:
177178
- name: Set up Docker Buildx
178179
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
179180

180-
########## ACRs ##########
181+
########## Registries ##########
182+
- name: Log in to GHCR
183+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
184+
with:
185+
registry: ghcr.io
186+
username: ${{ github.actor }}
187+
password: ${{ secrets.GITHUB_TOKEN }}
188+
181189
- name: Log in to Azure
182190
uses: bitwarden/gh-actions/azure-login@main
183191
with:
184192
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
185193
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
186194
client_id: ${{ secrets.AZURE_CLIENT_ID }}
187195

188-
- name: Log in to ACR - production subscription
196+
- name: Log in to ACR
189197
run: az acr login -n bitwardenprod
190198

191199
########## Generate image tag and build Docker image ##########
@@ -227,10 +235,13 @@ jobs:
227235
PROJECT_NAME: ${{ steps.setup.outputs.project_name }}
228236
SHA: ${{ github.sha }}
229237
run: |
230-
TAGS="${_AZ_REGISTRY}/${PROJECT_NAME}:${IMAGE_TAG}"
231-
echo "primary_tag=$TAGS" >> "$GITHUB_OUTPUT"
238+
GHCR_TAG="${_GHCR_REGISTRY}/${PROJECT_NAME}:${IMAGE_TAG}"
239+
ACR_TAG="${_AZ_REGISTRY}/${PROJECT_NAME}:${IMAGE_TAG}"
240+
TAGS="${GHCR_TAG},${ACR_TAG}"
241+
echo "primary_tag=${GHCR_TAG}" >> "$GITHUB_OUTPUT"
232242
if [[ "${IMAGE_TAG}" == "dev" ]]; then
233243
SHORT_SHA=$(git rev-parse --short "${SHA}")
244+
TAGS=$TAGS",${_GHCR_REGISTRY}/${PROJECT_NAME}:dev-${SHORT_SHA}"
234245
TAGS=$TAGS",${_AZ_REGISTRY}/${PROJECT_NAME}:dev-${SHORT_SHA}"
235246
fi
236247
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
@@ -255,11 +266,11 @@ jobs:
255266
tags: ${{ steps.image-tags.outputs.tags }}
256267

257268
- name: Install Cosign
258-
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
269+
if: github.event_name != 'pull_request' && env.is_publish_branch == 'true'
259270
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
260271

261272
- name: Sign image with Cosign
262-
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
273+
if: github.event_name != 'pull_request' && env.is_publish_branch == 'true'
263274
env:
264275
DIGEST: ${{ steps.build-artifacts.outputs.digest }}
265276
TAGS: ${{ steps.image-tags.outputs.tags }}
@@ -287,6 +298,9 @@ jobs:
287298
sha: ${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.sha || github.sha }}
288299
ref: ${{ contains(github.event_name, 'pull_request') && format('refs/pull/{0}/head', github.event.pull_request.number) || github.ref }}
289300

301+
- name: Log out from GHCR
302+
run: docker logout ghcr.io
303+
290304
- name: Log out from Azure
291305
uses: bitwarden/gh-actions/azure-logout@main
292306

@@ -307,15 +321,12 @@ jobs:
307321
- name: Set up .NET
308322
uses: actions/setup-dotnet@baa11fbfe1d6520db94683bd5c7a3818018e4309 # v5.1.0
309323

310-
- name: Log in to Azure
311-
uses: bitwarden/gh-actions/azure-login@main
324+
- name: Log in to GHCR
325+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
312326
with:
313-
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
314-
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
315-
client_id: ${{ secrets.AZURE_CLIENT_ID }}
316-
317-
- name: Log in to ACR - production subscription
318-
run: az acr login -n "$_AZ_REGISTRY" --only-show-errors
327+
registry: ghcr.io
328+
username: ${{ github.actor }}
329+
password: ${{ secrets.GITHUB_TOKEN }}
319330

320331
- name: Make Docker stubs
321332
if: |
@@ -325,13 +336,13 @@ jobs:
325336
# Set proper setup image based on branch
326337
case "$GITHUB_REF" in
327338
"refs/heads/main")
328-
SETUP_IMAGE="$_AZ_REGISTRY/setup:dev"
339+
SETUP_IMAGE="${_GHCR_REGISTRY}/setup:dev"
329340
;;
330341
"refs/heads/rc")
331-
SETUP_IMAGE="$_AZ_REGISTRY/setup:rc"
342+
SETUP_IMAGE="${_GHCR_REGISTRY}/setup:rc"
332343
;;
333344
"refs/heads/hotfix-rc")
334-
SETUP_IMAGE="$_AZ_REGISTRY/setup:hotfix-rc"
345+
SETUP_IMAGE="${_GHCR_REGISTRY}/setup:hotfix-rc"
335346
;;
336347
esac
337348
@@ -359,8 +370,8 @@ jobs:
359370
cd docker-stub/US; zip -r ../../docker-stub-US.zip ./*; cd ../..
360371
cd docker-stub/EU; zip -r ../../docker-stub-EU.zip ./*; cd ../..
361372
362-
- name: Log out from Azure
363-
uses: bitwarden/gh-actions/azure-logout@main
373+
- name: Log out from GHCR
374+
run: docker logout ghcr.io
364375

365376
- name: Upload Docker stub US artifact
366377
if: |

.github/workflows/publish.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424

2525
env:
2626
_AZ_REGISTRY: "bitwardenprod.azurecr.io"
27+
_GHCR_REGISTRY: "ghcr.io/bitwarden"
2728

2829
jobs:
2930
setup:
@@ -69,6 +70,7 @@ jobs:
6970
permissions:
7071
contents: read
7172
id-token: write
73+
packages: write
7274
env:
7375
_RELEASE_VERSION: ${{ needs.setup.outputs.release-version }}
7476
_BRANCH_NAME: ${{ inputs.branch }}
@@ -107,7 +109,32 @@ jobs:
107109
echo "PROJECT_NAME: $PROJECT_NAME"
108110
echo "project_name=$PROJECT_NAME" >> "$GITHUB_OUTPUT"
109111
110-
########## ACR PROD ##########
112+
########## GHCR ##########
113+
- name: Log in to GHCR
114+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
115+
with:
116+
registry: ghcr.io
117+
username: ${{ github.actor }}
118+
password: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- name: Push version image
121+
env:
122+
PROJECT_NAME: ${{ steps.setup.outputs.project_name }}
123+
run: |
124+
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
125+
skopeo copy --all \
126+
"docker://$_GHCR_REGISTRY/$PROJECT_NAME:$_BRANCH_NAME" \
127+
"docker://$_GHCR_REGISTRY/$PROJECT_NAME:dryrun"
128+
else
129+
skopeo copy --all \
130+
"docker://$_GHCR_REGISTRY/$PROJECT_NAME:$_BRANCH_NAME" \
131+
"docker://$_GHCR_REGISTRY/$PROJECT_NAME:$_RELEASE_VERSION"
132+
fi
133+
134+
- name: Log out from GHCR
135+
run: docker logout ghcr.io
136+
137+
########## ACR ##########
111138
- name: Log in to Azure
112139
uses: bitwarden/gh-actions/azure-login@main
113140
with:

0 commit comments

Comments
 (0)