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