source/docker: Add regex match for tags
infra/updatebot/pipeline/head This commit looks good
Details
infra/updatebot/pipeline/head This commit looks good
Details
Repositories on Docker Hub often have images we do not want to consider when determining the "latest" version of an application, such as non=container images, development/testing versions, etc. To exclude these, project sources can now define a `version_re` property that contains a regular expression. Images that do not match the expression will be ignored.master
parent
7efde27b48
commit
5f8db2fa47
13
updatebot.py
13
updatebot.py
|
@ -79,6 +79,7 @@ class DockerHubSource(BaseSource):
|
||||||
kind: Literal['docker']
|
kind: Literal['docker']
|
||||||
namespace: str
|
namespace: str
|
||||||
repository: str
|
repository: str
|
||||||
|
version_re: str = r'^(?P<version>[0-9]+(\.[0-9]+)*(-[0-9]+)?)$'
|
||||||
|
|
||||||
def get_latest_version(self) -> str:
|
def get_latest_version(self) -> str:
|
||||||
session = _get_session()
|
session = _get_session()
|
||||||
|
@ -89,10 +90,18 @@ class DockerHubSource(BaseSource):
|
||||||
r = session.get(url)
|
r = session.get(url)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
versions = []
|
versions = []
|
||||||
|
regex = re.compile(self.version_re)
|
||||||
for result in data['results']:
|
for result in data['results']:
|
||||||
if result['name'] == 'latest':
|
m = regex.match(result['name'])
|
||||||
|
if not m:
|
||||||
|
log.debug(
|
||||||
|
'Skipping tag %s: does not match regex %s',
|
||||||
|
result['name'],
|
||||||
|
self.version_re,
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
versions.append((result['last_updated'], result['name']))
|
version = m.groupdict()['version']
|
||||||
|
versions.append((result['last_updated'], version))
|
||||||
versions.sort()
|
versions.sort()
|
||||||
return versions[-1][-1]
|
return versions[-1][-1]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue