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