diff options
Diffstat (limited to 'releng/environment.py')
-rw-r--r-- | releng/environment.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/releng/environment.py b/releng/environment.py index b2278491a..ca8194fe5 100644 --- a/releng/environment.py +++ b/releng/environment.py @@ -1,4 +1,8 @@ +from typing import Callable import urllib.parse +import re +import functools +import subprocess import dataclasses S3_HOST = 's3.lix.systems' @@ -41,6 +45,7 @@ class DockerTarget: @dataclasses.dataclass class RelengEnvironment: name: str + colour: Callable[[str], str] cache_store_overlay: dict[str, str] cache_bucket: str @@ -56,8 +61,19 @@ class RelengEnvironment: return self.cache_bucket + "?" + urllib.parse.urlencode(qs) +SGR = '\x1b[' +RED = '31;1m' +GREEN = '32;1m' +RESET = '0m' + + +def sgr(colour: str, text: str) -> str: + return f'{SGR}{colour}{text}{SGR}{RESET}' + + STAGING = RelengEnvironment( name='staging', + colour=functools.partial(sgr, GREEN), docs_bucket='s3://staging-docs', cache_bucket='s3://staging-cache', cache_store_overlay={'secret-key': 'staging.key'}, @@ -72,8 +88,42 @@ STAGING = RelengEnvironment( ], ) +GERRIT_REMOTE_RE = re.compile(r'^ssh://(\w+@)?gerrit.lix.systems:2022/lix$') + + +def guess_gerrit_remote(): + """ + Deals with people having unknown gerrit username. + """ + out = [ + x.split()[1] for x in subprocess.check_output( + ['git', 'remote', '-v']).decode().splitlines() + ] + return next(x for x in out if GERRIT_REMOTE_RE.match(x)) + + +PROD = RelengEnvironment( + name='production', + colour=functools.partial(sgr, RED), + docs_bucket='s3://docs', + cache_bucket='s3://cache', + # FIXME: we should decrypt this with age into a tempdir in the future, but + # the issue is how to deal with the recipients file. For now, we should + # just delete it after doing a release. + cache_store_overlay={'secret-key': 'prod.key'}, + releases_bucket='s3://releases', + git_repo=guess_gerrit_remote(), + docker_targets=[ + # latest will be auto tagged if appropriate + DockerTarget('git.lix.systems/lix-project/lix', + tags=['{version}', '{major}']), + DockerTarget('ghcr.io/lix-project/lix', tags=['{version}', '{major}']), + ], +) + ENVIRONMENTS = { 'staging': STAGING, + 'production': PROD, } |