-
-
Notifications
You must be signed in to change notification settings - Fork 146
237 lines (225 loc) · 8.55 KB
/
dockerhub-release-matrix.yml
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: Release all major versions on Dockerhub
on:
push:
branches:
- develop
- release/*
- sam/docker-oriole17
paths:
- '**'
workflow_dispatch:
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix_config: ${{ steps.set-matrix.outputs.matrix_config }}
steps:
- uses: DeterminateSystems/nix-installer-action@main
- name: Checkout Repo
uses: actions/checkout@v3
- name: Generate build matrix
id: set-matrix
run: |
nix run nixpkgs#nushell -- -c 'let versions = (open ansible/vars.yml | get postgres_major)
let matrix = ($versions | each { |ver|
let version = ($ver | str trim)
let dockerfile = $"Dockerfile-($version)"
if ($dockerfile | path exists) {
{
version: $version,
dockerfile: $dockerfile
}
} else {
null
}
} | compact)
let matrix_config = {
include: $matrix
}
$"matrix_config=($matrix_config | to json -r)" | save --append $env.GITHUB_OUTPUT'
build:
needs: prepare
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.matrix_config) }}
runs-on: ubuntu-latest
outputs:
build_args: ${{ steps.args.outputs.result }}
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- name: Set PostgreSQL version environment variable
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.version }}" >> $GITHUB_ENV
- id: args
run: |
nix run nixpkgs#nushell -- -c '
open ansible/vars.yml
| items { |key value| {name: $key, item: $value} }
| where { |it| ($it.item | describe) == "string" }
| each { |it| $"($it.name)=($it.item)" }
| str join "\n"
| save --append $env.GITHUB_OUTPUT
'
build_release_image:
needs: [prepare, build]
strategy:
matrix:
postgres: ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
arch: [amd64, arm64]
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'arm-runner' }}
timeout-minutes: 180
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- run: docker context create builders
- uses: docker/setup-buildx-action@v3
with:
endpoint: builders
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get image tag
id: image
run: |
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
pg_version=$(sudo nix run nixpkgs#nushell -- -c '
let version = "${{ matrix.postgres.version }}"
let release_key = if ($version | str contains "orioledb") {
$"postgresorioledb-17"
} else {
$"postgres($version)"
}
open ansible/vars.yml | get postgres_release | get $release_key | str trim
')
echo "pg_version=supabase/postgres:$pg_version" >> $GITHUB_OUTPUT
else
pg_version=$(nix run nixpkgs#nushell -- -c '
let version = "${{ matrix.postgres.version }}"
let release_key = if ($version | str contains "orioledb") {
$"postgresorioledb-17"
} else {
$"postgres($version)"
}
open ansible/vars.yml | get postgres_release | get $release_key | str trim
')
echo "pg_version=supabase/postgres:$pg_version" >> $GITHUB_OUTPUT
fi
- id: build
uses: docker/build-push-action@v5
with:
push: true
build-args: |
${{ needs.build.outputs.build_args }}
target: production
tags: ${{ steps.image.outputs.pg_version }}_${{ matrix.arch }}
platforms: linux/${{ matrix.arch }}
cache-from: type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
file: ${{ matrix.postgres.dockerfile }}
merge_manifest:
needs: [prepare, build, build_release_image]
strategy:
matrix:
include: ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get image tag
id: get_version
run: |
nix run nixpkgs#nushell -- -c '
let version = "${{ matrix.version }}"
let release_key = if ($version | str contains "orioledb") {
$"postgresorioledb-17"
} else {
$"postgres($version)"
}
let pg_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
$"pg_version=supabase/postgres:($pg_version)" | save --append $env.GITHUB_OUTPUT
'
- name: Output version
id: output_version
run: |
echo "result=${{ steps.get_version.outputs.pg_version }}" >> $GITHUB_OUTPUT
- name: Collect versions
id: collect_versions
run: |
echo "${{ steps.output_version.outputs.result }}" >> results.txt # Append results
- name: Upload Results Artifact
uses: actions/upload-artifact@v3
with:
name: merge_results-${{ matrix.version }}
path: results.txt
if-no-files-found: warn
- name: Merge multi-arch manifests
run: |
docker buildx imagetools create -t ${{ steps.get_version.outputs.pg_version }} \
${{ steps.get_version.outputs.pg_version }}_amd64 \
${{ steps.get_version.outputs.pg_version }}_arm64
combine_results:
needs: [prepare, merge_manifest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- name: Debug Input from Prepare
run: |
echo "Raw matrix_config output:"
echo "${{ needs.prepare.outputs.matrix_config }}"
- name: Get Versions from Matrix Config
id: get_versions
run: |
nix run nixpkgs#nushell -- -c '
# Parse the matrix configuration directly
let matrix_config = (${{ toJson(needs.prepare.outputs.matrix_config) }} | from json)
# Get versions directly from include array
let versions = ($matrix_config.include | get version)
echo "Versions: $versions"
# Convert the versions to a comma-separated string
let versions_str = ($versions | str join ",")
$"versions=$versions_str" | save --append $env.GITHUB_ENV
'
- name: Download Results Artifacts
uses: actions/download-artifact@v3
with:
pattern: merge_results-*
- name: Combine Results
id: combine
run: |
nix run nixpkgs#nushell -- -c '
# Get all results files and process them in one go
let files = (ls **/results.txt | get name)
echo $"Found files: ($files)"
let matrix = {
include: (
$files
| each { |file| open $file } # Open each file
| each { |content| $content | lines } # Split into lines
| flatten # Flatten the nested lists
| where { |line| $line != "" } # Filter empty lines
| each { |line| {version: $line} } # Create objects
)
}
let json_output = ($matrix | to json -r) # -r for raw output
echo $"Debug output: ($json_output)"
$"matrix=($json_output)" | save --append $env.GITHUB_OUTPUT
'
- name: Debug Combined Results
run: |
echo "Combined Results: '${{ steps.combine.outputs.matrix }}'"
outputs:
matrix: ${{ steps.combine.outputs.matrix }}
publish:
needs: combine_results
strategy:
matrix: ${{ fromJson(needs.combine_results.outputs.matrix) }}
uses: ./.github/workflows/mirror.yml
with:
version: ${{ matrix.version }}
secrets: inherit