-
Notifications
You must be signed in to change notification settings - Fork 321
Expand file tree
/
Copy pathversions.sh
More file actions
executable file
·200 lines (180 loc) · 6.04 KB
/
Copy pathversions.sh
File metadata and controls
executable file
·200 lines (180 loc) · 6.04 KB
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
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
allVersions="$(
git ls-remote --tags https://github.com/TryGhost/Ghost.git \
| sed -rne 's!^.*\trefs/tags/v?|\^\{\}$!!g; /^[0-9][.][0-9]+/p' \
| sort -ruV
)"
cliTags="$(git ls-remote --tags https://github.com/TryGhost/Ghost-CLI.git)"
cliVersion="$(
echo "$cliTags" \
| sed -rne 's!^.*\trefs/tags/v?|\^\{\}$!!g; /^[0-9][.][0-9]+/p' \
| grep -vE -- '-(alpha|beta|rc)' \
| sort -ruV \
| head -n1
)"
# the Dockerfile clones Ghost-CLI by commit hash so that git's own object verification pins
# the source; prefer the peeled hash since these are annotated tags
cliSha="$(
awk -v tag="refs/tags/v$cliVersion" '
$2 == tag "^{}" { peeled = $1 }
$2 == tag { direct = $1 }
END { print (peeled != "" ? peeled : direct) }
' <<<"$cliTags"
)"
if [ -z "$cliSha" ]; then
echo >&2 "error: cannot determine commit for Ghost-CLI 'v$cliVersion'"
exit 1
fi
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
rcGrepV='-v'
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
rcGrepV+=' -E'
rcGrepExpr='alpha|beta|rc'
# "-next" previews the Ghost 7.0 image structure (no Ghost-CLI, install at /home/ghost) but
# tracks the same stable upstream releases as its plain major, so it is stripped after the
# prerelease decision above rather than before it
nextVersion="${rcVersion%-next}"
isNext=
if [ "$nextVersion" != "$rcVersion" ]; then
isNext=1
fi
rcVersion="$nextVersion"
export version
# https://docs.ghost.org/faq/node-versions
# https://github.com/nodejs/Release (looking for "LTS")
case "$rcVersion" in
6) nodeVersion='22' ;;
*)
echo >&2 "error: unknown node version for '$version'"
exit 1
;;
esac
fullVersion="$(
echo "$allVersions" \
| grep -E "^${rcVersion}([.-]|$)" \
| grep $rcGrepV -- "$rcGrepExpr" \
| head -1
)"
if [ -z "$fullVersion" ]; then
echo >&2 "error: cannot determine full version for '$version'"
exit 1
fi
# get a list of architectures supported by the sharp module's prebuilt libraries
# we cannot build it on other arches since the dep, libvips, is usually too old in Debian and Alpine
doc="$(curl -fsSL "https://raw.githubusercontent.com/TryGhost/Ghost/refs/tags/v$fullVersion/pnpm-lock.yaml" \
| jq --compact-output --raw-input --null-input '
reduce (
inputs
| capture("^ *'"'"'@img/sharp-(?<dist>linux[a-z]*)-(?<arch>[a-z0-9]+)@[0-9.]+'"'"':")
) as $item ({
# this controls the variant ordering
linux: [], # non-Alpine first
linuxmusl: [], # Alpine second
}; .[$item.dist] += [ $item.arch ])
| map_values(unique)
| with_entries(
select(.value | length > 0)
| .key = {
# each of these should be a single distro version unless something *really* exceptional happens
# if there is more than one, they should be in descending order
linux: [ "bookworm" ],
linuxmusl: [ "alpine3.23" ],
}[.key][]
| .value = {
arches: (
.value | map({
x64: "amd64",
arm64: "arm64v8",
arm: "arm32v7",
s390x: "s390x",
}[.] // empty) # TODO maybe warn/error on unexpected values?
| sort
)
}
)
'
)"
# the "-next" image installs Ghost from the release tarball attached to the GitHub tag instead of
# via Ghost-CLI, so pin the exact artifact and its hash rather than re-resolving at build time.
# These assets start at 6.60.0; anything older has no tarball to install from.
if [ -n "$isNext" ]; then
tarballName="ghost-$fullVersion.tgz"
releaseJson="$(curl -fsSL "https://api.github.com/repos/TryGhost/Ghost/releases/tags/v$fullVersion")"
tarballUrl="$(jq <<<"$releaseJson" --raw-output --arg name "$tarballName" '
.assets[]? | select(.name == $name) | .browser_download_url // empty
')"
tarballDigest="$(jq <<<"$releaseJson" --raw-output --arg name "$tarballName" '
.assets[]? | select(.name == $name) | .digest // empty
')"
if [ -z "$tarballUrl" ]; then
echo >&2 "error: the GitHub release for 'v$fullVersion' has no '$tarballName' asset (these start at 6.60.0)"
exit 1
fi
# GitHub reports the asset digest as "sha256:<hex>"; refuse anything else rather than
# writing a hash the Dockerfile would then check with the wrong algorithm
case "$tarballDigest" in
sha256:?*) tarballSha256="${tarballDigest#sha256:}" ;;
*)
echo >&2 "error: unexpected digest '$tarballDigest' for '$tarballName'; update versions.sh"
exit 1
;;
esac
sourceJson="$(jq --null-input --compact-output \
--arg url "$tarballUrl" \
--arg sha256 "$tarballSha256" \
'{ tarball: { url: $url, sha256: $sha256 } }')"
else
sourceJson="$(jq --null-input --compact-output \
--arg version "$cliVersion" \
--arg sha "$cliSha" \
'{ cli: { version: $version, sha: $sha } }')"
fi
export fullVersion nodeVersion
json="$(jq <<<"$json" --compact-output --argjson doc "$doc" --argjson source "$sourceJson" '
env.nodeVersion as $nodeVersion
| .[env.version] = (
{ version: env.fullVersion }
+ $source
+ {
node: { version: $nodeVersion },
variants: (
$doc
| with_entries(
# add image FROM for Dockerfile template and parent arch lookup in generate-stackbrew-library.sh
# e.g. "node:22-alpine3.23" or "node:22-trixie-slim"
.value.from = "node:\($nodeVersion)-\(.key)\(
if .key | startswith("alpine") then "" else "-slim" end
)"
)
),
}
)
')"
done
jq <<<"$json" '
to_entries
# sort by version number, descending
| sort_by([
(.value.version | split("[.-]"; "") | map(tonumber? // .)),
# a pseudo-major ("6-next") tracks the same upstream release as its plain major, so the
# version alone ties; break it explicitly instead of inheriting whatever order
# versions.json already happened to have (sorted ascending here, so the plain major needs
# the higher value to land first once this is reversed)
(if .key | test("-(rc|next)$") then 0 else 1 end)
])
| reverse
| from_entries
' > versions.json