Skip to content

Commit 63a710e

Browse files
authored
BRE-1190 - Update workflows to use GHCR instead of Azure ACR (#231)
1 parent c3c4a70 commit 63a710e

File tree

7 files changed

+124
-161
lines changed

7 files changed

+124
-161
lines changed

.github/workflows/build.yml

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ on:
77
- "main"
88
pull_request:
99

10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
1014
jobs:
1115
build-artifacts:
1216
name: Build artifacts
13-
runs-on: ubuntu-22.04
17+
runs-on: ubuntu-24.04
1418
permissions:
1519
contents: read
1620

@@ -24,59 +28,61 @@ jobs:
2428
- name: Publish project
2529
working-directory: src/KeyConnector
2630
run: |
27-
echo "Publish"
2831
dotnet publish -c "Release" -o obj/build-output/publish
2932
cd obj/build-output/publish
3033
zip -r KeyConnector.zip .
3134
mv KeyConnector.zip ../../../
32-
pwd
33-
ls -atlh ../../../
3435
3536
- name: Upload project artifact
3637
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
3738
with:
3839
name: KeyConnector.zip
3940
path: src/KeyConnector/KeyConnector.zip
4041
if-no-files-found: error
42+
retention-days: 7
4143

4244
build-docker:
4345
name: Build Docker images
4446
runs-on: ubuntu-24.04
4547
needs: build-artifacts
4648
permissions:
47-
security-events: write
4849
id-token: write
49-
env:
50-
_AZ_REGISTRY: bitwardenprod.azurecr.io
51-
_PROJECT_NAME: key-connector
50+
packages: write
51+
security-events: write
5252
steps:
5353
- name: Check out repo
5454
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
5555

56-
- name: Log in to Azure
57-
uses: bitwarden/gh-actions/azure-login@main
56+
- name: Login to GitHub Container Registry
57+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
5858
with:
59-
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
60-
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
61-
client_id: ${{ secrets.AZURE_CLIENT_ID }}
62-
63-
- name: Log in to ACR
64-
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}
59+
registry: ghcr.io
60+
username: ${{ github.actor }}
61+
password: ${{ secrets.GITHUB_TOKEN }}
6562

6663
- name: Generate Docker image tag
6764
id: tag
6865
run: |
69-
IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name
70-
if [[ "$IMAGE_TAG" == "main" ]]; then
66+
# Main branch always uses 'dev' tag
67+
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
7168
IMAGE_TAG=dev
69+
# PRs use 'pr-<number>' format for consistency
70+
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
71+
IMAGE_TAG="pr-${{ github.event.pull_request.number }}"
72+
# Other branches: sanitize name for Docker tag compatibility
73+
else
74+
# Extract branch name from refs
75+
IMAGE_TAG="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
76+
# Lowercase, replace invalid chars with dash, collapse dashes, trim, limit to 128 chars, remove trailing separators
77+
IMAGE_TAG=$(echo "$IMAGE_TAG" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9._-]+/-/g; s/-+/-/g; s/^-+|-+$//g' | cut -c1-128 | sed -E 's/[.-]$//')
7278
fi
7379
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
7480
7581
- name: Generate full image name
7682
id: image-name
7783
env:
7884
IMAGE_TAG: ${{ steps.tag.outputs.image_tag }}
79-
run: echo "name=${_AZ_REGISTRY}/${_PROJECT_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
85+
run: echo "name=ghcr.io/bitwarden/key-connector:${IMAGE_TAG}" >> $GITHUB_OUTPUT
8086

8187
- name: Get build artifact
8288
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -95,7 +101,8 @@ jobs:
95101
context: src/KeyConnector
96102
file: src/KeyConnector/Dockerfile
97103
platforms: linux/amd64
98-
push: true
104+
load: ${{ github.event_name == 'pull_request' }}
105+
push: ${{ github.event_name != 'pull_request' }}
99106
tags: ${{ steps.image-name.outputs.name }}
100107

101108
- name: Install Cosign
@@ -123,12 +130,12 @@ jobs:
123130
fail-build: false
124131
output-format: sarif
125132

126-
- name: Log out from Azure
127-
uses: bitwarden/gh-actions/azure-logout@main
128-
129133
- name: Upload Grype results to GitHub
130134
uses: github/codeql-action/upload-sarif@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13
131135
with:
132136
sarif_file: ${{ steps.container-scan.outputs.sarif }}
133137
sha: ${{ contains(github.event_name, 'pull_request') && github.event.pull_request.head.sha || github.sha }}
134138
ref: ${{ contains(github.event_name, 'pull_request') && format('refs/pull/{0}/head', github.event.pull_request.number) || github.ref }}
139+
140+
- name: Log out of Docker
141+
run: docker logout ghcr.io
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Cleanup Container Images
2+
3+
on:
4+
delete:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event.ref }}
8+
cancel-in-progress: false
9+
10+
jobs:
11+
cleanup-images:
12+
name: Delete branch container images
13+
runs-on: ubuntu-24.04
14+
permissions:
15+
packages: write
16+
steps:
17+
- name: Generate image tag to delete
18+
id: tag
19+
run: |
20+
# Sanitize deleted branch name to match build workflow tag generation
21+
BRANCH_NAME="${{ github.event.ref }}"
22+
IMAGE_TAG=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9._-]+/-/g; s/-+/-/g; s/^-+|-+$//g' | cut -c1-128 | sed -E 's/[.-]$//')
23+
echo "tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
24+
25+
- name: Delete container image version
26+
continue-on-error: true
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
IMAGE_TAG: ${{ steps.tag.outputs.tag }}
30+
run: |
31+
# Get the version ID for this specific tag
32+
VERSION_ID=$(gh api \
33+
-H "Accept: application/vnd.github+json" \
34+
-H "X-GitHub-Api-Version: 2022-11-28" \
35+
"/orgs/bitwarden/packages/container/key-connector/versions" \
36+
--jq ".[] | select(.metadata.container.tags[] | contains(\"$IMAGE_TAG\")) | .id" \
37+
| head -1)
38+
39+
if [[ -n "$VERSION_ID" ]]; then
40+
echo "Deleting image with tag: $IMAGE_TAG (version ID: $VERSION_ID)"
41+
gh api \
42+
--method DELETE \
43+
-H "Accept: application/vnd.github+json" \
44+
-H "X-GitHub-Api-Version: 2022-11-28" \
45+
"/orgs/bitwarden/packages/container/key-connector/versions/$VERSION_ID"
46+
echo "Successfully deleted image"
47+
else
48+
echo "No image found with tag: $IMAGE_TAG"
49+
fi

.github/workflows/publish.yml

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ jobs:
2525
permissions:
2626
contents: read
2727
outputs:
28-
release-version: ${{ steps.version-output.outputs.version }}
28+
release_version: ${{ steps.version-output.outputs.version }}
2929
steps:
3030
- name: Version output
3131
id: version-output
3232
run: |
3333
if [[ "${{ inputs.version }}" == "latest" || "${{ inputs.version }}" == "" ]]; then
34-
VERSION=$(curl "https://api.github.com/repos/bitwarden/directory-connector/releases" | jq -c '.[] | select(.tag_name) | .tag_name' | head -1 | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+')
34+
VERSION=$(curl -sSfL "https://api.github.com/repos/bitwarden/key-connector/releases" | jq -c '.[] | select(.tag_name) | .tag_name' | head -1 | grep -ohE '20[0-9]{2}\.([1-9]|1[0-2])\.[0-9]+')
35+
if [[ -z "$VERSION" ]]; then
36+
echo "Failed to fetch latest version"
37+
exit 1
38+
fi
3539
echo "Latest Released Version: $VERSION"
3640
echo "version=$VERSION" >> $GITHUB_OUTPUT
3741
else
@@ -44,81 +48,51 @@ jobs:
4448
runs-on: ubuntu-24.04
4549
needs: setup
4650
env:
47-
_AZ_REGISTRY: bitwardenprod.azurecr.io
48-
_PROJECT_NAME: key-connector
49-
_RELEASE_VERSION: ${{ needs.setup.outputs.release-version }}
51+
_RELEASE_VERSION: ${{ needs.setup.outputs.release_version }}
5052
permissions:
5153
id-token: write
5254
packages: write
5355
steps:
5456
- name: Install Cosign
5557
uses: sigstore/cosign-installer@d7d6bc7722e3daa8354c50bcb52f4837da5e9b6a # v3.8.1
5658

57-
- name: Log in to Azure
58-
uses: bitwarden/gh-actions/azure-login@main
59-
with:
60-
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
61-
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
62-
client_id: ${{ secrets.AZURE_CLIENT_ID }}
63-
64-
- name: Log in to ACR
65-
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}
66-
6759
- name: Login to GitHub Container Registry
68-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
60+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
6961
with:
7062
registry: ghcr.io
7163
username: ${{ github.actor }}
7264
password: ${{ secrets.GITHUB_TOKEN }}
7365

7466
- name: Pull image
75-
run: docker pull $_AZ_REGISTRY/$_PROJECT_NAME:dev
67+
run: docker pull ghcr.io/bitwarden/key-connector:dev
7668

7769
- name: Tag version and latest
7870
run: |
7971
if [[ "${{ inputs.publish_type }}" == "Dry Run" ]]; then
80-
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:dev ghcr.io/bitwarden/$_PROJECT_NAME:dryrun
72+
docker tag ghcr.io/bitwarden/key-connector:dev ghcr.io/bitwarden/key-connector:dryrun
8173
else
82-
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:dev $_AZ_REGISTRY/$_PROJECT_NAME:$_RELEASE_VERSION
83-
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:dev $_AZ_REGISTRY/$_PROJECT_NAME:latest
84-
85-
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:dev ghcr.io/bitwarden/$_PROJECT_NAME:$_RELEASE_VERSION
86-
docker tag $_AZ_REGISTRY/$_PROJECT_NAME:dev ghcr.io/bitwarden/$_PROJECT_NAME:latest
74+
docker tag ghcr.io/bitwarden/key-connector:dev ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
75+
docker tag ghcr.io/bitwarden/key-connector:dev ghcr.io/bitwarden/key-connector:latest
8776
fi
8877
89-
- name: Push release version and latest image to ACR
90-
if: ${{ inputs.publish_type != 'Dry Run' }}
91-
run: |
92-
docker push $_AZ_REGISTRY/$_PROJECT_NAME:$_RELEASE_VERSION
93-
docker push $_AZ_REGISTRY/$_PROJECT_NAME:latest
94-
9578
- name: Push release version and latest image
9679
if: ${{ inputs.publish_type != 'Dry Run' }}
9780
run: |
98-
docker push ghcr.io/bitwarden/$_PROJECT_NAME:$_RELEASE_VERSION
99-
docker push ghcr.io/bitwarden/$_PROJECT_NAME:latest
100-
101-
- name: Sign image with Cosign
102-
run: |
103-
cosign sign --yes ghcr.io/bitwarden/$_PROJECT_NAME:$_RELEASE_VERSION
104-
cosign sign --yes ghcr.io/bitwarden/$_PROJECT_NAME:latest
81+
docker push ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
82+
docker push ghcr.io/bitwarden/key-connector:latest
10583
10684
- name: Verify the signed image with Cosign
85+
if: ${{ inputs.publish_type != 'Dry Run' }}
10786
run: |
10887
cosign verify \
109-
--certificate-identity "${{ github.server_url }}/${{ github.workflow_ref }}" \
88+
--certificate-identity-regexp="https://github\.com/bitwarden/key-connector/.*" \
11089
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
111-
ghcr.io/bitwarden/$_PROJECT_NAME:$_RELEASE_VERSION
90+
ghcr.io/bitwarden/key-connector:$_RELEASE_VERSION
11291
11392
cosign verify \
114-
--certificate-identity "${{ github.server_url }}/${{ github.workflow_ref }}" \
93+
--certificate-identity-regexp="https://github\.com/bitwarden/key-connector/.*" \
11594
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
116-
ghcr.io/bitwarden/$_PROJECT_NAME:latest
95+
ghcr.io/bitwarden/key-connector:latest
11796
11897
- name: Log out of Docker
119-
run: |
120-
docker logout ghcr.io
121-
docker logout $_AZ_REGISTRY
122-
123-
- name: Log out from Azure
124-
uses: bitwarden/gh-actions/azure-logout@main
98+
run: docker logout ghcr.io

.github/workflows/release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ on:
1616
jobs:
1717
setup:
1818
name: Setup
19-
runs-on: ubuntu-22.04
19+
runs-on: ubuntu-24.04
2020
permissions:
2121
contents: read
2222
outputs:
2323
release_version: ${{ steps.version.outputs.version }}
24-
branch-name: ${{ steps.branch.outputs.branch-name }}
25-
2624
steps:
2725
- name: Check branch
2826
if: ${{ inputs.release_type != 'Dry Run' }}
@@ -54,7 +52,7 @@ jobs:
5452
release-github:
5553
name: Create GitHub Release
5654
if: ${{ inputs.release_type != 'Dry Run' }}
57-
runs-on: ubuntu-22.04
55+
runs-on: ubuntu-24.04
5856
needs: setup
5957
permissions:
6058
contents: write
@@ -72,7 +70,7 @@ jobs:
7270
check-failures:
7371
name: Check for failures
7472
if: always()
75-
runs-on: ubuntu-22.04
73+
runs-on: ubuntu-24.04
7674
needs:
7775
- release-github
7876
- setup

.github/workflows/scan.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ on:
1414
branches:
1515
- main
1616

17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
1721
permissions: {}
1822

1923
jobs:

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ on:
77
- "main"
88
pull_request:
99

10-
jobs:
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
1113

14+
jobs:
1215
testing:
1316
name: Run tests
1417
if: ${{ startsWith(github.head_ref, 'version_bump_') == false }}
15-
runs-on: ubuntu-22.04
18+
runs-on: ubuntu-24.04
1619
permissions:
1720
checks: write
1821
contents: read

0 commit comments

Comments
 (0)