aboutsummaryrefslogtreecommitdiff
path: root/releng/environment.py
diff options
context:
space:
mode:
Diffstat (limited to 'releng/environment.py')
-rw-r--r--releng/environment.py92
1 files changed, 88 insertions, 4 deletions
diff --git a/releng/environment.py b/releng/environment.py
index 58633d548..ca8194fe5 100644
--- a/releng/environment.py
+++ b/releng/environment.py
@@ -1,5 +1,9 @@
-import dataclasses
+from typing import Callable
import urllib.parse
+import re
+import functools
+import subprocess
+import dataclasses
S3_HOST = 's3.lix.systems'
S3_ENDPOINT = 'https://s3.lix.systems'
@@ -17,8 +21,31 @@ DEFAULT_STORE_URI_BITS = {
@dataclasses.dataclass
+class DockerTarget:
+ registry_path: str
+ """Registry path without the tag, e.g. ghcr.io/lix-project/lix"""
+
+ tags: list[str]
+ """List of tags this image should take. There must be at least one."""
+
+ @staticmethod
+ def resolve(item: str, version: str, major: str) -> str:
+ """
+ Applies templates:
+ - version: the Lix version e.g. 2.90.0
+ - major: the major Lix version e.g. 2.90
+ """
+ return item.format(version=version, major=major)
+
+ def registry_name(self) -> str:
+ [a, _, _] = self.registry_path.partition('/')
+ return a
+
+
+@dataclasses.dataclass
class RelengEnvironment:
name: str
+ colour: Callable[[str], str]
cache_store_overlay: dict[str, str]
cache_bucket: str
@@ -26,22 +53,79 @@ class RelengEnvironment:
docs_bucket: str
git_repo: str
+ docker_targets: list[DockerTarget]
+
def cache_store_uri(self):
qs = DEFAULT_STORE_URI_BITS.copy()
qs.update(self.cache_store_overlay)
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'
- },
+ cache_store_overlay={'secret-key': 'staging.key'},
releases_bucket='s3://staging-releases',
git_repo='ssh://git@git.lix.systems/lix-project/lix-releng-staging',
+ docker_targets=[
+ # latest will be auto tagged if appropriate
+ DockerTarget('git.lix.systems/lix-project/lix-releng-staging',
+ tags=['{version}', '{major}']),
+ DockerTarget('ghcr.io/lix-project/lix-releng-staging',
+ tags=['{version}', '{major}']),
+ ],
)
+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,
+}
+
@dataclasses.dataclass
class S3Credentials: