Repository navigation
158 lines (143 loc) · 6.05 KB
/
Copy pathdatabase-cluster-release.yml
File metadata and controls
158 lines (143 loc) · 6.05 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
name: Build Database Replication Images
on:
pull_request:
paths:
- 'database-ha/**'
- 'checks/check-*-cluster.sh'
- '.github/workflows/database-cluster-release.yml'
workflow_dispatch:
inputs:
database:
description: 'Database'
type: choice
options: [all, mysql, postgresql, redis]
default: all
version:
description: 'Supported series (e.g. 8.4, 18, 8.10); builds the full version from versions.json'
default: all
publish:
description: 'Publish to Docker Hub after both architectures pass'
type: boolean
default: false
permissions:
contents: read
concurrency:
group: database-cluster-${{ github.event_name == 'workflow_dispatch' && inputs.publish && 'publish' || github.run_id }}
cancel-in-progress: false
jobs:
prepare:
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
images: ${{ steps.matrix.outputs.images }}
steps:
- uses: actions/checkout@v5
- name: Prepare supported versions
id: matrix
env:
DATABASE: ${{ inputs.database || 'all' }}
VERSION: ${{ inputs.version || 'all' }}
run: |
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
import os
import re
from pathlib import Path
selected = os.environ['DATABASE']
series_filter = os.environ['VERSION']
versions = json.loads(Path('database-ha/versions.json').read_text())
arguments = {'mysql': 'MYSQL_VERSION', 'postgresql': 'POSTGRESQL_VERSION', 'redis': 'REDIS_VERSION'}
if selected != 'all' and selected not in versions:
raise SystemExit('Unsupported database')
if selected == 'all' and series_filter != 'all':
raise SystemExit('Select a database when selecting one version series')
builds, images = [], []
for name, supported in versions.items():
if name not in arguments:
raise SystemExit(f'Unsupported database in versions.json: {name}')
if selected not in ('all', name):
continue
if series_filter != 'all' and series_filter not in supported:
raise SystemExit(f'Unsupported {name} series: {series_filter}')
for series, version in supported.items():
if not re.fullmatch(r'[0-9]+(?:\.[0-9]+)*', series) or not re.fullmatch(re.escape(series) + r'\.[0-9]+', version):
raise SystemExit(f'Invalid {name} version mapping: {series} -> {version}')
if series_filter not in ('all', series):
continue
build_args = f'{arguments[name]}={version}'
if name == 'redis':
variant = 'trixie' if series == '8.10' else 'bookworm'
build_args += f'\nREDIS_VARIANT={variant}'
image = f'1panel/{name}-cluster:{version}'
images.append({'image': image, 'series_image': f'1panel/{name}-cluster:{series}'})
for architecture, runner in [('amd64', 'ubuntu-24.04'), ('arm64', 'ubuntu-24.04-arm')]:
builds.append({
'database': name,
'build_args': build_args,
'version': version,
'series': series,
'architecture': architecture,
'runner': runner,
'image': f'{image}-{architecture}',
})
print('matrix=' + json.dumps({'include': builds}))
print('images=' + json.dumps({'include': images}))
PY
build:
needs: prepare
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v5
- uses: docker/setup-buildx-action@v3
- name: Build native image
uses: docker/build-push-action@v6
with:
context: database-ha/${{ matrix.database }}
platforms: linux/${{ matrix.architecture }}
load: true
pull: true
build-args: ${{ matrix.build_args }}
tags: ${{ matrix.image }}
labels: |
org.opencontainers.image.source=https://github.com/1Panel-dev/containers
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ matrix.version }}
cache-from: type=gha,scope=${{ matrix.database }}-${{ matrix.series }}-${{ matrix.architecture }}
cache-to: type=gha,scope=${{ matrix.database }}-${{ matrix.series }}-${{ matrix.architecture }},mode=max
- name: Check replication and persistence
env:
DATABASE: ${{ matrix.database }}
IMAGE: ${{ matrix.image }}
run: bash "checks/check-${DATABASE}-cluster.sh" "$IMAGE"
- name: Login to Docker Hub
if: github.event_name == 'workflow_dispatch' && inputs.publish
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push verified architecture
if: github.event_name == 'workflow_dispatch' && inputs.publish
env:
IMAGE: ${{ matrix.image }}
run: docker push "$IMAGE"
publish:
if: github.event_name == 'workflow_dispatch' && inputs.publish
needs: [prepare, build]
strategy:
matrix: ${{ fromJSON(needs.prepare.outputs.images) }}
runs-on: ubuntu-24.04
steps:
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Publish multi-platform manifest
env:
IMAGE: ${{ matrix.image }}
SERIES_IMAGE: ${{ matrix.series_image }}
run: docker buildx imagetools create --tag "$IMAGE" --tag "$SERIES_IMAGE" "${IMAGE}-amd64" "${IMAGE}-arm64"