Add a versioned backend catalog and YAML deployment configuration
This commit is contained in:
+15
-12
@@ -45,26 +45,29 @@ def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--deployment", default="default")
|
||||
parser.add_argument("--config-version", default="local")
|
||||
options = parser.parse_args()
|
||||
if not re.fullmatch(r"[A-Za-z0-9._-]{1,128}", options.deployment):
|
||||
parser.error("invalid deployment name")
|
||||
config = {
|
||||
"deployment": options.deployment,
|
||||
"cluster": "postgres",
|
||||
"clusters": {
|
||||
"postgres": {
|
||||
"driver": "postgres",
|
||||
"primary": database_url(),
|
||||
}
|
||||
},
|
||||
}
|
||||
if not re.fullmatch(r"[A-Za-z0-9._-]{1,128}", options.config_version):
|
||||
parser.error("invalid config version")
|
||||
# JSON quoting is valid for scalars in YAML and handles special characters.
|
||||
config = (
|
||||
f"deployment: {json.dumps(options.deployment)}\n"
|
||||
f"config_version: {json.dumps(options.config_version)}\n"
|
||||
"sql:\n"
|
||||
" documents: postgres\n"
|
||||
"clusters:\n"
|
||||
" postgres:\n"
|
||||
" driver: postgres\n"
|
||||
f" primary: {json.dumps(database_url())}\n"
|
||||
)
|
||||
|
||||
# Write with owner-only permissions, then replace the destination atomically.
|
||||
file = tempfile.NamedTemporaryFile(mode="w", dir=options.output.parent, delete=False)
|
||||
try:
|
||||
with file:
|
||||
json.dump(config, file, indent=2)
|
||||
file.write("\n")
|
||||
file.write(config)
|
||||
os.replace(file.name, options.output)
|
||||
finally:
|
||||
Path(file.name).unlink(missing_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user