Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Honor publishing provider selection on AWS hosting (#1217)

Regan Bell1cdad4c49e76
diff --git a/cli/src/backends/aws.ts b/cli/src/backends/aws.ts
index 46ba01590..bc36f3a76 100644
--- a/cli/src/backends/aws.ts
+++ b/cli/src/backends/aws.ts
@@ -16,6 +16,7 @@ import {
import { CliError, dim, errMessage, header, note, ok, step, warn } from "../log.ts";
import {
awsWorkloadArchitecture,
+ requiresAwsMicrovmImage,
isDigestPinned,
sandboxCoreEnv,
securityScreenEnv,
@@ -269,6 +270,7 @@ export function guardLambdaMicrovms(e: unknown): never {
}
function assertAwsDeployImage(config: QmConfig): void {
+ if (!requiresAwsMicrovmImage(config)) return;
const aws = requireAws(config);
const { name, version } = deployImageCoordinates(config);
const expectedArn = `arn:aws:lambda:${aws.region}:${aws.accountId}:microvm-image:${name}`;
@@ -329,7 +331,7 @@ export function serviceEnvironment(config: QmConfig, service: ServiceName): Reco
if (service === "core") {
const sandboxBackend = config.env.core?.SANDBOX_BACKEND?.trim() || config.sandbox?.backend;
const stores = {
- DEPLOY_PROVIDER: "aws",
+ DEPLOY_PROVIDER: config.env.core?.DEPLOY_PROVIDER?.trim() || "aws",
AWS_DEPLOY_REGION: aws.region,
SESSION_STORE: "postgres",
RUN_STORE: "postgres",
diff --git a/cli/src/config.ts b/cli/src/config.ts
index 2913e8673..02b75c123 100644
--- a/cli/src/config.ts
+++ b/cli/src/config.ts
@@ -937,6 +937,18 @@ export function validatePortalTrust(config: QmConfig, path = "config", secrets?:
}
}
+export function requiresAwsMicrovmImage(config: QmConfig): boolean {
+ if (config.target !== "aws") return false;
+ const core = config.env.core;
+ if ((core?.DEPLOY_PROVIDER?.trim() || "aws") === "aws") return true;
+ if ((core?.SANDBOX_BACKEND?.trim() || config.sandbox?.backend || "aws") === "aws") return true;
+ const scopes: unknown = JSON.parse(core?.SANDBOX_SCOPE_BACKENDS || "{}");
+ if (!scopes || typeof scopes !== "object" || Array.isArray(scopes)) {
+ throw new CliError("SANDBOX_SCOPE_BACKENDS must be an object");
+ }
+ return Object.values(scopes).some((value) => typeof value === "string" && value.trim() === "aws");
+}
+
function validateAwsFrontDoor(config: QmConfig, path: string): void {
const hasPortal = config.services.includes("portal");
const hasWebUi = config.services.includes("web-ui");
@@ -949,7 +961,10 @@ function validateAwsFrontDoor(config: QmConfig, path: string): void {
throw new CliError(`${path}: AWS apiUrl must use the same protocol as publicUrl`);
}
const deployImage = config.env.core?.AWS_DEPLOY_IMAGE?.trim();
- if (isMissingOrPlaceholder(deployImage) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(deployImage!)) {
+ if (
+ (requiresAwsMicrovmImage(config) || Boolean(deployImage)) &&
+ (isMissingOrPlaceholder(deployImage) || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(deployImage!))
+ ) {
throw new CliError(
`${path}: AWS requires env.core.AWS_DEPLOY_IMAGE to name a non-placeholder, stack-owned Lambda MicroVM image`,
);
diff --git a/cli/src/terraform.ts b/cli/src/terraform.ts
index 325d47fa5..ba4214907 100644
--- a/cli/src/terraform.ts
+++ b/cli/src/terraform.ts
@@ -212,7 +212,7 @@ function derivedValues(
...(declared.includes("github_environment") ? { github_environment: aws.deployEnvironment ?? "" } : {}),
object_store_bucket: awsObjectStoreBucket(config),
transfer_lifecycle_prefix: `${config.env.core?.S3_PREFIX ?? ""}transfer/`,
- deploy_microvm_image: config.env.core!.AWS_DEPLOY_IMAGE!,
+ deploy_microvm_image: config.env.core?.AWS_DEPLOY_IMAGE?.trim() || config.orgId,
deploy_microvm_execution_role_arn:
config.env.core?.AWS_DEPLOY_EXEC_ROLE_ARN ?? `arn:aws:iam::${aws.accountId}:role/${aws.cluster}-microvm-exec`,
},
diff --git a/cli/test/aws.test.ts b/cli/test/aws.test.ts
index 11391b0ec..cbdbfac58 100644
--- a/cli/test/aws.test.ts
+++ b/cli/test/aws.test.ts
@@ -572,6 +572,24 @@ test("AWS environment derives identity, public URLs, private wiring, and MicroVM
assert.equal(core.PORT, "8080");
});
+test("AWS hosting preserves an explicit publishing provider independently of sandbox selection", () => {
+ for (const sandbox of [config.sandbox, undefined]) {
+ for (const provider of ["fly", "porter"]) {
+ const selected: QmConfig = {
+ ...config,
+ sandbox,
+ env: { ...config.env, core: { ...config.env.core, DEPLOY_PROVIDER: provider } },
+ };
+ const core = serviceEnvironment(selected, "core");
+ assert.equal(core.DEPLOY_PROVIDER, provider);
+ assert.equal(core.SANDBOX_BACKEND, sandbox?.backend ?? "aws");
+ assert.equal(core.SESSION_STORE, "postgres");
+ assert.equal(core.SNAPSHOT_STORE, "s3");
+ assert.equal(serviceEnvironment(selected, "portal").DEPLOY_PROVIDER, undefined);
+ }
+ }
+});
+
test("a configured bot identity lands in the AWS core task env and only there", () => {
const branded = { ...config, botName: "straylight", orgName: "Straylight Industries" };
const core = serviceEnvironment(branded, "core");
diff --git a/cli/test/config.test.ts b/cli/test/config.test.ts
index 5b28596c7..2b1d103e7 100644
--- a/cli/test/config.test.ts
+++ b/cli/test/config.test.ts
@@ -606,6 +606,26 @@ test("AWS validates release labels, unique coordinates, Fargate sizes, and owned
networking: { cloudMapNamespace: "acme.internal" },
services: { core: service },
};
+ for (const scopeBackend of ["modal", "aws"]) {
+ withConfig(
+ {
+ target: "aws",
+ aws,
+ env: {
+ core: {
+ DEPLOY_PROVIDER: "fly",
+ SANDBOX_BACKEND: "sprites",
+ AWS_DEPLOY_IMAGE: "",
+ SANDBOX_SCOPE_BACKENDS: JSON.stringify({ personal: scopeBackend }),
+ },
+ },
+ },
+ ({ path }) => {
+ if (scopeBackend === "aws") assert.throws(() => loadConfigAt(path), /AWS_DEPLOY_IMAGE/);
+ else assert.equal(loadConfigAt(path).config.env.core?.DEPLOY_PROVIDER, "fly");
+ },
+ );
+ }
withConfig({ target: "aws", aws }, ({ path }) =>
assert.equal(loadConfigAt(path).config.aws?.imageLabel, "release-1"),
);
diff --git a/cli/test/terraform.test.ts b/cli/test/terraform.test.ts
index 1d3ddbd80..45920ee74 100644
--- a/cli/test/terraform.test.ts
+++ b/cli/test/terraform.test.ts
@@ -489,6 +489,17 @@ test("GitHub environments remain compatible with AWS scaffolds created before th
);
});
+test("AWS Terraform renders valid reserved coordinates without an unused MicroVM image", () => {
+ const selected: QmConfig = {
+ ...config,
+ env: { core: { DEPLOY_PROVIDER: "fly", SANDBOX_BACKEND: "sprites" } },
+ };
+ const rendered = terraformVars(selected, "", declared);
+ assert.match(rendered, /deploy_microvm_image\s*= "acme"/);
+ assert.doesNotMatch(rendered, /undefined/);
+ assert.deepEqual(terraformVarsDrift(selected, rendered, declared), []);
+});
+
test("terraform derives the transfer lifecycle prefix from the same core S3 prefix as runtime", () => {
const unprefixed = terraformVars(config, "", declared);
assert.match(unprefixed, /transfer_lifecycle_prefix\s*= "transfer\/"/);