Skip to content

Commit 0df17b1

Browse files
committed
SCF-788: Added build & push workflow, on scalefield_v* pattern
1 parent 421bd6d commit 0df17b1

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: Build and Push Docker Images to Harbor
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
- 'docs/**'
8+
branches:
9+
- 'scalefield_v*'
10+
workflow_dispatch:
11+
inputs:
12+
image_tags:
13+
description: 'Comma-separated list of tags'
14+
required: true
15+
type: string
16+
run_e2e_tests:
17+
description: 'Run E2E tests'
18+
required: false
19+
type: boolean
20+
default: true
21+
push_image:
22+
description: 'Push images to Harbor'
23+
required: false
24+
type: boolean
25+
default: true
26+
27+
concurrency:
28+
group: ${{ github.ref }}
29+
cancel-in-progress: true
30+
31+
jobs:
32+
e2e-tests:
33+
name: Run E2E Tests
34+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.run_e2e_tests)
35+
uses: ./.github/workflows/run_e2e.yaml
36+
37+
build-and-push:
38+
name: Build and Push Docker Images to Harbor
39+
needs: [e2e-tests]
40+
if: always() && (needs.e2e-tests.result == 'success' || needs.e2e-tests.result == 'skipped')
41+
runs-on: ubuntu-latest-m
42+
env:
43+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
44+
steps:
45+
- name: Checkout Repository
46+
uses: actions/checkout@v4
47+
48+
- name: Determine tags
49+
id: tags
50+
run: |
51+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
52+
echo "tags=${{ inputs.image_tags }}" >> $GITHUB_OUTPUT
53+
else
54+
FULL_SHA="${{ github.sha }}"
55+
SHORT_SHA="${FULL_SHA:0:7}"
56+
echo "tags=${FULL_SHA},${SHORT_SHA}" >> $GITHUB_OUTPUT
57+
fi
58+
59+
- name: Generate Harbor tags
60+
id: harbor_tags
61+
run: |
62+
{
63+
echo "operator_tags<<EOF"
64+
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}"
65+
for tag in "${TAG_ARRAY[@]}"; do
66+
echo "${{ vars.HARBOR_ORG }}/scalefield/postgres-operator:${tag}"
67+
done
68+
echo "EOF"
69+
} >> "$GITHUB_OUTPUT"
70+
{
71+
echo "logical_backup_tags<<EOF"
72+
IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}"
73+
for tag in "${TAG_ARRAY[@]}"; do
74+
echo "${{ vars.HARBOR_ORG }}/scalefield/postgres-operator/logical-backup:${tag}"
75+
done
76+
echo "EOF"
77+
} >> "$GITHUB_OUTPUT"
78+
79+
- name: Debug tags
80+
run: |
81+
echo "::group::Operator Image Tags"
82+
echo "${{ steps.harbor_tags.outputs.operator_tags }}"
83+
echo "::endgroup::"
84+
echo "::group::Logical Backup Image Tags"
85+
echo "${{ steps.harbor_tags.outputs.logical_backup_tags }}"
86+
echo "::endgroup::"
87+
88+
- name: Set up QEMU
89+
uses: docker/setup-qemu-action@v3
90+
91+
- name: Set up Docker Buildx
92+
uses: docker/setup-buildx-action@v4.0.0
93+
94+
- name: Log in to Harbor
95+
uses: docker/login-action@v4
96+
with:
97+
registry: ${{ vars.HARBOR_ORG }}
98+
username: ${{ vars.HARBOR_USERNAME }}
99+
password: ${{ secrets.HARBOR_PASSWORD }}
100+
101+
- name: Build and push operator image
102+
id: build_operator
103+
uses: docker/build-push-action@v7
104+
continue-on-error: true
105+
with:
106+
context: .
107+
file: docker/Dockerfile
108+
platforms: linux/amd64,linux/arm64
109+
push: ${{ github.event_name != 'workflow_dispatch' || inputs.push_image }}
110+
tags: ${{ steps.harbor_tags.outputs.operator_tags }}
111+
cache-from: type=gha
112+
cache-to: type=gha,mode=max
113+
114+
- name: Notify Slack on operator build failure
115+
if: steps.build_operator.outcome == 'failure'
116+
uses: rtCamp/action-slack-notify@master
117+
env:
118+
SLACK_USERNAME: 'GitHub Actions'
119+
SLACK_ICON_EMOJI: ':x:'
120+
SLACK_COLOR: '#FF0000'
121+
SLACK_TITLE: 'Postgres Operator image build failed'
122+
SLACK_MESSAGE: 'Failed to build `postgres-operator` image with tags `${{ steps.tags.outputs.tags }}`. Please check the workflow logs for details.'
123+
124+
- name: Build and push logical-backup image
125+
id: build_logical_backup
126+
uses: docker/build-push-action@v7
127+
continue-on-error: true
128+
with:
129+
context: logical-backup
130+
platforms: linux/amd64,linux/arm64
131+
push: ${{ github.event_name != 'workflow_dispatch' || inputs.push_image }}
132+
tags: ${{ steps.harbor_tags.outputs.logical_backup_tags }}
133+
cache-from: type=gha
134+
cache-to: type=gha,mode=max
135+
136+
- name: Notify Slack on logical-backup build failure
137+
if: steps.build_logical_backup.outcome == 'failure'
138+
uses: rtCamp/action-slack-notify@master
139+
env:
140+
SLACK_USERNAME: 'GitHub Actions'
141+
SLACK_ICON_EMOJI: ':x:'
142+
SLACK_COLOR: '#FF0000'
143+
SLACK_TITLE: 'Logical-backup image build failed'
144+
SLACK_MESSAGE: 'Failed to build `postgres-operator/logical-backup` image with tags `${{ steps.tags.outputs.tags }}`. Please check the workflow logs for details.'
145+
146+
- name: Check for build failures
147+
if: steps.build_operator.outcome == 'failure' || steps.build_logical_backup.outcome == 'failure'
148+
run: exit 1
149+
150+
- name: Notify Slack - Success
151+
if: success()
152+
uses: rtCamp/action-slack-notify@master
153+
env:
154+
SLACK_USERNAME: 'GitHub Actions'
155+
SLACK_ICON_EMOJI: ':rocket:'
156+
SLACK_COLOR: '#3278BD'
157+
SLACK_TITLE: 'Images deployed to Harbor'
158+
SLACK_MESSAGE: |
159+
Postgres Operator images pushed with tags `${{ steps.tags.outputs.tags }}`.
160+
Operator: ${{ vars.HARBOR_ORG }}/scalefield/postgres-operator
161+
Logical-backup: ${{ vars.HARBOR_ORG }}/scalefield/postgres-operator/logical-backup
162+
Harbor: https://containers.cybertec.at/harbor/projects/3/repositories/postgres-operator/artifacts-tab
163+

0 commit comments

Comments
 (0)