47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Write the staging and production release records for one published image.
|
|
|
|
Inputs: pricing/app/app.py (version, unit price), reports/image-digest.txt,
|
|
and the Jenkins environment (COMMIT, BUILD_URL, STAGING_URL, PROD_URL, PROXY_NET).
|
|
Outputs: pricing/releases/<version>-staging.yml and <version>-production.yml.
|
|
The records hold metadata only, never credentials.
|
|
"""
|
|
import datetime
|
|
import os
|
|
import pathlib
|
|
import re
|
|
import sys
|
|
|
|
src = pathlib.Path("pricing/app/app.py").read_text()
|
|
version = re.search(r'^VERSION = "(v\d+)"', src, re.M).group(1)
|
|
unit_price = int(re.search(r"^UNIT_PRICE = (\d+)", src, re.M).group(1))
|
|
image = pathlib.Path("reports/image-digest.txt").read_text().strip()
|
|
if "@sha256:" not in image:
|
|
sys.exit(f"not a registry digest reference: {image!r}")
|
|
commit = os.environ["COMMIT"]
|
|
if not re.fullmatch(r"[0-9a-f]{40}", commit):
|
|
sys.exit(f"not a full commit hash: {commit!r}")
|
|
now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
for env, url in (("staging", os.environ["STAGING_URL"]), ("production", os.environ["PROD_URL"])):
|
|
record = (
|
|
f"# Release record: {version} {env}. Metadata only; no credentials.\n"
|
|
f"target_env: {env}\n"
|
|
f"release_image: {image}\n"
|
|
f"expected_version: {version}\n"
|
|
f"expected_commit: {commit}\n"
|
|
f"expected_total: {unit_price * 3}\n"
|
|
f"public_url: {url}\n"
|
|
f"proxy_network: {os.environ['PROXY_NET']}\n"
|
|
f"config_commit: {commit}\n"
|
|
f"jenkins_build: {os.environ['BUILD_URL']}\n"
|
|
f"recorded_at: {now}\n"
|
|
)
|
|
path = pathlib.Path(f"pricing/releases/{version}-{env}.yml")
|
|
path.write_text(record)
|
|
print(f"--- {path}\n{record}")
|
|
|
|
pathlib.Path("reports/release.env").write_text(
|
|
f"APP_VERSION={version}\nEXPECTED_TOTAL={unit_price * 3}\nDIGEST_REF={image}\n"
|
|
)
|