Fix gpg key usage when uploading config to multiple deployers
All checks were successful
Lint Checks / Run linter (pull_request) Successful in 40s
Webapp Test / Run webapp test suite (pull_request) Successful in 5m17s
Deploy Test / Run deploy test suite (pull_request) Successful in 6m10s
K8s Deployment Control Test / Run deployment control suite on kind/k8s (pull_request) Successful in 8m35s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 9m47s
Smoke Test / Run basic test suite (pull_request) Successful in 4m14s
All checks were successful
Lint Checks / Run linter (pull_request) Successful in 40s
Webapp Test / Run webapp test suite (pull_request) Successful in 5m17s
Deploy Test / Run deploy test suite (pull_request) Successful in 6m10s
K8s Deployment Control Test / Run deployment control suite on kind/k8s (pull_request) Successful in 8m35s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 9m47s
Smoke Test / Run basic test suite (pull_request) Successful in 4m14s
This commit is contained in:
parent
2bf1ed5653
commit
9810b46f7f
@ -97,69 +97,70 @@ def command( # noqa: C901
|
|||||||
if env_file and config_ref:
|
if env_file and config_ref:
|
||||||
fatal("Cannot use --env-file and --config-ref at the same time.")
|
fatal("Cannot use --env-file and --config-ref at the same time.")
|
||||||
|
|
||||||
tempdir = tempfile.mkdtemp()
|
laconic = LaconicRegistryClient(laconic_config)
|
||||||
try:
|
|
||||||
laconic = LaconicRegistryClient(laconic_config)
|
|
||||||
|
|
||||||
app_record = laconic.get_record(app)
|
app_record = laconic.get_record(app)
|
||||||
if not app_record:
|
if not app_record:
|
||||||
fatal(f"Unable to locate app: {app}")
|
fatal(f"Unable to locate app: {app}")
|
||||||
|
|
||||||
# Deployers to send requests to
|
# Deployers to send requests to
|
||||||
deployer_records = []
|
deployer_records = []
|
||||||
|
|
||||||
auction = None
|
auction = None
|
||||||
auction_winners = None
|
auction_winners = None
|
||||||
if auction_id:
|
if auction_id:
|
||||||
# Fetch auction details
|
# Fetch auction details
|
||||||
auction = laconic.get_auction(auction_id)
|
auction = laconic.get_auction(auction_id)
|
||||||
if not auction:
|
if not auction:
|
||||||
fatal(f"Unable to locate auction: {auction_id}")
|
fatal(f"Unable to locate auction: {auction_id}")
|
||||||
|
|
||||||
# Check auction owner
|
# Check auction owner
|
||||||
if auction.ownerAddress != laconic.whoami().address:
|
if auction.ownerAddress != laconic.whoami().address:
|
||||||
fatal(f"Auction {auction_id} owner mismatch")
|
fatal(f"Auction {auction_id} owner mismatch")
|
||||||
|
|
||||||
# Check auction kind
|
# Check auction kind
|
||||||
if auction.kind != AUCTION_KIND_PROVIDER:
|
if auction.kind != AUCTION_KIND_PROVIDER:
|
||||||
fatal(f"Auction kind needs to be ${AUCTION_KIND_PROVIDER}, got {auction.kind}")
|
fatal(f"Auction kind needs to be ${AUCTION_KIND_PROVIDER}, got {auction.kind}")
|
||||||
|
|
||||||
# Check auction status
|
# Check auction status
|
||||||
if auction.status != AuctionStatus.COMPLETED:
|
if auction.status != AuctionStatus.COMPLETED:
|
||||||
fatal(f"Auction {auction_id} not completed yet, status {auction.status}")
|
fatal(f"Auction {auction_id} not completed yet, status {auction.status}")
|
||||||
|
|
||||||
# Check that winner list is not empty
|
# Check that winner list is not empty
|
||||||
if len(auction.winnerAddresses) == 0:
|
if len(auction.winnerAddresses) == 0:
|
||||||
fatal(f"Auction {auction_id} has no winners")
|
fatal(f"Auction {auction_id} has no winners")
|
||||||
|
|
||||||
auction_winners = auction.winnerAddresses
|
auction_winners = auction.winnerAddresses
|
||||||
|
|
||||||
# Get deployer record for all the auction winners
|
# Get deployer record for all the auction winners
|
||||||
for auction_winner in auction_winners:
|
for auction_winner in auction_winners:
|
||||||
# TODO: Match auction winner address with provider address?
|
# TODO: Match auction winner address with provider address?
|
||||||
deployer_records_by_owner = laconic.webapp_deployers({"paymentAddress": auction_winner})
|
deployer_records_by_owner = laconic.webapp_deployers({"paymentAddress": auction_winner})
|
||||||
if len(deployer_records_by_owner) == 0:
|
if len(deployer_records_by_owner) == 0:
|
||||||
print(f"WARNING: Unable to locate deployer for auction winner {auction_winner}")
|
print(f"WARNING: Unable to locate deployer for auction winner {auction_winner}")
|
||||||
|
|
||||||
# Take first record with name set
|
# Take first record with name set
|
||||||
target_deployer_record = deployer_records_by_owner[0]
|
target_deployer_record = deployer_records_by_owner[0]
|
||||||
for r in deployer_records_by_owner:
|
for r in deployer_records_by_owner:
|
||||||
if len(r.names) > 0:
|
if len(r.names) > 0:
|
||||||
target_deployer_record = r
|
target_deployer_record = r
|
||||||
break
|
break
|
||||||
deployer_records.append(target_deployer_record)
|
print("target_deployer_record", target_deployer_record)
|
||||||
else:
|
deployer_records.append(target_deployer_record)
|
||||||
deployer_record = laconic.get_record(deployer)
|
else:
|
||||||
if not deployer_record:
|
deployer_record = laconic.get_record(deployer)
|
||||||
fatal(f"Unable to locate deployer: {deployer}")
|
if not deployer_record:
|
||||||
|
fatal(f"Unable to locate deployer: {deployer}")
|
||||||
|
|
||||||
deployer_records.append(deployer_record)
|
deployer_records.append(deployer_record)
|
||||||
|
|
||||||
# Create and send request to each deployer
|
# Create and send request to each deployer
|
||||||
deployment_requests = []
|
deployment_requests = []
|
||||||
for deployer_record in deployer_records:
|
for deployer_record in deployer_records:
|
||||||
# If env_file
|
# Upload config to deployers if env_file is passed
|
||||||
if env_file:
|
if env_file:
|
||||||
|
tempdir = tempfile.mkdtemp()
|
||||||
|
try:
|
||||||
gpg = gnupg.GPG(gnupghome=tempdir)
|
gpg = gnupg.GPG(gnupghome=tempdir)
|
||||||
|
|
||||||
# Import the deployer's public key
|
# Import the deployer's public key
|
||||||
@ -194,59 +195,59 @@ def command( # noqa: C901
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
config_ref = response.json()["id"]
|
config_ref = response.json()["id"]
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tempdir, ignore_errors=True)
|
||||||
|
|
||||||
target_deployer = deployer
|
target_deployer = deployer
|
||||||
if (not deployer) and len(deployer_record.names):
|
if (not deployer) and len(deployer_record.names):
|
||||||
target_deployer = deployer_record.names[0]
|
target_deployer = deployer_record.names[0]
|
||||||
|
|
||||||
deployment_request = {
|
deployment_request = {
|
||||||
"record": {
|
"record": {
|
||||||
"type": "ApplicationDeploymentRequest",
|
"type": "ApplicationDeploymentRequest",
|
||||||
"application": app,
|
"application": app,
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"name": f"{app_record.attributes.name}@{app_record.attributes.version}",
|
"name": f"{app_record.attributes.name}@{app_record.attributes.version}",
|
||||||
"deployer": target_deployer,
|
"deployer": target_deployer,
|
||||||
"meta": {"when": str(datetime.utcnow())},
|
"meta": {"when": str(datetime.utcnow())},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if auction_id:
|
if auction_id:
|
||||||
deployment_request["record"]["auction"] = auction_id
|
deployment_request["record"]["auction"] = auction_id
|
||||||
|
|
||||||
if config_ref:
|
if config_ref:
|
||||||
deployment_request["record"]["config"] = {"ref": config_ref}
|
deployment_request["record"]["config"] = {"ref": config_ref}
|
||||||
|
|
||||||
if dns:
|
if dns:
|
||||||
deployment_request["record"]["dns"] = dns.lower()
|
deployment_request["record"]["dns"] = dns.lower()
|
||||||
|
|
||||||
if make_payment:
|
if make_payment:
|
||||||
amount = 0
|
amount = 0
|
||||||
if dry_run:
|
|
||||||
deployment_request["record"]["payment"] = "DRY_RUN"
|
|
||||||
elif "auto" == make_payment:
|
|
||||||
if "minimumPayment" in deployer_record.attributes:
|
|
||||||
amount = int(
|
|
||||||
deployer_record.attributes.minimumPayment.replace("alnt", "")
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
amount = make_payment
|
|
||||||
if amount:
|
|
||||||
receipt = laconic.send_tokens(
|
|
||||||
deployer_record.attributes.paymentAddress, amount
|
|
||||||
)
|
|
||||||
deployment_request["record"]["payment"] = receipt.tx.hash
|
|
||||||
print("Payment TX:", receipt.tx.hash)
|
|
||||||
elif use_payment:
|
|
||||||
deployment_request["record"]["payment"] = use_payment
|
|
||||||
|
|
||||||
deployment_requests.append(deployment_request)
|
|
||||||
|
|
||||||
# Send all requests
|
|
||||||
for deployment_request in deployment_requests:
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print(yaml.dump(deployment_request))
|
deployment_request["record"]["payment"] = "DRY_RUN"
|
||||||
continue
|
elif "auto" == make_payment:
|
||||||
|
if "minimumPayment" in deployer_record.attributes:
|
||||||
|
amount = int(
|
||||||
|
deployer_record.attributes.minimumPayment.replace("alnt", "")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
amount = make_payment
|
||||||
|
if amount:
|
||||||
|
receipt = laconic.send_tokens(
|
||||||
|
deployer_record.attributes.paymentAddress, amount
|
||||||
|
)
|
||||||
|
deployment_request["record"]["payment"] = receipt.tx.hash
|
||||||
|
print("Payment TX:", receipt.tx.hash)
|
||||||
|
elif use_payment:
|
||||||
|
deployment_request["record"]["payment"] = use_payment
|
||||||
|
|
||||||
laconic.publish(deployment_request)
|
deployment_requests.append(deployment_request)
|
||||||
finally:
|
|
||||||
shutil.rmtree(tempdir, ignore_errors=True)
|
# Send all requests
|
||||||
|
for deployment_request in deployment_requests:
|
||||||
|
if dry_run:
|
||||||
|
print(yaml.dump(deployment_request))
|
||||||
|
continue
|
||||||
|
|
||||||
|
laconic.publish(deployment_request)
|
||||||
|
Loading…
Reference in New Issue
Block a user