Connect release initialization to runner-local PostgreSQL
This commit is contained in:
@@ -18,8 +18,10 @@ def required(variable):
|
||||
return value
|
||||
|
||||
|
||||
def database_url():
|
||||
def database_url(runner_loopback):
|
||||
host = required("BEDROCK_PG_HOST").removeprefix("[").removesuffix("]")
|
||||
if runner_loopback and host not in ("127.0.0.1", "::1"):
|
||||
raise SystemExit("--runner-loopback requires a loopback IP literal")
|
||||
if ":" in host:
|
||||
try:
|
||||
host = f"[{ipaddress.IPv6Address(host)}]"
|
||||
@@ -46,6 +48,10 @@ def main():
|
||||
parser.add_argument("output", type=Path)
|
||||
parser.add_argument("--deployment", default="default")
|
||||
parser.add_argument("--config-version", default="local")
|
||||
parser.add_argument(
|
||||
"--runner-loopback", action="store_true",
|
||||
help="connect without TLS to a loopback IP from the runner's host network",
|
||||
)
|
||||
options = parser.parse_args()
|
||||
if not re.fullmatch(r"[A-Za-z0-9._-]{1,128}", options.deployment):
|
||||
parser.error("invalid deployment name")
|
||||
@@ -61,8 +67,10 @@ def main():
|
||||
" postgres:\n"
|
||||
" kind: sql\n"
|
||||
" driver: postgres\n"
|
||||
f" primary: {json.dumps(database_url())}\n"
|
||||
f" primary: {json.dumps(database_url(options.runner_loopback))}\n"
|
||||
)
|
||||
if options.runner_loopback:
|
||||
config += " tls: disabled\n"
|
||||
|
||||
# Write with owner-only permissions, then replace the destination atomically.
|
||||
file = tempfile.NamedTemporaryFile(mode="w", dir=options.output.parent, delete=False)
|
||||
|
||||
Reference in New Issue
Block a user