Skip to content

Commit ac06d48

Browse files
committed
fix build
1 parent 1ade191 commit ac06d48

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

.github/workflows/build.yaml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,50 @@ jobs:
2121
id: versions
2222
env:
2323
GH_TOKEN: ${{ github.token }}
24+
PG_MAJOR: "16"
2425
run: |
2526
set -euo pipefail
2627
28+
# Timescale + Toolkit: latest GitHub release (strip leading 'v')
2729
ts=$(curl -fsSL -H "Authorization: Bearer $GH_TOKEN" \
2830
https://api.github.com/repos/timescale/timescaledb/releases/latest \
2931
| jq -r .tag_name | sed 's/^v//')
3032
tk=$(curl -fsSL -H "Authorization: Bearer $GH_TOKEN" \
3133
https://api.github.com/repos/timescale/timescaledb-toolkit/releases/latest \
3234
| jq -r .tag_name | sed 's/^v//')
3335
34-
reg_token=$(curl -fsSL 'https://ghcr.io/token?service=ghcr.io&scope=repository:cloudnative-pg/postgresql:pull' | jq -r .token)
35-
pg=$(curl -fsSL -H "Authorization: Bearer $reg_token" \
36-
'https://ghcr.io/v2/cloudnative-pg/postgresql/tags/list?n=10000' \
37-
| jq -r '.tags[]' | grep -E '^16\.[0-9]+$' | sort -V | tail -1)
36+
# Latest PG minor from postgresql.org, then probe CNPG for a published tag,
37+
# walking back if CNPG hasn't republished yet.
38+
pg_minor=$(curl -fsSL https://www.postgresql.org/versions.json \
39+
| jq -r --arg m "$PG_MAJOR" '.[] | select(.major == $m) | .latestMinor')
40+
reg_token=$(curl -fsSL "https://ghcr.io/token?service=ghcr.io&scope=repository:cloudnative-pg/postgresql:pull" | jq -r .token)
41+
pg=""
42+
for n in $(seq "$pg_minor" -1 0); do
43+
code=$(curl -sS -o /dev/null -w "%{http_code}" \
44+
-H "Authorization: Bearer $reg_token" \
45+
-H "Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json" \
46+
"https://ghcr.io/v2/cloudnative-pg/postgresql/manifests/${PG_MAJOR}.${n}")
47+
if [ "$code" = "200" ]; then pg="${PG_MAJOR}.${n}"; break; fi
48+
done
49+
if [ -z "$pg" ]; then
50+
echo "No ${PG_MAJOR}.x tag found on ghcr.io/cloudnative-pg/postgresql" >&2
51+
exit 1
52+
fi
3853
3954
{
4055
echo "timescale=$ts"
4156
echo "timescale_minor=$(echo "$ts" | cut -d. -f-2)"
4257
echo "timescale_major=$(echo "$ts" | cut -d. -f1)"
4358
echo "timescale_toolkit=$tk"
4459
echo "postgres=$pg"
45-
echo "postgres_minor=$(echo "$pg" | cut -d. -f-2)"
46-
echo "postgres_major=$(echo "$pg" | cut -d. -f1)"
60+
echo "postgres_major=$PG_MAJOR"
4761
} >> "$GITHUB_OUTPUT"
4862
4963
{
5064
echo "## Resolved versions"
5165
echo "- TimescaleDB: \`$ts\`"
5266
echo "- TimescaleDB Toolkit: \`$tk\`"
53-
echo "- PostgreSQL (CNPG): \`$pg\`"
67+
echo "- PostgreSQL (CNPG): \`$pg\` (PG major \`$PG_MAJOR\`)"
5468
} >> "$GITHUB_STEP_SUMMARY"
5569
- name: Docker meta
5670
id: meta
@@ -62,11 +76,10 @@ jobs:
6276
tags: |
6377
type=raw,priority=1000,value=latest
6478
type=raw,priority=999,value=${{ steps.versions.outputs.postgres }}-ts${{ steps.versions.outputs.timescale }}
65-
type=raw,priority=998,value=${{ steps.versions.outputs.postgres_minor }}-ts${{ steps.versions.outputs.timescale_minor }}
79+
type=raw,priority=998,value=${{ steps.versions.outputs.postgres }}-ts${{ steps.versions.outputs.timescale_minor }}
6680
type=raw,priority=997,value=${{ steps.versions.outputs.postgres_major }}-ts${{ steps.versions.outputs.timescale_major }}
6781
type=raw,priority=996,value=${{ steps.versions.outputs.postgres }}
68-
type=raw,priority=995,value=${{ steps.versions.outputs.postgres_minor }}
69-
type=raw,priority=994,value=${{ steps.versions.outputs.postgres_major }}
82+
type=raw,priority=995,value=${{ steps.versions.outputs.postgres_major }}
7083
- name: Set up QEMU
7184
uses: docker/setup-qemu-action@v3
7285
- name: Set up Buildx
@@ -87,7 +100,7 @@ jobs:
87100
tags: ${{ steps.meta.outputs.tags }}
88101
labels: ${{ steps.meta.outputs.labels }}
89102
build-args: |
90-
POSTGRES_VERSION=${{ steps.versions.outputs.postgres }}
103+
POSTGRES_VERSION=${{ steps.versions.outputs.postgres_major }}
91104
CLOUDNATIVEPG_VERSION=${{ steps.versions.outputs.postgres }}
92105
TIMESCALE_VERSION=${{ steps.versions.outputs.timescale }}
93106
TIMESCALE_TOOLKIT_VERSION=${{ steps.versions.outputs.timescale_toolkit }}

CLAUDE.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ A Dockerfile + GitHub Actions pipeline that layers TimescaleDB and TimescaleDB T
1111
Versions are **not pinned** in this repo. The `Resolve latest versions` step in `.github/workflows/build.yaml` fetches them at build time:
1212

1313
- TimescaleDB + Toolkit: GitHub `releases/latest` of `timescale/timescaledb` and `timescale/timescaledb-toolkit` (leading `v` stripped).
14-
- PostgreSQL / CNPG: `ghcr.io/v2/cloudnative-pg/postgresql/tags/list`, filtered to `^16\.[0-9]+$` and `sort -V | tail -1`. Only Postgres 16 is tracked — to add another major, add a parallel filter or matrix, don't change `16` in place.
14+
- PostgreSQL: `https://www.postgresql.org/versions.json` is queried for `latestMinor` of PG major `16` (`PG_MAJOR` env in the step). We then HEAD-probe `ghcr.io/v2/cloudnative-pg/postgresql/manifests/16.<minor>` and walk back one minor at a time until we get a `200` — this tolerates the lag between an upstream PG release and CNPG re-publishing. The tags/list endpoint is intentionally **not** used: it's capped at 1000 entries per page and CNPG has enough historical tags that a plain-minor tag like `16.13` can fall off the first page.
1515

16-
`POSTGRES_VERSION` and `CLOUDNATIVEPG_VERSION` are fed the **same** resolved value (the CNPG tag like `16.11`). The Dockerfile uses `$POSTGRES_VERSION` inside the Timescale apt package name, so this relies on Timescale's Debian repo accepting the full `major.minor` (or on apt's loose matching for the major). If a scheduled build starts failing on `apt-get install` of `timescaledb-2-postgresql-<ver>`, verify the packagecloud triplet first — upstream may not have published yet for a brand-new CNPG minor.
16+
Two build args derive from different halves of the resolved version:
17+
18+
- `CLOUDNATIVEPG_VERSION` = the full probed tag (e.g. `16.13`) — used as the `FROM` tag.
19+
- `POSTGRES_VERSION` = the PG major only (e.g. `16`) — used inside the Timescale apt package name `timescaledb-2-postgresql-<major>`. Passing the full `16.13` here will fail (`E: Unable to locate package timescaledb-2-postgresql-16.13`) — Timescale's Debian packages are keyed on the PG major, not the minor.
20+
21+
Changing the tracked PG major means updating `PG_MAJOR` in the resolver step; there is no matrix anymore.
1722

1823
Renovate (`renovate.json`) no longer drives these versions; its regex managers now match nothing in `build.yaml` but are left in place for future use. Don't reintroduce the old Renovate comment pragmas — they'd fight the runtime resolver.
1924

0 commit comments

Comments
 (0)