2024-06-09 08:26:21 +00:00
|
|
|
from typing import Callable
|
2024-05-31 23:35:13 +00:00
|
|
|
import urllib.parse
|
2024-06-09 08:26:21 +00:00
|
|
|
import re
|
|
|
|
import functools
|
|
|
|
import subprocess
|
2024-06-09 07:27:06 +00:00
|
|
|
import dataclasses
|
2024-05-31 23:35:13 +00:00
|
|
|
|
|
|
|
S3_HOST = 's3.lix.systems'
|
|
|
|
S3_ENDPOINT = 'https://s3.lix.systems'
|
|
|
|
|
|
|
|
DEFAULT_STORE_URI_BITS = {
|
|
|
|
'region': 'garage',
|
|
|
|
'endpoint': 's3.lix.systems',
|
|
|
|
'want-mass-query': 'true',
|
|
|
|
'write-nar-listing': 'true',
|
|
|
|
'ls-compression': 'zstd',
|
|
|
|
'narinfo-compression': 'zstd',
|
|
|
|
'compression': 'zstd',
|
|
|
|
'parallel-compression': 'true',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-06-07 05:28:49 +00:00
|
|
|
@dataclasses.dataclass
|
|
|
|
class DockerTarget:
|
|
|
|
registry_path: str
|
2024-06-09 07:27:06 +00:00
|
|
|
"""Registry path without the tag, e.g. ghcr.io/lix-project/lix"""
|
2024-06-07 05:28:49 +00:00
|
|
|
|
2024-06-09 07:27:06 +00:00
|
|
|
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
|
2024-06-07 05:28:49 +00:00
|
|
|
"""
|
2024-06-09 07:27:06 +00:00
|
|
|
return item.format(version=version, major=major)
|
2024-06-07 05:28:49 +00:00
|
|
|
|
|
|
|
def registry_name(self) -> str:
|
|
|
|
[a, _, _] = self.registry_path.partition('/')
|
|
|
|
return a
|
|
|
|
|
|
|
|
|
2024-05-31 23:35:13 +00:00
|
|
|
@dataclasses.dataclass
|
|
|
|
class RelengEnvironment:
|
|
|
|
name: str
|
2024-06-09 08:26:21 +00:00
|
|
|
colour: Callable[[str], str]
|
2024-05-31 23:35:13 +00:00
|
|
|
|
|
|
|
cache_store_overlay: dict[str, str]
|
|
|
|
cache_bucket: str
|
|
|
|
releases_bucket: str
|
2024-06-06 21:40:59 +00:00
|
|
|
docs_bucket: str
|
2024-05-31 23:35:13 +00:00
|
|
|
git_repo: str
|
|
|
|
|
2024-06-07 05:28:49 +00:00
|
|
|
docker_targets: list[DockerTarget]
|
|
|
|
|
2024-05-31 23:35:13 +00:00
|
|
|
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)
|
|
|
|
|
2024-06-07 05:28:49 +00:00
|
|
|
|
2024-06-09 08:26:21 +00:00
|
|
|
SGR = '\x1b['
|
|
|
|
RED = '31;1m'
|
|
|
|
GREEN = '32;1m'
|
|
|
|
RESET = '0m'
|
|
|
|
|
|
|
|
|
|
|
|
def sgr(colour: str, text: str) -> str:
|
|
|
|
return f'{SGR}{colour}{text}{SGR}{RESET}'
|
|
|
|
|
|
|
|
|
2024-05-31 23:35:13 +00:00
|
|
|
STAGING = RelengEnvironment(
|
|
|
|
name='staging',
|
2024-06-09 08:26:21 +00:00
|
|
|
colour=functools.partial(sgr, GREEN),
|
2024-06-06 21:40:59 +00:00
|
|
|
docs_bucket='s3://staging-docs',
|
2024-05-31 23:35:13 +00:00
|
|
|
cache_bucket='s3://staging-cache',
|
2024-06-07 05:28:49 +00:00
|
|
|
cache_store_overlay={'secret-key': 'staging.key'},
|
2024-05-31 23:35:13 +00:00
|
|
|
releases_bucket='s3://staging-releases',
|
|
|
|
git_repo='ssh://git@git.lix.systems/lix-project/lix-releng-staging',
|
2024-06-07 05:28:49 +00:00
|
|
|
docker_targets=[
|
2024-06-09 07:50:40 +00:00
|
|
|
# latest will be auto tagged if appropriate
|
2024-06-09 07:27:06 +00:00
|
|
|
DockerTarget('git.lix.systems/lix-project/lix-releng-staging',
|
|
|
|
tags=['{version}', '{major}']),
|
|
|
|
DockerTarget('ghcr.io/lix-project/lix-releng-staging',
|
|
|
|
tags=['{version}', '{major}']),
|
2024-06-07 05:28:49 +00:00
|
|
|
],
|
2024-05-31 23:35:13 +00:00
|
|
|
)
|
|
|
|
|
2024-06-09 08:26:21 +00:00
|
|
|
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}']),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2024-06-07 05:28:49 +00:00
|
|
|
ENVIRONMENTS = {
|
|
|
|
'staging': STAGING,
|
2024-06-09 08:26:21 +00:00
|
|
|
'production': PROD,
|
2024-06-07 05:28:49 +00:00
|
|
|
}
|
|
|
|
|
2024-05-31 23:35:13 +00:00
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
class S3Credentials:
|
|
|
|
name: str
|
|
|
|
id: str
|
|
|
|
secret_key: str
|