Skip to content

Commit f950a06

Browse files
committed
Add workflows for building and promoting security images
- Introduced `build-security-image.yaml` to automate the building of security Docker images on pushes to branches prefixed with 'secure/'. - Added `promote-security-image.yaml` to extract image tags from pull request titles and promote images to GCP Artifact Registry upon approval of pull requests targeting 'master' or 'main' from 'secure/' branches.
1 parent f5e74e8 commit f950a06

3 files changed

Lines changed: 91 additions & 1 deletion

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build Security Image
2+
3+
on:
4+
push:
5+
branches:
6+
- 'secure/*'
7+
create:
8+
9+
jobs:
10+
variables-setup:
11+
name: Setting variables for docker build
12+
runs-on: ubuntu-latest
13+
if: >-
14+
github.event_name == 'push' ||
15+
(
16+
github.event_name == 'create' &&
17+
github.event.ref_type == 'branch' &&
18+
startsWith(github.ref_name, 'secure/')
19+
)
20+
steps:
21+
- name: Create variables
22+
id: vars
23+
run: |
24+
echo "image-tag=$(echo '${{ github.ref_name }}' | sed 's|secure/||')" >> $GITHUB_OUTPUT
25+
echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
26+
outputs:
27+
image-tag: ${{ steps.vars.outputs.image-tag }}
28+
date: ${{ steps.vars.outputs.date }}
29+
30+
build-security-image:
31+
name: Build security Docker image
32+
needs: variables-setup
33+
uses: reportportal/.github/.github/workflows/build-docker-image.yaml@main
34+
with:
35+
aws-region: ${{ vars.AWS_REGION }}
36+
build-platforms: ${{ vars.BUILD_PLATFORMS || 'linux/amd64,linux/arm64' }}
37+
image-tag: ${{ needs.variables-setup.outputs.image-tag }}
38+
release-mode: false
39+
additional-tag: 'secure-latest'
40+
date: ${{ needs.variables-setup.outputs.date }}
41+
runs-on: ubuntu-latest
42+
secrets: inherit

.github/workflows/dockerhub-release.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ jobs:
1717
name: Retag and push image
1818
runs-on: ubuntu-latest
1919
environment: rc
20-
if: github.event.review.state == 'approved' && (github.event.pull_request.base.ref == 'master' || github.event.pull_request.base.ref == 'main')
20+
if: >
21+
github.event.review.state == 'approved' &&
22+
(github.event.pull_request.base.ref == 'master' || github.event.pull_request.base.ref == 'main') &&
23+
(startsWith(github.event.pull_request.head.ref, 'rc/') || startsWith(github.event.pull_request.head.ref, 'hotfix/'))
2124
steps:
2225
- name: Checkout
2326
uses: actions/checkout@v3
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Promote Security Image
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
7+
jobs:
8+
extract-image-tag:
9+
name: Extract image tag from PR title
10+
if: >-
11+
github.event.review.state == 'approved' &&
12+
startsWith(github.event.pull_request.head.ref, 'secure/') &&
13+
(github.event.pull_request.base.ref == 'master' || github.event.pull_request.base.ref == 'main')
14+
runs-on: ubuntu-latest
15+
outputs:
16+
image-tag: ${{ steps.extract.outputs.image-tag }}
17+
steps:
18+
- name: Extract image tag from PR title
19+
id: extract
20+
env:
21+
PR_TITLE: ${{ github.event.pull_request.title }}
22+
run: |
23+
NORM=$(echo "${PR_TITLE}" | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+)[[:space:]]+[rR]([0-9]+)/\1-r\2/g')
24+
IMAGE_TAG=$(echo "${NORM}" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+-r[0-9]+' | tail -1)
25+
if [ -z "${IMAGE_TAG}" ]; then
26+
echo "::error::Could not extract a version tag (x.x.x-rN or x.x.x rN) from PR title: '${PR_TITLE}'"
27+
exit 1
28+
fi
29+
echo "image-tag=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
30+
echo "Extracted image tag: ${IMAGE_TAG}"
31+
32+
promote-to-gcr:
33+
name: Promote ${{ github.event.repository.name }} to GCP Artifact Registry
34+
needs: extract-image-tag
35+
uses: reportportal/.github/.github/workflows/promote-ecr-to-gcr.yaml@main
36+
with:
37+
service: ${{ github.event.repository.name }}
38+
image-tag: ${{ needs.extract-image-tag.outputs.image-tag }}
39+
aws-region: ${{ vars.AWS_REGION }}
40+
secrets:
41+
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
42+
GCP_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
43+
GCP_SERVICE_ACCOUNT: ${{ secrets.GCP_SERVICE_ACCOUNT }}
44+
GCR_REGION: ${{ secrets.GCR_REGION }}
45+
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}

0 commit comments

Comments
 (0)