Update undeploy
Some checks failed
Lint Checks / Run linter (pull_request) Failing after 36s
Deploy Test / Run deploy test suite (pull_request) Successful in 5m30s
Webapp Test / Run webapp test suite (pull_request) Successful in 5m10s
K8s Deployment Control Test / Run deployment control suite on kind/k8s (pull_request) Successful in 8m29s
Smoke Test / Run basic test suite (pull_request) Successful in 5m8s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 11m13s

This commit is contained in:
Thomas E Lackey 2024-08-26 13:58:39 -05:00
parent 970351db92
commit 004b5ab8fe
4 changed files with 46 additions and 29 deletions

View File

@ -58,7 +58,7 @@ def process_app_deployment_request(
force_rebuild, force_rebuild,
fqdn_policy, fqdn_policy,
recreate_on_deploy, recreate_on_deploy,
deployer_record, webapp_deployer_record,
gpg, gpg,
private_key_passphrase, private_key_passphrase,
config_upload_dir, config_upload_dir,
@ -245,7 +245,7 @@ def process_app_deployment_request(
dns_lrn, dns_lrn,
deployment_dir, deployment_dir,
app_deployment_request, app_deployment_request,
deployer_record, webapp_deployer_record,
logger, logger,
) )
logger.log("Publication complete.") logger.log("Publication complete.")
@ -438,8 +438,16 @@ def command( # noqa: C901
exclude_tags = [tag.strip() for tag in exclude_tags.split(",") if tag] exclude_tags = [tag.strip() for tag in exclude_tags.split(",") if tag]
laconic = LaconicRegistryClient(laconic_config, log_file=sys.stderr) laconic = LaconicRegistryClient(laconic_config, log_file=sys.stderr)
deployer_record = laconic.get_record(lrn, require=True) webapp_deployer_record = laconic.get_record(lrn, require=True)
main_logger.log(f"Payment address: {deployer_record.attributes.paymentAddress}") payment_address = webapp_deployer_record.attributes.paymentAddress
main_logger.log(f"Payment address: {payment_address}")
if min_required_payment and not payment_address:
print(
f"Minimum payment required, but no payment address listed for deployer: {lrn}.",
file=sys.stderr,
)
sys.exit(2)
# Find deployment requests. # Find deployment requests.
# single request # single request
@ -576,7 +584,7 @@ def command( # noqa: C901
if confirm_payment( if confirm_payment(
laconic, laconic,
r, r,
deployer_record.attributes.paymentAddress, payment_address,
min_required_payment, min_required_payment,
main_logger, main_logger,
): ):
@ -631,7 +639,7 @@ def command( # noqa: C901
force_rebuild, force_rebuild,
fqdn_policy, fqdn_policy,
recreate_on_deploy, recreate_on_deploy,
deployer_record, webapp_deployer_record,
gpg, gpg,
private_key_passphrase, private_key_passphrase,
config_upload_dir, config_upload_dir,

View File

@ -74,7 +74,7 @@ def command( # noqa: C901
pub_key = base64.b64encode(open(public_key_file, "rb").read()).decode("ASCII") pub_key = base64.b64encode(open(public_key_file, "rb").read()).decode("ASCII")
hostname = urlparse(api_url).hostname hostname = urlparse(api_url).hostname
deployer_record = { webapp_deployer_record = {
"record": { "record": {
"type": "WebappDeployer", "type": "WebappDeployer",
"version": "1.0.0", "version": "1.0.0",
@ -86,10 +86,12 @@ def command( # noqa: C901
} }
if min_required_payment: if min_required_payment:
deployer_record["record"]["minimumPayment"] = f"{min_required_payment}alnt" webapp_deployer_record["record"][
"minimumPayment"
] = f"{min_required_payment}alnt"
if dry_run: if dry_run:
yaml.dump(deployer_record, sys.stdout) yaml.dump(webapp_deployer_record, sys.stdout)
return return
laconic.publish(deployer_record, [lrn]) laconic.publish(webapp_deployer_record, [lrn])

View File

@ -38,7 +38,7 @@ def process_app_removal_request(
deployment_parent_dir, deployment_parent_dir,
delete_volumes, delete_volumes,
delete_names, delete_names,
payment_address, webapp_deployer_record,
): ):
deployment_record = laconic.get_record( deployment_record = laconic.get_record(
app_removal_request.attributes.deployment, require=True app_removal_request.attributes.deployment, require=True
@ -84,7 +84,7 @@ def process_app_removal_request(
"version": "1.0.0", "version": "1.0.0",
"request": app_removal_request.id, "request": app_removal_request.id,
"deployment": deployment_record.id, "deployment": deployment_record.id,
"by": payment_address, "deployer": webapp_deployer_record.names[0],
} }
} }
@ -171,12 +171,7 @@ def dump_known_requests(filename, requests):
help="Requests must have a minimum payment to be processed (in alnt)", help="Requests must have a minimum payment to be processed (in alnt)",
default=0, default=0,
) )
@click.option( @click.option("--lrn", help="The LRN of this deployer.", required=True)
"--payment-address",
help="The address to which payments should be made. "
"Default is the current laconic account.",
default=None,
)
@click.option( @click.option(
"--all-requests", "--all-requests",
help="Handle requests addressed to anyone (by default only requests to" help="Handle requests addressed to anyone (by default only requests to"
@ -198,7 +193,7 @@ def command( # noqa: C901
include_tags, include_tags,
exclude_tags, exclude_tags,
min_required_payment, min_required_payment,
payment_address, lrn,
all_requests, all_requests,
): ):
if request_id and discover: if request_id and discover:
@ -218,8 +213,16 @@ def command( # noqa: C901
exclude_tags = [tag.strip() for tag in exclude_tags.split(",") if tag] exclude_tags = [tag.strip() for tag in exclude_tags.split(",") if tag]
laconic = LaconicRegistryClient(laconic_config, log_file=sys.stderr) laconic = LaconicRegistryClient(laconic_config, log_file=sys.stderr)
if not payment_address: deployer_record = laconic.get_record(lrn, require=True)
payment_address = laconic.whoami().address payment_address = deployer_record.attributes.paymentAddress
main_logger.log(f"Payment address: {payment_address}")
if min_required_payment and not payment_address:
print(
f"Minimum payment required, but no payment address listed for deployer: {lrn}.",
file=sys.stderr,
)
sys.exit(2)
# Find deployment removal requests. # Find deployment removal requests.
# single request # single request
@ -233,7 +236,7 @@ def command( # noqa: C901
if all_requests: if all_requests:
requests = laconic.app_deployment_removal_requests() requests = laconic.app_deployment_removal_requests()
else: else:
requests = laconic.app_deployment_removal_requests({"to": payment_address}) requests = laconic.app_deployment_removal_requests({"deployer": lrn})
if only_update_state: if only_update_state:
if not dry_run: if not dry_run:
@ -312,7 +315,11 @@ def command( # noqa: C901
for r in requests_to_check_for_payment: for r in requests_to_check_for_payment:
main_logger.log(f"{r.id}: Confirming payment...") main_logger.log(f"{r.id}: Confirming payment...")
if confirm_payment( if confirm_payment(
laconic, r, payment_address, min_required_payment, main_logger laconic,
r,
payment_address,
min_required_payment,
main_logger,
): ):
main_logger.log(f"{r.id}: Payment confirmed.") main_logger.log(f"{r.id}: Payment confirmed.")
requests_to_execute.append(r) requests_to_execute.append(r)
@ -336,7 +343,7 @@ def command( # noqa: C901
os.path.abspath(deployment_parent_dir), os.path.abspath(deployment_parent_dir),
delete_volumes, delete_volumes,
delete_names, delete_names,
payment_address, deployer_record,
) )
except Exception as e: except Exception as e:
main_logger.log(f"ERROR processing removal request {r.id}: {e}") main_logger.log(f"ERROR processing removal request {r.id}: {e}")

View File

@ -142,14 +142,14 @@ def confirm_payment(laconic, record, payment_address, min_amount, logger):
# Check if the payment was already used on a # Check if the payment was already used on a
used = laconic.app_deployments( used = laconic.app_deployments(
{"by": payment_address, "payment": tx.hash}, all=True {"deployer": payment_address, "payment": tx.hash}, all=True
) )
if len(used): if len(used):
logger.log(f"{record.id}: payment {tx.hash} already used on deployment {used}") logger.log(f"{record.id}: payment {tx.hash} already used on deployment {used}")
return False return False
used = laconic.app_deployment_removals( used = laconic.app_deployment_removals(
{"by": payment_address, "payment": tx.hash}, all=True {"deployer": payment_address, "payment": tx.hash}, all=True
) )
if len(used): if len(used):
logger.log( logger.log(
@ -627,7 +627,7 @@ def publish_deployment(
dns_lrn, dns_lrn,
deployment_dir, deployment_dir,
app_deployment_request=None, app_deployment_request=None,
deployment_record=None, webapp_deployer_record=None,
logger=None, logger=None,
): ):
if not deploy_record: if not deploy_record:
@ -684,8 +684,8 @@ def publish_deployment(
"payment" "payment"
] = app_deployment_request.attributes.payment ] = app_deployment_request.attributes.payment
if deployment_record: if webapp_deployer_record:
new_deployment_record["record"]["deployer"] = deployment_record.names[0] new_deployment_record["record"]["deployer"] = webapp_deployer_record.names[0]
if logger: if logger:
logger.log("Publishing ApplicationDeploymentRecord.") logger.log("Publishing ApplicationDeploymentRecord.")