@@ -19,29 +19,52 @@ jobs:
1919 runs-on : blacksmith-4vcpu-ubuntu-2404
2020 outputs :
2121 matrix_config : ${{ steps.set-matrix.outputs.matrix_config }}
22- base_matrix : ${{ steps.set-matrix.outputs.base_matrix }}
23- layered_matrix : ${{ steps.set-matrix.outputs.layered_matrix }}
2422 steps :
2523 - name : Checkout Repo
2624 uses : supabase/postgres/.github/actions/shared-checkout@HEAD
2725 - uses : ./.github/actions/nix-install-ephemeral
2826 - name : Generate build matrix
2927 id : set-matrix
3028 run : |
31- nix run nixpkgs#nushell -- -c '
32- let releases = (open ansible/vars.yml | get postgres_release)
33- let base = (open ansible/vars.yml | get release_matrix_base
34- | each { |e| $e | insert tag ($releases | get $e.release_key) })
35- let layered = (open ansible/vars.yml | get release_matrix_layered
36- | each { |e|
37- let ver = ($releases | get $e.release_key)
38- $e | insert tag $"($ver)($e.tag_suffix)" | insert base_tag $ver
39- })
40- let combined = ($base | append $layered)
41- $"base_matrix=({include: $base} | to json -r)(char eol)" | save --append $env.GITHUB_OUTPUT
42- $"layered_matrix=({include: $layered} | to json -r)(char eol)" | save --append $env.GITHUB_OUTPUT
43- $"matrix_config=({include: $combined} | to json -r)(char eol)" | save --append $env.GITHUB_OUTPUT
44- '
29+ nix run nixpkgs#nushell -- -c 'let versions = (open ansible/vars.yml | get postgres_major)
30+ let base_matrix = ($versions | each { |ver|
31+ let version = ($ver | str trim)
32+ let dockerfile = $"Dockerfile-($version)"
33+ if ($dockerfile | path exists) {
34+ {
35+ version: $version,
36+ dockerfile: $dockerfile,
37+ target: "production"
38+ }
39+ } else {
40+ null
41+ }
42+ } | compact)
43+
44+ # Discover multigres variants by checking for matching targets in Dockerfile-multigres
45+ let multigres_matrix = ($versions | each { |ver|
46+ let version = ($ver | str trim)
47+ let mg_version = $"multigres-($version)"
48+ let mg_dockerfile = "Dockerfile-multigres"
49+ let mg_target = $"variant-($version)"
50+ if ($mg_dockerfile | path exists) and (open --raw $mg_dockerfile | str contains $"AS ($mg_target)") {
51+ {
52+ version: $mg_version,
53+ dockerfile: $mg_dockerfile,
54+ target: $mg_target
55+ }
56+ } else {
57+ null
58+ }
59+ } | compact)
60+
61+ let matrix = ($base_matrix | append $multigres_matrix)
62+
63+ let matrix_config = {
64+ include: $matrix
65+ }
66+
67+ $"matrix_config=($matrix_config | to json -r)" | save --append $env.GITHUB_OUTPUT'
4568 build :
4669 needs : prepare
4770 strategy :
@@ -66,45 +89,11 @@ jobs:
6689 | str join "\n"
6790 | save --append $env.GITHUB_OUTPUT
6891 '
69- build_base_images :
92+ build_release_image :
7093 needs : [prepare, build]
7194 strategy :
7295 matrix :
73- postgres : ${{ fromJson(needs.prepare.outputs.base_matrix).include }}
74- arch : [amd64, arm64]
75- runs-on : ${{ matrix.arch == 'amd64' && 'large-linux-x86' || 'large-linux-arm' }}
76- timeout-minutes : 180
77- steps :
78- - name : Checkout Repo
79- uses : supabase/postgres/.github/actions/shared-checkout@HEAD
80- - uses : ./.github/actions/nix-install-ephemeral
81- - run : docker context create builders
82- - uses : docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
83- with :
84- endpoint : builders
85- - uses : docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
86- with :
87- username : ${{ secrets.DOCKER_USERNAME }}
88- password : ${{ secrets.DOCKER_PASSWORD }}
89- - id : build
90- uses : docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
91- with :
92- push : true
93- build-args : |
94- ${{ needs.build.outputs.build_args }}
95- PG_VERSION=${{ matrix.postgres.pg_version }}
96- target : ${{ matrix.postgres.target }}
97- tags : supabase/postgres:${{ matrix.postgres.tag }}_${{ matrix.arch }}
98- platforms : linux/${{ matrix.arch }}
99- cache-from : type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
100- cache-to : type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
101- file : ${{ matrix.postgres.dockerfile }}
102-
103- build_layered_images :
104- needs : [prepare, build, build_base_images]
105- strategy :
106- matrix :
107- postgres : ${{ fromJson(needs.prepare.outputs.layered_matrix).include }}
96+ postgres : ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
10897 arch : [amd64, arm64]
10998 runs-on : ${{ matrix.arch == 'amd64' && 'large-linux-x86' || 'large-linux-arm' }}
11099 timeout-minutes : 180
@@ -120,22 +109,52 @@ jobs:
120109 with :
121110 username : ${{ secrets.DOCKER_USERNAME }}
122111 password : ${{ secrets.DOCKER_PASSWORD }}
112+ - name : Get image tag
113+ id : image
114+ run : |
115+ if [[ "${{ matrix.arch }}" == "arm64" ]]; then
116+ pg_version=$(nix run nixpkgs#nushell -- -c '
117+ let version = "${{ matrix.postgres.version }}"
118+ let is_multigres = ($version | str starts-with "multigres-")
119+ let base_version = if $is_multigres { $version | str replace "multigres-" "" } else { $version }
120+ let release_key = if ($base_version | str contains "orioledb") {
121+ $"postgresorioledb-17"
122+ } else {
123+ $"postgres($base_version)"
124+ }
125+ let base_tag = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
126+ if $is_multigres { $"($base_tag)-multigres" } else { $base_tag }
127+ ')
128+ echo "pg_version=supabase/postgres:$pg_version" >> $GITHUB_OUTPUT
129+ else
130+ pg_version=$(nix run nixpkgs#nushell -- -c '
131+ let version = "${{ matrix.postgres.version }}"
132+ let is_multigres = ($version | str starts-with "multigres-")
133+ let base_version = if $is_multigres { $version | str replace "multigres-" "" } else { $version }
134+ let release_key = if ($base_version | str contains "orioledb") {
135+ $"postgresorioledb-17"
136+ } else {
137+ $"postgres($base_version)"
138+ }
139+ let base_tag = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
140+ if $is_multigres { $"($base_tag)-multigres" } else { $base_tag }
141+ ')
142+ echo "pg_version=supabase/postgres:$pg_version" >> $GITHUB_OUTPUT
143+ fi
123144 - id : build
124145 uses : docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
125146 with :
126147 push : true
127148 build-args : |
128149 ${{ needs.build.outputs.build_args }}
129- PG_VERSION=${{ matrix.postgres.pg_version }}
130- SUPABASE_IMAGE=supabase/postgres:${{ matrix.postgres.base_tag }}_${{ matrix.arch }}
131150 target : ${{ matrix.postgres.target }}
132- tags : supabase/postgres: ${{ matrix.postgres.tag }}_${{ matrix.arch }}
151+ tags : ${{ steps.image.outputs.pg_version }}_${{ matrix.arch }}
133152 platforms : linux/${{ matrix.arch }}
134153 cache-from : type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
135154 cache-to : type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
136155 file : ${{ matrix.postgres.dockerfile }}
137156 merge_manifest :
138- needs : [prepare, build, build_base_images, build_layered_images ]
157+ needs : [prepare, build, build_release_image ]
139158 strategy :
140159 matrix :
141160 include : ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
@@ -151,7 +170,20 @@ jobs:
151170 password : ${{ secrets.DOCKER_PASSWORD }}
152171 - name : Get image tag
153172 id : get_version
154- run : echo "pg_version=supabase/postgres:${{ matrix.tag }}" >> $GITHUB_OUTPUT
173+ run : |
174+ nix run nixpkgs#nushell -- -c '
175+ let version = "${{ matrix.version }}"
176+ let is_multigres = ($version | str starts-with "multigres-")
177+ let base_version = if $is_multigres { $version | str replace "multigres-" "" } else { $version }
178+ let release_key = if ($base_version | str contains "orioledb") {
179+ $"postgresorioledb-17"
180+ } else {
181+ $"postgres($base_version)"
182+ }
183+ let base_tag = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
184+ let pg_version = if $is_multigres { $"($base_tag)-multigres" } else { $base_tag }
185+ $"pg_version=supabase/postgres:($pg_version)" | save --append $env.GITHUB_OUTPUT
186+ '
155187 - name : Output version
156188 id : output_version
157189 run : |
@@ -163,7 +195,7 @@ jobs:
163195 - name : Upload Results Artifact
164196 uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
165197 with :
166- name : merge_results-${{ matrix.tag }}
198+ name : merge_results-${{ matrix.version }}
167199 path : results.txt
168200 if-no-files-found : warn
169201 - name : Merge multi-arch manifests
@@ -189,14 +221,14 @@ jobs:
189221 nix run nixpkgs#nushell -- -c '
190222 # Parse the matrix configuration directly
191223 let matrix_config = (${{ toJson(needs.prepare.outputs.matrix_config) }} | from json)
192-
193- # Get tags directly from include array
194- let tags = ($matrix_config.include | get tag )
195-
196- echo "Tags : $tags "
197-
198- # Convert the tags to a comma-separated string
199- let versions_str = ($tags | str join ",")
224+
225+ # Get versions directly from include array
226+ let versions = ($matrix_config.include | get version )
227+
228+ echo "Versions : $versions "
229+
230+ # Convert the versions to a comma-separated string
231+ let versions_str = ($versions | str join ",")
200232 $"versions=$versions_str" | save --append $env.GITHUB_ENV
201233 '
202234 - name: Download Results Artifacts
0 commit comments