Initial Homegate 0.4.0 with web UI, Compose and Gitea Actions
This commit is contained in:
49
ci/image_metadata.py
Normal file
49
ci/image_metadata.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Validate release identity before registry credentials are used."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
|
||||
VERSION_PATTERN = r'(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?'
|
||||
COMPONENT = r'[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*'
|
||||
|
||||
|
||||
def metadata(server_url, repository, ref, revision, version_file, registry_override=''):
|
||||
server = urlsplit(server_url)
|
||||
if server.scheme not in ('http', 'https') or not server.hostname or server.username or server.query or server.fragment:
|
||||
raise ValueError('Invalid Gitea server URL')
|
||||
registry = (registry_override or server.netloc).lower()
|
||||
parsed = urlsplit('https://' + registry)
|
||||
if (not re.fullmatch(r'[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::[0-9]{1,5})?', registry)
|
||||
or parsed.port is not None and not 1 <= parsed.port <= 65535):
|
||||
raise ValueError('REGISTRY must be a hostname[:port], without scheme or path')
|
||||
if '.' not in registry and ':' not in registry and registry != 'localhost':
|
||||
raise ValueError('Use a registry FQDN or explicit port; a bare name is a Docker Hub namespace')
|
||||
repository = repository.lower()
|
||||
if not re.fullmatch(COMPONENT + '/' + COMPONENT, repository):
|
||||
raise ValueError('Repository must be owner/name with a Docker-compatible lowercase name')
|
||||
if not ref.startswith('refs/tags/v'):
|
||||
raise ValueError('Images are published only for vVERSION tags')
|
||||
version = ref.removeprefix('refs/tags/v')
|
||||
if not re.fullmatch(VERSION_PATTERN, version) or len(version) > 100:
|
||||
raise ValueError('Use a tag such as v0.4.0 or v0.4.0-rc.1')
|
||||
if version != version_file.strip():
|
||||
raise ValueError('Release tag must match VERSION in the checked-out commit')
|
||||
if not re.fullmatch(r'[a-fA-F0-9]{40}|[a-fA-F0-9]{64}', revision):
|
||||
raise ValueError('Invalid commit SHA')
|
||||
return {'registry': registry, 'image': registry + '/' + repository,
|
||||
'version': version, 'revision': revision.lower(),
|
||||
'source': server_url.rstrip('/') + '/' + repository}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
values = metadata(os.environ['CI_SERVER_URL'], os.environ['CI_REPOSITORY'],
|
||||
os.environ['CI_REF'], os.environ['CI_REVISION'],
|
||||
Path('VERSION').read_text(), os.environ.get('REGISTRY', ''))
|
||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
|
||||
for key, value in values.items():
|
||||
if '\n' in value or '\r' in value:
|
||||
raise ValueError('Invalid multiline output')
|
||||
output.write(f'{key}={value}\n')
|
||||
print('Validated release:', values['image'] + ':' + values['version'])
|
||||
Reference in New Issue
Block a user