Autodetect Current Revision of Alpine Version (#113)

* continue to use provided 'release' value if specified
* continue to use 'edge' for edge versions
* deduce 'release' value from the version on the alpine-base APK in https://dl-cdn.alpinelinux.org/alpine/v<version/main/<arch>/ 
* update test profile with 3.13
This commit is contained in:
tomalok 2021-02-02 20:13:33 -08:00 committed by GitHub
parent 30550530fe
commit 88f3f1374e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 19 deletions

View File

@ -8,7 +8,7 @@ revision = "r0"
# Versioning
version = null
release = null
release = null # defaults to autodetect
end_of_life = null
# Architecture

View File

@ -8,7 +8,7 @@ revision = "r0"
# Versioning
version = null
release = null
release = null # defaults to autodetect
end_of_life = null
# Architecture

View File

@ -1,6 +1,7 @@
### Profile for Testing Builds
# vim: ts=2 et:
version-3_13 { include required("version/3.13") }
version-3_12 { include required("version/3.12") }
version-3_11 { include required("version/3.11") }
version-3_10 { include required("version/3.10") }
@ -25,11 +26,13 @@ test {
# Build definitions
BUILDS {
# merge version, arch, profile, and build vars
v3_13-x86_64 = ${version-3_13} ${arch-x86_64} ${test}
v3_12-x86_64 = ${version-3_12} ${arch-x86_64} ${test}
v3_11-x86_64 = ${version-3_11} ${arch-x86_64} ${test} { revision = "r1" }
v3_10-x86_64 = ${version-3_10} ${arch-x86_64} ${test} { revision = "r2" }
edge-x86_64 = ${version-edge} ${arch-x86_64} ${test}
v3_13-aarch64 = ${version-3_13} ${arch-aarch64} ${test}
v3_12-aarch64 = ${version-3_12} ${arch-aarch64} ${test}
edge-aarch64 = ${version-edge} ${arch-aarch64} ${test}
}

View File

@ -6,7 +6,6 @@ include required("../base/1")
# set version-specific vars
version = "3.10"
release = "3.10.5"
end_of_life = "2021-05-01"
repos {
"http://dl-cdn.alpinelinux.org/alpine/v3.10/main" = true

View File

@ -6,7 +6,6 @@ include required("../base/1")
# set version-specific vars
version = "3.11"
release = "3.11.7"
end_of_life = "2021-11-01"
repos {
"http://dl-cdn.alpinelinux.org/alpine/v3.11/main" = true

View File

@ -6,7 +6,6 @@ include required("../base/1")
# set version-specific vars
version = "3.12"
release = "3.12.3"
end_of_life = "2022-05-01"
repos {
"http://dl-cdn.alpinelinux.org/alpine/v3.12/main" = true

View File

@ -6,7 +6,6 @@ include required("../base/current")
# add edge-specific tweaks...
version = "3.13"
release = "3.13.1"
end_of_life = "2022-11-01"
repos {

View File

@ -6,7 +6,6 @@ include required("../base/1")
# set version-specific vars
version = "3.9"
release = "3.9.6"
end_of_life = "2021-01-01"
repos {
"http://dl-cdn.alpinelinux.org/alpine/v3.9/main" = true

View File

@ -6,7 +6,6 @@ include required("../base/current")
# add edge-specific tweaks...
version = "edge"
release = "edge"
end_of_life = null # defaults to tomorrow
revision = null # defaults to datetime

View File

@ -404,12 +404,38 @@ class ConfigBuilder:
def force_iso_date(input):
return datetime.fromisoformat(input).isoformat(timespec="seconds")
@classmethod
def resolve_release(cls, input, cfg):
if input:
# release is explicitly defined, run with it
return input
if cfg['version'] == 'edge':
return 'edge'
# hack to determine release value from version's alpine-base APK
pkgs_url = f"https://dl-cdn.alpinelinux.org/alpine/v{cfg['version']}/main/{cfg['arch']}/"
try:
res = urlopen(pkgs_url)
except urllib.error.HTTPError as ex:
print(f"Unable to urlopen {pkgs_url} - {ex}", file=sys.stderr)
exit(1)
line = res.readline().decode('utf-8')
while line:
if line.startswith('<a href="'):
pkg = line.split('"')[1]
if pkg.startswith('alpine-base-'):
# we got it, use package version as the revision value
return pkg.split('-')[2]
line = res.readline().decode('utf-8')
# didn't find it?
raise RuntimeError(f"Unable to parse 'alpine-base' APK from {pkgs_url}")
@classmethod
def resolve_now(cls):
return cls.now.strftime("%Y%m%d%H%M%S")
@classmethod
def resolve_revision(cls, input):
def resolve_revision(cls, input, cfg):
if input is None or input == "":
return cls.resolve_now()
return input
@ -419,33 +445,33 @@ class ConfigBuilder:
return cls.tomorrow.isoformat(timespec="seconds")
@classmethod
def resolve_end_of_life(cls, input):
def resolve_end_of_life(cls, input, cfg):
if input is None or input == "":
return cls.resolve_tomorrow()
return input
@classmethod
def fold_comma(cls, input):
def fold_comma(cls, input, cfg):
return ",".join([cls.unquote(k) for k in input.keys()])
@classmethod
def fold_space(cls, input):
def fold_space(cls, input, cfg):
return " ".join([cls.unquote(k) for k in input.keys()])
@classmethod
def fold_repos(cls, input):
def fold_repos(cls, input, cfg):
return "\n".join(
f"@{v} {cls.unquote(k)}" if isinstance(v, str) else cls.unquote(k)
for k, v in input.items())
@staticmethod
def fold_packages(input):
def fold_packages(input, cfg):
return " ".join(
f"{k}@{v}" if isinstance(v, str) else k
for k, v in input.items())
@staticmethod
def fold_services(input):
def fold_services(input, cfg):
return " ".join(
"{}={}".format(k, ",".join(v.keys()))
for k, v in input.items())
@ -461,9 +487,10 @@ class ConfigBuilder:
"repos" : self.fold_repos,
"pkgs" : self.fold_packages,
"svcs" : self.fold_services,
"release" : self.resolve_release,
"revision" : self.resolve_revision,
"end_of_life" : lambda x: \
self.force_iso_date(self.resolve_end_of_life(x)),
"end_of_life" : lambda x, y: \
self.force_iso_date(self.resolve_end_of_life(x, y)),
}
def build_all(self):
@ -509,7 +536,7 @@ class ConfigBuilder:
for k, v in cfg.items():
transform = self._keys_to_transform.get(k)
if transform:
cfg[k] = transform(v)
cfg[k] = transform(v, cfg)
if isinstance(v, str) and "{var." in v:
cfg[k] = v.format(var=cfg)

View File

@ -122,7 +122,7 @@ install_base() {
if [ "$VERSION" != edge ]; then
ALPINE_RELEASE=$(cat "$TARGET/etc/alpine-release")
[ "$RELEASE" = "$ALPINE_RELEASE" ] || \
die "Newer Alpine release detected: $ALPINE_RELEASE"
die "Release '$RELEASE' does not match /etc/alpine-release: $ALPINE_RELEASE"
fi
}