Merge branch 'staging-home-config' into main
Keep the staging Home settings across restages staging-thin.py applies EQUIPO_HOME_* from a private 0600 file, checks issuer and consumer before mutating, and never echoes secrets. Reviewed by Astra (discussion 21).
1 file changed,
+31
−3
scripts/staging-thin.py+31 −3
CI passed — run details
diff --git a/scripts/staging-thin.py b/scripts/staging-thin.py| index 7a213d43..0b9da2d8 100755 |
| --- a/scripts/staging-thin.py |
| +++ b/scripts/staging-thin.py |
| @@ -39,7 +39,7 @@ import time |
| import urllib.parse |
| import urllib.request |
| -APP, ACCOUNT, CONSOLE = 'equipo-staging', 'oficina', 'https://console.carloku.com' |
| +APP, ACCOUNT, CONSOLE = 'equipo-staging', 'bds', 'https://console.carloku.com' |
| HOST = 'equipo-staging.bds.oncarlos.com' |
| ORIGIN = 'https://' + HOST |
| UNIT = 'equipo-runner-staging.service' |
| @@ -166,7 +166,33 @@ def instance_binary(sha): |
| return REPO / 'releases' / f'equipo-linux-arm64-{sha}' |
| -def deploy(): |
| +def home_config(): |
| + home = json.loads((ROOT / 'home-config.json').read_text()) |
| + if (not isinstance(home, dict) or |
| + set(home) != {'EQUIPO_HOME_ISSUER', 'EQUIPO_HOME_CONSUMER_ID', |
| + 'EQUIPO_HOME_KEYS_BASE64', 'EQUIPO_HOME_DEK_BASE64'} or |
| + home['EQUIPO_HOME_ISSUER'] != 'https://oficina-id-staging.bds.oncarlos.com' or |
| + home['EQUIPO_HOME_CONSUMER_ID'] != 'equipo-staging' or |
| + not all(isinstance(value, str) and value for value in home.values())): |
| + raise RuntimeError('invalid staging home configuration') |
| + return home |
| + |
| + |
| +def set_home_config(home): |
| + try: |
| + result = subprocess.run(['carlos', 'env', 'set', '--app', APP, '--account', ACCOUNT, |
| + '--console', CONSOLE, '--no-prompt', |
| + *(name + '=' + value for name, value in home.items())], |
| + cwd=REPO, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
| + timeout=60) |
| + except (OSError, subprocess.TimeoutExpired): |
| + raise RuntimeError('could not set staging home configuration') from None |
| + if result.returncode: |
| + raise RuntimeError('could not set staging home configuration') |
| + |
| + |
| +def deploy(home=None): |
| + home = home_config() if home is None else home |
| sha = head() |
| binary = instance_binary(sha) |
| if not binary.exists(): |
| @@ -185,6 +211,7 @@ def deploy(): |
| 'EQUIPO_EXECUTION_ENABLED=1', 'EQUIPO_EXECUTION_MARKER_PATH=/data/instances/' + HOST + '/execution/witness', |
| 'EQUIPO_ALLOW_LOGGED_MAIL=1', 'EQUIPO_TEST_PEOPLE=.invalid', |
| 'EQUIPO_ASSISTANT_HOSTS=' + ASSISTANT_HOSTS) |
| + set_home_config(home) |
| carlos('deploy', '--target', 'linux-arm64', '--swap', 'hold', '--version', sha, '--timeout', '5m', '--no-prompt', str(binary)) |
| deadline = time.monotonic() + 120 |
| while True: |
| @@ -498,6 +525,7 @@ def release(): |
| reconnect. Steps dispatched after the swap are never cut by a |
| runner restart, which is why the runners go first. |
| """ |
| + home = home_config() |
| sha = head() |
| served = deployed() |
| full = run(['git', 'rev-parse', sha], quiet=True).strip() |
| @@ -516,7 +544,7 @@ def release(): |
| time.sleep(60) |
| print('nothing in flight; runners first', flush=True) |
| runner(sha) |
| - deploy() |
| + deploy(home) |
| def main(): |