Skip to content

Commit 45e80ac

Browse files
authored
chore: create a workflow_dispatch only method with input, for docker … (#1440)
* chore: create a workflow_dispatch only method with input, for docker release * chore: move file to correct dir
1 parent 3cd81a2 commit 45e80ac

File tree

1 file changed

+250
-0
lines changed

1 file changed

+250
-0
lines changed
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
name: Manual Docker Artifacts Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
postgresVersion:
7+
description: 'Optional. Postgres version to publish against, i.e. 15.1.1.78'
8+
required: false
9+
10+
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
matrix_config: ${{ steps.set-matrix.outputs.matrix_config }}
15+
steps:
16+
- uses: DeterminateSystems/nix-installer-action@main
17+
- name: Checkout Repo
18+
uses: actions/checkout@v3
19+
- name: Generate build matrix
20+
id: set-matrix
21+
run: |
22+
nix run nixpkgs#nushell -- -c 'let versions = (open ansible/vars.yml | get postgres_major)
23+
let matrix = ($versions | each { |ver|
24+
let version = ($ver | str trim)
25+
let dockerfile = $"Dockerfile-($version)"
26+
if ($dockerfile | path exists) {
27+
{
28+
version: $version,
29+
dockerfile: $dockerfile
30+
}
31+
} else {
32+
null
33+
}
34+
} | compact)
35+
36+
let matrix_config = {
37+
include: $matrix
38+
}
39+
40+
$"matrix_config=($matrix_config | to json -r)" | save --append $env.GITHUB_OUTPUT'
41+
build:
42+
needs: prepare
43+
strategy:
44+
matrix: ${{ fromJson(needs.prepare.outputs.matrix_config) }}
45+
runs-on: ubuntu-latest
46+
outputs:
47+
build_args: ${{ steps.args.outputs.result }}
48+
steps:
49+
- uses: actions/checkout@v3
50+
- uses: DeterminateSystems/nix-installer-action@main
51+
- name: Set PostgreSQL version environment variable
52+
run: echo "POSTGRES_MAJOR_VERSION=${{ matrix.version }}" >> $GITHUB_ENV
53+
54+
- id: args
55+
run: |
56+
nix run nixpkgs#nushell -- -c '
57+
open ansible/vars.yml
58+
| items { |key value| {name: $key, item: $value} }
59+
| where { |it| ($it.item | describe) == "string" }
60+
| each { |it| $"($it.name)=($it.item)" }
61+
| str join "\n"
62+
| save --append $env.GITHUB_OUTPUT
63+
'
64+
build_release_image:
65+
needs: [prepare, build]
66+
strategy:
67+
matrix:
68+
postgres: ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
69+
arch: [amd64, arm64]
70+
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'arm-runner' }}
71+
timeout-minutes: 180
72+
steps:
73+
- uses: actions/checkout@v3
74+
- uses: DeterminateSystems/nix-installer-action@main
75+
- run: docker context create builders
76+
- uses: docker/setup-buildx-action@v3
77+
with:
78+
endpoint: builders
79+
- uses: docker/login-action@v2
80+
with:
81+
username: ${{ secrets.DOCKER_USERNAME }}
82+
password: ${{ secrets.DOCKER_PASSWORD }}
83+
- name: Get image tag
84+
id: image
85+
run: |
86+
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
87+
pg_version=$(sudo nix run nixpkgs#nushell -- -c '
88+
let version = "${{ matrix.postgres.version }}"
89+
let release_key = if ($version | str contains "orioledb") {
90+
$"postgresorioledb-17"
91+
} else {
92+
$"postgres($version)"
93+
}
94+
let base_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
95+
let final_version = if "${{ inputs.postgresVersion }}" != "" {
96+
"${{ inputs.postgresVersion }}"
97+
} else {
98+
$base_version
99+
}
100+
$final_version | str trim
101+
')
102+
echo "pg_version=supabase/postgres:$pg_version" >> $GITHUB_OUTPUT
103+
else
104+
pg_version=$(nix run nixpkgs#nushell -- -c '
105+
let version = "${{ matrix.postgres.version }}"
106+
let release_key = if ($version | str contains "orioledb") {
107+
$"postgresorioledb-17"
108+
} else {
109+
$"postgres($version)"
110+
}
111+
let base_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
112+
let final_version = if "${{ inputs.postgresVersion }}" != "" {
113+
"${{ inputs.postgresVersion }}"
114+
} else {
115+
$base_version
116+
}
117+
$final_version | str trim
118+
')
119+
echo "pg_version=supabase/postgres:$pg_version" >> $GITHUB_OUTPUT
120+
fi
121+
- id: build
122+
uses: docker/build-push-action@v5
123+
with:
124+
push: true
125+
build-args: |
126+
${{ needs.build.outputs.build_args }}
127+
target: production
128+
tags: ${{ steps.image.outputs.pg_version }}_${{ matrix.arch }}
129+
platforms: linux/${{ matrix.arch }}
130+
cache-from: type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
131+
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
132+
file: ${{ matrix.postgres.dockerfile }}
133+
merge_manifest:
134+
needs: [prepare, build, build_release_image]
135+
strategy:
136+
matrix:
137+
include: ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
138+
runs-on: ubuntu-latest
139+
steps:
140+
- uses: actions/checkout@v3
141+
- uses: DeterminateSystems/nix-installer-action@main
142+
- uses: docker/setup-buildx-action@v3
143+
- uses: docker/login-action@v2
144+
with:
145+
username: ${{ secrets.DOCKER_USERNAME }}
146+
password: ${{ secrets.DOCKER_PASSWORD }}
147+
- name: Get image tag
148+
id: get_version
149+
run: |
150+
nix run nixpkgs#nushell -- -c '
151+
let version = "${{ matrix.version }}"
152+
let release_key = if ($version | str contains "orioledb") {
153+
$"postgresorioledb-17"
154+
} else {
155+
$"postgres($version)"
156+
}
157+
let pg_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
158+
$"pg_version=supabase/postgres:($pg_version)" | save --append $env.GITHUB_OUTPUT
159+
'
160+
- name: Output version
161+
id: output_version
162+
run: |
163+
echo "result=${{ steps.get_version.outputs.pg_version }}" >> $GITHUB_OUTPUT
164+
- name: Collect versions
165+
id: collect_versions
166+
run: |
167+
echo "${{ steps.output_version.outputs.result }}" >> results.txt # Append results
168+
- name: Upload Results Artifact
169+
uses: actions/upload-artifact@v4
170+
with:
171+
name: merge_results-${{ matrix.version }}
172+
path: results.txt
173+
if-no-files-found: warn
174+
- name: Merge multi-arch manifests
175+
run: |
176+
docker buildx imagetools create -t ${{ steps.get_version.outputs.pg_version }} \
177+
${{ steps.get_version.outputs.pg_version }}_amd64 \
178+
${{ steps.get_version.outputs.pg_version }}_arm64
179+
combine_results:
180+
needs: [prepare, merge_manifest]
181+
runs-on: ubuntu-latest
182+
steps:
183+
- uses: actions/checkout@v3
184+
- uses: DeterminateSystems/nix-installer-action@main
185+
186+
- name: Debug Input from Prepare
187+
run: |
188+
echo "Raw matrix_config output:"
189+
echo "${{ needs.prepare.outputs.matrix_config }}"
190+
- name: Get Versions from Matrix Config
191+
id: get_versions
192+
run: |
193+
nix run nixpkgs#nushell -- -c '
194+
# Parse the matrix configuration directly
195+
let matrix_config = (${{ toJson(needs.prepare.outputs.matrix_config) }} | from json)
196+
197+
# Get versions directly from include array
198+
let versions = ($matrix_config.include | get version)
199+
200+
echo "Versions: $versions"
201+
202+
# Convert the versions to a comma-separated string
203+
let versions_str = ($versions | str join ",")
204+
$"versions=$versions_str" | save --append $env.GITHUB_ENV
205+
'
206+
- name: Download Results Artifacts
207+
uses: actions/download-artifact@v4
208+
with:
209+
pattern: merge_results-*
210+
- name: Combine Results
211+
id: combine
212+
run: |
213+
nix run nixpkgs#nushell -- -c '
214+
# Get all results files and process them in one go
215+
let files = (ls **/results.txt | get name)
216+
echo $"Found files: ($files)"
217+
218+
let matrix = {
219+
include: (
220+
$files
221+
| each { |file| open $file } # Open each file
222+
| each { |content| $content | lines } # Split into lines
223+
| flatten # Flatten the nested lists
224+
| where { |line| $line != "" } # Filter empty lines
225+
| each { |line|
226+
# Extract just the version part after the last colon
227+
let version = ($line | parse "supabase/postgres:{version}" | get version.0)
228+
{version: $version}
229+
}
230+
)
231+
}
232+
233+
let json_output = ($matrix | to json -r) # -r for raw output
234+
echo $"Debug output: ($json_output)"
235+
236+
$"matrix=($json_output)" | save --append $env.GITHUB_OUTPUT
237+
'
238+
- name: Debug Combined Results
239+
run: |
240+
echo "Combined Results: '${{ steps.combine.outputs.matrix }}'"
241+
outputs:
242+
matrix: ${{ steps.combine.outputs.matrix }}
243+
publish:
244+
needs: combine_results
245+
strategy:
246+
matrix: ${{ fromJson(needs.combine_results.outputs.matrix) }}
247+
uses: ./.github/workflows/mirror.yml
248+
with:
249+
version: ${{ inputs.postgresVersion != '' && inputs.postgresVersion || matrix.version }}
250+
secrets: inherit

0 commit comments

Comments
 (0)