Skip to content

Commit c299296

Browse files
authored
[BRE-1137] Polishing Release Process (#106)
1 parent 75c6585 commit c299296

File tree

6 files changed

+172
-300
lines changed

6 files changed

+172
-300
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
#
55
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
66

7+
# Default owners
8+
* @bitwarden/team-secrets-manager-dev
9+
710
# Workflows ownership
8-
.github/workflows/build_ghcr.yml @bitwarden/dept-bre
9-
.github/workflows/build.yml @bitwarden/dept-bre
10-
.github/workflows/bump_version.yml @bitwarden/dept-bre
11-
.github/workflows/release.yml @bitwarden/dept-bre
1211
.github/workflows/release.yml @bitwarden/dept-bre
1312

1413
## Dockerfile shared ownership

.github/workflows/build-ghcr.yml

Lines changed: 0 additions & 108 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 101 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
1-
name: Build
1+
name: Build and test
22

33
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
48
workflow_dispatch:
9+
inputs:
10+
push_image:
11+
description: "Push image to GitHub Container Registry (Always true on main)"
12+
required: false
13+
default: false
14+
type: boolean
15+
16+
env:
17+
_PUSH_IMAGE: ${{ (inputs.push_image == true || github.ref == 'refs/heads/main') && 'true' || 'false' }}
518

619
jobs:
7-
build-docker:
8-
name: Build Docker images
9-
runs-on: ubuntu-22.04
20+
build-and-test:
21+
name: Build image and test
22+
runs-on: ubuntu-24.04
1023
permissions:
1124
contents: read
25+
packages: write
26+
security-events: write
1227
id-token: write
1328
env:
14-
_AZ_REGISTRY: bitwardenprod.azurecr.io
15-
_PROJECT_NAME: sm-operator
29+
_IMAGE_NAME: ghcr.io/bitwarden/sm-operator
1630

1731
steps:
1832
- name: Check out repo
1933
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
34+
with:
35+
persist-credentials: false
2036

2137
- name: Set up QEMU
22-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
38+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
2339

2440
- name: Set up Docker Buildx
2541
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
2642

27-
- name: Log in to Azure
28-
uses: bitwarden/gh-actions/azure-login@main
43+
- name: Log in to GitHub Container Registry
44+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
2945
with:
30-
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
31-
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
32-
client_id: ${{ secrets.AZURE_CLIENT_ID }}
33-
34-
- name: Log in to ACR
35-
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}
46+
registry: ghcr.io
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
3649

3750
- name: Test operator
3851
id: test
@@ -42,45 +55,95 @@ jobs:
4255
make test
4356
4457
- name: Upload to codecov.io
45-
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
58+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
4659

4760
- name: Generate Docker image tag
4861
id: tag
62+
env:
63+
EVENT_TYPE: ${{ contains(github.event_name, 'pull_request') && 'pull_request' || '' }}
4964
run: |
50-
IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name
51-
if [[ "$IMAGE_TAG" == "main" ]]; then
52-
IMAGE_TAG=dev
65+
if [[ "$EVENT_TYPE" == "pull_request" ]]; then
66+
IMAGE_TAG="pr-${{ github.event.pull_request.number }}"
67+
else
68+
ref="${GITHUB_REF:11}"
69+
IMAGE_TAG="${ref//\//-}"
70+
71+
if [[ "${IMAGE_TAG}" == "main" ]]; then
72+
IMAGE_TAG="dev"
73+
fi
5374
fi
54-
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
75+
echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
5576
56-
- name: Generate image full name
57-
id: image-name
77+
- name: Generate image tag(s)
78+
id: image-tags
5879
env:
5980
IMAGE_TAG: ${{ steps.tag.outputs.image_tag }}
60-
run: echo "name=${_AZ_REGISTRY}/${_PROJECT_NAME}:${IMAGE_TAG}" >> $GITHUB_OUTPUT
81+
SHA: ${{ github.sha }}
82+
run: |
83+
TAGS="$_IMAGE_NAME:$IMAGE_TAG"
84+
echo "primary_tag=$TAGS" >> "$GITHUB_OUTPUT"
85+
if [[ "$IMAGE_TAG" == "dev" ]]; then
86+
SHORT_SHA="$(git rev-parse --short "${SHA}")"
87+
TAGS="$TAGS,$TAGS-${SHORT_SHA}"
88+
fi
89+
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
6190
6291
- name: Build Docker image
63-
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
92+
id: build-docker
93+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
6494
with:
6595
file: Dockerfile
66-
platforms: linux/amd64,linux/arm64
67-
push: true
68-
tags: ${{ steps.image-name.outputs.name }}
96+
platforms: ${{ env._PUSH_IMAGE == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }} # Can only do single arch when not pushing to support scan and testing locally
97+
push: ${{ env._PUSH_IMAGE == 'true' }}
98+
load: ${{ env._PUSH_IMAGE != 'true' }}
99+
tags: ${{ steps.image-tags.outputs.tags }}
100+
101+
- name: Install Cosign
102+
if: ${{ env._PUSH_IMAGE == 'true' }}
103+
uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0
104+
105+
- name: Sign image with Cosign
106+
if: ${{ env._PUSH_IMAGE == 'true' }}
107+
id: cosign
108+
env:
109+
DIGEST: ${{ steps.build-docker.outputs.digest }}
110+
TAGS: ${{ steps.image-tags.outputs.tags }}
111+
run: |
112+
IFS="," read -a tags <<< "${TAGS}"
113+
images=""
114+
for tag in "${tags[@]}"; do
115+
images+="${tag}@${DIGEST} "
116+
done
117+
cosign sign --yes "${images}"
118+
echo "images=${images}" >> "$GITHUB_OUTPUT"
119+
120+
- name: Verify the signed image with Cosign
121+
if: ${{ env._PUSH_IMAGE == 'true' }}
122+
env:
123+
GITHUB_SERVER_URL: "${{ github.server_url }}"
124+
REF: "${{ github.workflow_ref }}"
125+
IMAGES: "${{ steps.cosign.outputs.images }}"
126+
run: |
127+
cosign verify \
128+
--certificate-identity "$GITHUB_SERVER_URL/$REF" \
129+
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
130+
"$IMAGES"
69131
70132
- name: Create kind cluster
71-
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
133+
uses: helm/kind-action@a1b0e391336a6ee6713a0583f8c6240d70863de3 # v1.12.0
134+
135+
- name: Load image into kind
136+
if: ${{ env._PUSH_IMAGE != 'true' }}
137+
env:
138+
IMAGE: ${{ steps.image-tags.outputs.primary_tag }}
139+
run: kind load docker-image "$IMAGE" --name "$(kind get clusters)"
72140

73141
- name: Smoke test image
74142
id: smoke-test
75143
env:
76-
IMAGE: ${{ steps.image-name.outputs.name }}
144+
IMAGE: ${{ steps.image-tags.outputs.primary_tag }}
77145
run: |
78-
make deploy IMG=$IMAGE
79-
80-
#Setup image pull secret (Until repo is made public)
81-
kubectl create secret -n sm-operator-system docker-registry ghcr-login-secret --docker-server=ghcr.io --docker-username=bitwarden-devops-bot --docker-password=${{ secrets.GITHUB_TOKEN }} --docker-email=106330231+bitwarden-devops-bot@users.noreply.github.com
82-
83-
kubectl patch deployment sm-operator-controller-manager -n sm-operator-system --patch-file "$GITHUB_WORKSPACE/.github/workflows/test_files/deployment-patch.yaml"
146+
make deploy IMG="$IMAGE"
84147
85148
count=0
86149
while [[ $(kubectl get pods -n sm-operator-system -l control-plane=controller-manager -o jsonpath="{.items[*].status.containerStatuses[*].ready}") != "true" ]]; do
@@ -97,7 +160,7 @@ jobs:
97160
98161
echo "*****PODS*****"
99162
pods=$(kubectl get pods -n sm-operator-system -l control-plane=controller-manager | grep 2/2)
100-
echo $pods
163+
echo "$pods"
101164
102165
if [[ -z "$pods" ]]; then
103166
echo "::error::No pods found."
@@ -111,5 +174,5 @@ jobs:
111174
make undeploy
112175
kind delete cluster
113176
114-
- name: Log out from Azure
115-
uses: bitwarden/gh-actions/azure-logout@main
177+
- name: Log out of Docker
178+
run: docker logout ghcr.io

0 commit comments

Comments
 (0)