@mp-lb/arcnet 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +7 -53
  2. package/dist/arcnetConfig.d.ts +55 -0
  3. package/dist/arcnetConfig.d.ts.map +1 -0
  4. package/dist/arcnetConfig.js +53 -0
  5. package/dist/arcnetConfig.js.map +1 -0
  6. package/dist/ciOutputs.d.ts.map +1 -1
  7. package/dist/ciOutputs.js +26 -0
  8. package/dist/ciOutputs.js.map +1 -1
  9. package/dist/compileArcnet.d.ts +78 -0
  10. package/dist/compileArcnet.d.ts.map +1 -0
  11. package/dist/compileArcnet.js +60 -0
  12. package/dist/compileArcnet.js.map +1 -0
  13. package/dist/createCli.d.ts.map +1 -1
  14. package/dist/createCli.js +17 -4
  15. package/dist/createCli.js.map +1 -1
  16. package/dist/environment/grantDomainOwner.d.ts.map +1 -1
  17. package/dist/environment/grantDomainOwner.js.map +1 -1
  18. package/dist/resolveEnvironment.d.ts +21 -0
  19. package/dist/resolveEnvironment.d.ts.map +1 -0
  20. package/dist/resolveEnvironment.js +37 -0
  21. package/dist/resolveEnvironment.js.map +1 -0
  22. package/dist/runTerraform.d.ts.map +1 -1
  23. package/dist/runTerraform.js +57 -10
  24. package/dist/runTerraform.js.map +1 -1
  25. package/dist/runVercel.d.ts.map +1 -1
  26. package/dist/runVercel.js +16 -3
  27. package/dist/runVercel.js.map +1 -1
  28. package/dist/secrets/config.d.ts +16 -6
  29. package/dist/secrets/config.d.ts.map +1 -1
  30. package/dist/secrets/config.js +59 -6
  31. package/dist/secrets/config.js.map +1 -1
  32. package/dist/secrets/createSecretsCommands.d.ts.map +1 -1
  33. package/dist/secrets/createSecretsCommands.js +12 -10
  34. package/dist/secrets/createSecretsCommands.js.map +1 -1
  35. package/dist/secrets/loadSecrets.d.ts.map +1 -1
  36. package/dist/secrets/loadSecrets.js +2 -2
  37. package/dist/secrets/loadSecrets.js.map +1 -1
  38. package/dist/secrets/provisionSource.d.ts +12 -2
  39. package/dist/secrets/provisionSource.d.ts.map +1 -1
  40. package/dist/secrets/provisionSource.js +42 -7
  41. package/dist/secrets/provisionSource.js.map +1 -1
  42. package/dist/secrets/readRemoteSource.js +1 -1
  43. package/dist/secrets/readRemoteSource.js.map +1 -1
  44. package/dist/secrets/syncSecrets.d.ts +7 -0
  45. package/dist/secrets/syncSecrets.d.ts.map +1 -1
  46. package/dist/secrets/syncSecrets.js +36 -2
  47. package/dist/secrets/syncSecrets.js.map +1 -1
  48. package/dist/secrets/withDeploymentSecrets.d.ts.map +1 -1
  49. package/dist/secrets/withDeploymentSecrets.js +11 -5
  50. package/dist/secrets/withDeploymentSecrets.js.map +1 -1
  51. package/dist/secrets/writeSecretsWorkflow.d.ts.map +1 -1
  52. package/dist/secrets/writeSecretsWorkflow.js +5 -4
  53. package/dist/secrets/writeSecretsWorkflow.js.map +1 -1
  54. package/dist/setup.d.ts.map +1 -1
  55. package/dist/setup.js +12 -0
  56. package/dist/setup.js.map +1 -1
  57. package/dist/setupArcnet.d.ts +2 -0
  58. package/dist/setupArcnet.d.ts.map +1 -0
  59. package/dist/setupArcnet.js +63 -0
  60. package/dist/setupArcnet.js.map +1 -0
  61. package/docs/public/commands.md +6 -4
  62. package/docs/public/llms-full.txt +13 -57
  63. package/environments/mp-lb.yaml +76 -0
  64. package/package.json +3 -2
  65. package/src/arcnetConfig.ts +68 -0
  66. package/src/ciOutputs.ts +36 -0
  67. package/src/compileArcnet.ts +82 -0
  68. package/src/createCli.ts +45 -11
  69. package/src/environment/grantDomainOwner.ts +16 -3
  70. package/src/resolveEnvironment.ts +50 -0
  71. package/src/runTerraform.ts +75 -10
  72. package/src/runVercel.ts +29 -3
  73. package/src/secrets/config.ts +69 -8
  74. package/src/secrets/createSecretsCommands.ts +30 -38
  75. package/src/secrets/loadSecrets.ts +12 -4
  76. package/src/secrets/provisionSource.ts +69 -16
  77. package/src/secrets/readRemoteSource.ts +1 -1
  78. package/src/secrets/syncSecrets.ts +52 -6
  79. package/src/secrets/withDeploymentSecrets.ts +18 -8
  80. package/src/secrets/writeSecretsWorkflow.ts +7 -5
  81. package/src/setup.ts +19 -0
  82. package/src/setupArcnet.ts +96 -0
@@ -0,0 +1,76 @@
1
+ name: mp-lb
2
+ region: asia-southeast1
3
+ aws-region: ap-southeast-1
4
+ gcp-project: arcnet-{slug}
5
+ network-project: arcnet-platform
6
+ billing-account: 01D217-1685AF-7C9109
7
+ dns:
8
+ zone: mp-lb.dev
9
+ env:
10
+ resolver: "false"
11
+ public-file: .arcnet/unused.env
12
+ backend:
13
+ gcs:
14
+ bucket: arcnet-platform-terraform-state
15
+ prefix: terraform/state/{slug}
16
+ registry: "{region}-docker.pkg.dev/{gcp-project}/{slug}"
17
+ providers:
18
+ google:
19
+ source: hashicorp/google
20
+ version: ~> 5.0
21
+ config:
22
+ project: "{gcp-project}"
23
+ region: "{region}"
24
+ default_labels:
25
+ source: arcnet
26
+ project: "{slug}"
27
+ user_project_override: true
28
+ billing_project: "{network-project}"
29
+ cloudflare:
30
+ source: cloudflare/cloudflare
31
+ version: ~> 4.0
32
+ config:
33
+ api_token: "{{cred.CLOUDFLARE_API_TOKEN}}"
34
+ vercel:
35
+ source: vercel/vercel
36
+ version: ~> 1.0
37
+ config:
38
+ api_token: "{{cred.VERCEL_API_TOKEN}}"
39
+ mongodbatlas:
40
+ source: mongodb/mongodbatlas
41
+ version: ~> 1.0
42
+ config:
43
+ public_key: "{{cred.MONGODB_ATLAS_PUBLIC_KEY}}"
44
+ private_key: "{{cred.MONGODB_ATLAS_PRIVATE_KEY}}"
45
+ aws:
46
+ source: hashicorp/aws
47
+ version: ~> 5.0
48
+ config:
49
+ region: "{aws-region}"
50
+ default_tags:
51
+ tags:
52
+ source: arcnet
53
+ project: "{slug}"
54
+ access_key: "{{cred.ARC_AWS_ACCESS_KEY_ID}}"
55
+ secret_key: "{{cred.ARC_AWS_SECRET_ACCESS_KEY}}"
56
+ module-defaults:
57
+ github-ci:
58
+ gcp-project-id: "{gcp-project}"
59
+ state-bucket: arcnet-platform-terraform-state
60
+ network-project: ""
61
+ billing-account: "{billing-account}"
62
+ gcp-project:
63
+ project-id: "{gcp-project}"
64
+ billing-account: "{billing-account}"
65
+ gcp-budget:
66
+ billing-account: "{billing-account}"
67
+ gcp-project: "{gcp-project}"
68
+ currency: AUD
69
+ project-base:
70
+ region: "{region}"
71
+ cloud-run-web:
72
+ gcp-project-id: "{gcp-project}"
73
+ region: "{region}"
74
+ shared-mongo-atlas:
75
+ atlas-project-id: 69574e5a53349040d2f5a789
76
+ cluster-host: cluster0.qmcjryf.mongodb.net
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mp-lb/arcnet",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
4
4
  "description": "ArcNet project installation and deployment CLI.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,6 +21,7 @@
21
21
  "files": [
22
22
  "dist",
23
23
  "templates",
24
+ "environments",
24
25
  "README.md",
25
26
  "docs/public",
26
27
  "src"
@@ -35,7 +36,7 @@
35
36
  },
36
37
  "dependencies": {
37
38
  "@mp-lb/forum-secrets": "0.2.1",
38
- "@mp-lb/zapper": "0.21.3",
39
+ "@mp-lb/zapper": "0.21.4",
39
40
  "commander": "14.0.3",
40
41
  "yaml": "2.8.1",
41
42
  "zod": "4.4.1"
@@ -0,0 +1,68 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parse } from "yaml";
4
+ import { z } from "zod";
5
+ import { deployBlockSchema } from "@mp-lb/zapper/dist/arc/schemas.js";
6
+ import { vercelInputSchema } from "./schemas.js";
7
+ import { secretsConfigSchema, simpleSourceSchema } from "./secrets/config.js";
8
+
9
+ const slug = z
10
+ .string()
11
+ .regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/)
12
+ .max(23);
13
+
14
+ const repository = z.string().regex(/^[\w.-]+\/[\w.-]+$/);
15
+ const variables = z.record(z.string().regex(/^[A-Z_][A-Z0-9_]*$/), z.string());
16
+
17
+ const arcnetConfigSchema = z
18
+ .object({
19
+ version: z.literal(1),
20
+ project: slug,
21
+ environment: z.string().default("mp-lb"),
22
+ repository,
23
+ approved: z.boolean().default(false),
24
+ services: z.record(z.string(), z.unknown()).optional(),
25
+ infrastructure: z.record(z.string(), z.unknown()).optional(),
26
+ identity: z
27
+ .object({
28
+ workloadIdentityProvider: z.string().default(""),
29
+ serviceAccount: z.string().default(""),
30
+ })
31
+ .strict()
32
+ .optional(),
33
+ vercel: vercelInputSchema.omit({ repository: true }).optional(),
34
+ variables: variables.optional(),
35
+ secrets: z
36
+ .object({
37
+ sources: z.array(simpleSourceSchema).min(1),
38
+ consumers: secretsConfigSchema.shape.consumers,
39
+ })
40
+ .strict()
41
+ .optional(),
42
+ })
43
+ .strict()
44
+ .refine(
45
+ (config) => !config.vercel || !config.services,
46
+ "Vercel references and Terraform services cannot yet be combined.",
47
+ );
48
+
49
+ export type ArcnetConfig = z.infer<typeof arcnetConfigSchema>;
50
+
51
+ export const arcnetConfigPath = (root: string) =>
52
+ join(root, ".arcnet/arcnet.yaml");
53
+
54
+ export const hasArcnetConfig = (root: string) =>
55
+ existsSync(arcnetConfigPath(root));
56
+
57
+ export const readArcnetConfig = (root: string): ArcnetConfig => {
58
+ const config = arcnetConfigSchema.parse(
59
+ parse(readFileSync(arcnetConfigPath(root), "utf8")),
60
+ );
61
+
62
+ if (config.services || config.infrastructure)
63
+ deployBlockSchema.parse({
64
+ services: config.services ?? {},
65
+ project: config.infrastructure ?? {},
66
+ });
67
+ return config;
68
+ };
package/src/ciOutputs.ts CHANGED
@@ -4,8 +4,44 @@ import { parse } from "yaml";
4
4
  import { z } from "zod";
5
5
  import { terraformConfigSchema } from "./schemas.js";
6
6
  import { validateConfig } from "./validateConfig.js";
7
+ import { hasArcnetConfig, readArcnetConfig } from "./arcnetConfig.js";
8
+ import { compileTerraform, compileVercel } from "./compileArcnet.js";
7
9
 
8
10
  export const ciOutputs = (root: string): Record<string, string> => {
11
+ if (hasArcnetConfig(root)) {
12
+ const config = readArcnetConfig(root);
13
+
14
+ if (config.vercel) {
15
+ const site = validateConfig(compileVercel(config), root);
16
+ return {
17
+ approved: String(
18
+ site.approved &&
19
+ Object.values(site.sites).every((item) => item.mode === "existing"),
20
+ ),
21
+ };
22
+ }
23
+
24
+ if (!config.services) return { approved: "false" };
25
+ const compiled = compileTerraform(config);
26
+ const identity = compiled.identity;
27
+ if (
28
+ config.approved &&
29
+ (!/^projects\/\d+\/locations\/global\/workloadIdentityPools\/github\/providers\/github-actions$/.test(
30
+ identity.workloadIdentityProvider,
31
+ ) ||
32
+ !/^arc-deploy@[a-z][a-z0-9-]+\.iam\.gserviceaccount\.com$/.test(
33
+ identity.serviceAccount,
34
+ ))
35
+ )
36
+ throw new Error("Complete WIF configuration before approval.");
37
+ return {
38
+ approved: String(config.approved),
39
+ provider: config.approved ? identity.workloadIdentityProvider : "",
40
+ account: config.approved ? identity.serviceAccount : "",
41
+ registry: `${compiled.network.region}-docker.pkg.dev`,
42
+ };
43
+ }
44
+
9
45
  const input: unknown = JSON.parse(
10
46
  readFileSync(join(root, ".arcnet/project.json"), "utf8"),
11
47
  );
@@ -0,0 +1,82 @@
1
+ import { deployBlockSchema } from "@mp-lb/zapper/dist/arc/schemas.js";
2
+ import type { ArcnetConfig } from "./arcnetConfig.js";
3
+ import { resolveEnvironment } from "./resolveEnvironment.js";
4
+ import { vercelConfigSchema } from "./schemas.js";
5
+
6
+ export const arcnetMode = (config: ArcnetConfig) =>
7
+ config.vercel ? "vercel" : config.services ? "terraform" : "package";
8
+
9
+ export const compileVercel = (config: ArcnetConfig) => {
10
+ if (!config.vercel) throw new Error("No Vercel sites selected.");
11
+ return vercelConfigSchema.parse({
12
+ version: 1,
13
+ mode: "vercel",
14
+ slug: config.project,
15
+ repository: config.repository,
16
+ approved: config.approved,
17
+ ...config.vercel,
18
+ });
19
+ };
20
+
21
+ export const compileTerraform = (config: ArcnetConfig) => {
22
+ if (!config.services || !Object.keys(config.services).length)
23
+ throw new Error("No Terraform services selected.");
24
+ if (config.vercel)
25
+ throw new Error(
26
+ "Vercel references cannot yet be mixed with Terraform services.",
27
+ );
28
+ const services = deployBlockSchema.shape.services.parse(config.services);
29
+ if (
30
+ Object.values(services).some((service) => service.module === "gce-worker")
31
+ )
32
+ throw new Error(
33
+ "GCE workers are deferred until the startup module is replaced.",
34
+ );
35
+
36
+ for (const [name, service] of Object.entries(services)) {
37
+ if (
38
+ ["cloud-run-web", "gce-worker"].includes(service.module) &&
39
+ !service.dockerfile
40
+ )
41
+ service.dockerfile = `.arcnet/${name}.Dockerfile`;
42
+ if (
43
+ ["cloud-run-web", "vercel-static"].includes(service.module) &&
44
+ !service.domain
45
+ )
46
+ service.domain = `${["frontend", "web", "landing-page"].includes(name) ? "" : `${name === "backend" ? "api" : name}.`}${config.project}.mp-lb.dev`;
47
+ }
48
+
49
+ const modules = Object.values(services).map((service) => service.module);
50
+ const network = resolveEnvironment(config.environment, modules);
51
+ for (const service of Object.values(services))
52
+ if (service.module === "vercel-static")
53
+ service.module = "./node_modules/@mp-lb/arcnet/templates/vercel-static";
54
+
55
+ const infrastructure = deployBlockSchema.shape.project.parse(
56
+ config.infrastructure ?? {},
57
+ );
58
+
59
+ const project = {
60
+ gcp: { module: "gcp-project" },
61
+ registry: { module: "project-base", "depends-on": ["gcp"] },
62
+ ci: {
63
+ module: "github-ci",
64
+ "depends-on": ["gcp"],
65
+ params: { repository: config.repository },
66
+ },
67
+ ...infrastructure,
68
+ };
69
+
70
+ const deployment = deployBlockSchema.parse({ project, services });
71
+
72
+ const identity = config.identity ?? {
73
+ workloadIdentityProvider: "",
74
+ serviceAccount: `arc-deploy@arcnet-${config.project}.iam.gserviceaccount.com`,
75
+ };
76
+
77
+ return {
78
+ deployment,
79
+ network,
80
+ identity,
81
+ };
82
+ };
package/src/createCli.ts CHANGED
@@ -12,6 +12,8 @@ import { runVercel } from "./runVercel.js";
12
12
  import { setup } from "./setup.js";
13
13
  import { createSecretsCommands } from "./secrets/createSecretsCommands.js";
14
14
  import { withDeploymentSecrets } from "./secrets/withDeploymentSecrets.js";
15
+ import { hasArcnetConfig, readArcnetConfig } from "./arcnetConfig.js";
16
+ import { arcnetMode } from "./compileArcnet.js";
15
17
 
16
18
  export const createCli = () => {
17
19
  const cli = new Command("arcnet")
@@ -40,13 +42,30 @@ export const createCli = () => {
40
42
  .command("environment")
41
43
  .description("Manage ArcNet environment prerequisites.")
42
44
  .command("domain-owner")
43
- .description("Grant a deploy identity ownership of an already verified base domain.")
45
+ .description(
46
+ "Grant a deploy identity ownership of an already verified base domain.",
47
+ )
44
48
  .requiredOption("--domain <domain>", "Verified base domain")
45
49
  .requiredOption("--email <email>", "Deploy service account email")
46
- .requiredOption("--quota-project <id>", "GCP project with Site Verification API enabled")
47
- .action(async (options: { domain: string; email: string; quotaProject: string }) => {
48
- output(await grantDomainOwner(options.domain, options.email, options.quotaProject));
49
- });
50
+ .requiredOption(
51
+ "--quota-project <id>",
52
+ "GCP project with Site Verification API enabled",
53
+ )
54
+ .action(
55
+ async (options: {
56
+ domain: string;
57
+ email: string;
58
+ quotaProject: string;
59
+ }) => {
60
+ output(
61
+ await grantDomainOwner(
62
+ options.domain,
63
+ options.email,
64
+ options.quotaProject,
65
+ ),
66
+ );
67
+ },
68
+ );
50
69
 
51
70
  cli
52
71
  .command("version")
@@ -92,15 +111,29 @@ export const createCli = () => {
92
111
  command.action(async (site: unknown) => {
93
112
  const root = realpathSync(cli.opts().root);
94
113
 
95
- const mode = z
96
- .object({ mode: z.string().optional() })
97
- .parse(
98
- JSON.parse(readFileSync(join(root, ".arcnet/project.json"), "utf8")),
99
- ).mode;
114
+ const mode = hasArcnetConfig(root)
115
+ ? arcnetMode(readArcnetConfig(root))
116
+ : z
117
+ .object({ mode: z.string().optional() })
118
+ .parse(
119
+ JSON.parse(
120
+ readFileSync(join(root, ".arcnet/project.json"), "utf8"),
121
+ ),
122
+ ).mode;
100
123
 
101
124
  const machine = Boolean(cli.opts().json || cli.opts().jsonl);
102
125
 
103
126
  const execute = async () => {
127
+ if (mode === "package") {
128
+ if (name === "check" || name === "plan")
129
+ return {
130
+ operation: name,
131
+ message:
132
+ "Package-only ArcNet configuration is valid; no cloud deployment selected.",
133
+ };
134
+ throw new Error("This project has no ArcNet deployment services.");
135
+ }
136
+
104
137
  if (mode === "vercel")
105
138
  return runVercel(
106
139
  name,
@@ -116,7 +149,8 @@ export const createCli = () => {
116
149
  };
117
150
 
118
151
  output(
119
- await (name === "check" || (name === "plan" && mode === "vercel")
152
+ await (name === "check" ||
153
+ (name === "plan" && (mode === "vercel" || mode === "package"))
120
154
  ? execute()
121
155
  : withDeploymentSecrets(
122
156
  root,
@@ -30,13 +30,17 @@ export const grantDomainOwner = async (
30
30
  { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] },
31
31
  )
32
32
  ).trim();
33
+
33
34
  const request = dependencies.request ?? fetch;
34
35
  const base = "https://www.googleapis.com/siteVerification/v1/webResource";
36
+
35
37
  const headers = {
36
38
  Authorization: `Bearer ${token}`,
37
39
  "x-goog-user-project": quotaProject,
38
40
  };
41
+
39
42
  const list = await request(base, { headers });
43
+
40
44
  if (!list.ok) {
41
45
  if (list.status === 403)
42
46
  throw new Error(
@@ -46,16 +50,20 @@ export const grantDomainOwner = async (
46
50
  }
47
51
 
48
52
  const { items = [] } = (await list.json()) as { items?: WebResource[] };
53
+
49
54
  const resource = items.find(
50
55
  ({ site }) =>
51
56
  site.type === "INET_DOMAIN" &&
52
57
  site.identifier.toLowerCase() === domain.toLowerCase(),
53
58
  );
59
+
54
60
  if (!resource)
55
61
  throw new Error(
56
62
  `${domain} is not verified for the signed-in Google identity. Verify the base domain with a DNS TXT record first.`,
57
63
  );
58
- if (resource.owners.some((owner) => owner.toLowerCase() === email.toLowerCase()))
64
+ if (
65
+ resource.owners.some((owner) => owner.toLowerCase() === email.toLowerCase())
66
+ )
59
67
  return { domain, email, changed: false };
60
68
 
61
69
  const update = await request(`${base}/${encodeURIComponent(resource.id)}`, {
@@ -63,10 +71,15 @@ export const grantDomainOwner = async (
63
71
  headers: { ...headers, "Content-Type": "application/json" },
64
72
  body: JSON.stringify({ ...resource, owners: [...resource.owners, email] }),
65
73
  });
74
+
66
75
  if (!update.ok)
67
- throw new Error(`Google Site Verification owner update failed (${update.status}).`);
76
+ throw new Error(
77
+ `Google Site Verification owner update failed (${update.status}).`,
78
+ );
68
79
  const result = (await update.json()) as WebResource;
69
- if (!result.owners.some((owner) => owner.toLowerCase() === email.toLowerCase()))
80
+ if (
81
+ !result.owners.some((owner) => owner.toLowerCase() === email.toLowerCase())
82
+ )
70
83
  throw new Error("Google did not confirm the new domain owner.");
71
84
  return { domain, email, changed: true };
72
85
  };
@@ -0,0 +1,50 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parse } from "yaml";
4
+ import { networkConfigSchema } from "@mp-lb/zapper/dist/arc/schemas.js";
5
+ import { packageRoot } from "./packageInfo.js";
6
+
7
+ export const resolveEnvironment = (name: string, modules: string[]) => {
8
+ if (name !== "mp-lb") throw new Error(`Unknown ArcNet environment: ${name}.`);
9
+
10
+ const network = networkConfigSchema.parse(
11
+ parse(readFileSync(join(packageRoot, "environments/mp-lb.yaml"), "utf8")),
12
+ );
13
+
14
+ const required: Record<string, string[]> = {
15
+ "cloud-run-web": ["google", "cloudflare"],
16
+ "gce-worker": ["google"],
17
+ "vercel-static": ["vercel", "cloudflare"],
18
+ "shared-mongo-atlas": ["mongodbatlas"],
19
+ "upstash-redis": ["upstash"],
20
+ "aws-s3": ["aws"],
21
+ };
22
+
23
+ const providers = new Set([
24
+ "google",
25
+ ...modules.flatMap((module) => required[module] ?? []),
26
+ ]);
27
+
28
+ network.providers = Object.fromEntries(
29
+ [...providers].map((provider) => {
30
+ const config = network.providers[provider];
31
+ if (!config) throw new Error(`Environment lacks provider ${provider}.`);
32
+ return [provider, config];
33
+ }),
34
+ );
35
+
36
+ const defaults = new Set([
37
+ "github-ci",
38
+ "gcp-project",
39
+ "project-base",
40
+ ...modules,
41
+ ]);
42
+
43
+ network["module-defaults"] = Object.fromEntries(
44
+ Object.entries(network["module-defaults"]).filter(([key]) =>
45
+ defaults.has(key),
46
+ ),
47
+ );
48
+
49
+ return network;
50
+ };
@@ -15,7 +15,9 @@ import {
15
15
  import { createRequire } from "node:module";
16
16
  import { devNull, tmpdir } from "node:os";
17
17
  import { dirname, join, resolve } from "node:path";
18
- import { parse } from "yaml";
18
+ import { parse, stringify } from "yaml";
19
+ import { hasArcnetConfig, readArcnetConfig } from "./arcnetConfig.js";
20
+ import { compileTerraform } from "./compileArcnet.js";
19
21
  import { runProcess } from "./runProcess.js";
20
22
  import { resolvePublicEnv } from "./resolvePublicEnv.js";
21
23
  import { envPoolSchema, terraformConfigSchema } from "./schemas.js";
@@ -28,11 +30,39 @@ export const runTerraform = (
28
30
  ) => {
29
31
  const here = join(root, ".arcnet");
30
32
  const read = (name: string) => readFileSync(join(here, name), "utf8");
31
- const config = terraformConfigSchema.parse(JSON.parse(read("project.json")));
33
+ const modern = hasArcnetConfig(root) ? readArcnetConfig(root) : undefined;
34
+ const compiled = modern ? compileTerraform(modern) : undefined;
35
+
36
+ const legacy = modern
37
+ ? undefined
38
+ : terraformConfigSchema.parse(JSON.parse(read("project.json")));
39
+
40
+ const config = {
41
+ slug: modern?.project ?? legacy!.slug,
42
+ repository: modern?.repository ?? legacy!.repository,
43
+ approved: modern?.approved ?? legacy!.approved,
44
+ services: modern ? Object.keys(modern.services ?? {}) : legacy!.services,
45
+ workloadIdentityProvider: modern
46
+ ? compiled!.identity.workloadIdentityProvider
47
+ : legacy!.workloadIdentityProvider,
48
+ serviceAccount: modern
49
+ ? compiled!.identity.serviceAccount
50
+ : legacy!.serviceAccount,
51
+ };
52
+
32
53
  const zap = parse(readFileSync(join(root, "zap.yaml"), "utf8"));
33
- const network = networkConfigSchema.parse(parse(read("network.yaml")));
34
- const deployment = deployBlockSchema.parse(zap.deploy);
35
- if (config.version !== 1 || zap.project !== config.slug)
54
+ if (modern && zap.deploy)
55
+ throw new Error(
56
+ "Remove the duplicate deploy block from zap.yaml; arcnet.yaml is authoritative.",
57
+ );
58
+
59
+ const network =
60
+ compiled?.network ?? networkConfigSchema.parse(parse(read("network.yaml")));
61
+
62
+ const deployment =
63
+ compiled?.deployment ?? deployBlockSchema.parse(zap.deploy);
64
+
65
+ if (zap.project !== config.slug)
36
66
  throw new Error("Project config does not match zap.yaml.");
37
67
  const services = Object.keys(deployment?.services ?? {});
38
68
  if (
@@ -55,9 +85,11 @@ export const runTerraform = (
55
85
  "Deployment manifest repository differs from project config.",
56
86
  );
57
87
 
58
- const publicEnv: unknown = existsSync(join(here, "env.production.json"))
59
- ? JSON.parse(read("env.production.json"))
60
- : {};
88
+ const publicEnv: unknown =
89
+ modern?.variables ??
90
+ (existsSync(join(here, "env.production.json"))
91
+ ? JSON.parse(read("env.production.json"))
92
+ : {});
61
93
 
62
94
  let secretEnv;
63
95
 
@@ -121,7 +153,19 @@ export const runTerraform = (
121
153
  "../arc",
122
154
  );
123
155
 
124
- const instances = resolveModules(loadManifest(root), modulesDir, root);
156
+ const manifest = compiled
157
+ ? {
158
+ slug: config.slug,
159
+ deploy: deployment,
160
+ localServiceNames: [
161
+ ...Object.keys(zap.native ?? {}),
162
+ ...Object.keys(zap.docker ?? {}),
163
+ ...Object.keys(zap.containers ?? {}),
164
+ ],
165
+ }
166
+ : loadManifest(root);
167
+
168
+ const instances = resolveModules(manifest, modulesDir, root);
125
169
  for (const instance of instances)
126
170
  for (const credential of instance.manifest.credentials)
127
171
  if (!process.env[credential.name])
@@ -163,13 +207,34 @@ export const runTerraform = (
163
207
  mode: 0o600,
164
208
  });
165
209
 
210
+ const networkFile = compiled
211
+ ? join(temporary, "environment.yaml")
212
+ : join(here, "network.yaml");
213
+
214
+ const manifestFile = compiled ? join(temporary, "zap.yaml") : undefined;
215
+
216
+ if (compiled) {
217
+ writeFileSync(networkFile, stringify(network));
218
+ writeFileSync(
219
+ manifestFile!,
220
+ stringify({
221
+ project: config.slug,
222
+ native: zap.native,
223
+ docker: zap.docker,
224
+ containers: zap.containers,
225
+ deploy: deployment,
226
+ }),
227
+ );
228
+ }
229
+
166
230
  runProcess(
167
231
  process.execPath,
168
232
  [executable, "arc", command],
169
233
  root,
170
234
  {
171
235
  ...process.env,
172
- ZAP_ARC_NETWORK_FILE: join(here, "network.yaml"),
236
+ ZAP_ARC_NETWORK_FILE: networkFile,
237
+ ...(manifestFile ? { ZAP_ARC_MANIFEST_FILE: manifestFile } : {}),
173
238
  ZAP_ARC_CONFIG: operator,
174
239
  },
175
240
  machine,
package/src/runVercel.ts CHANGED
@@ -7,6 +7,13 @@ import { inspectReferences } from "./inspectReferences.js";
7
7
  import { renderPlan } from "./renderPlan.js";
8
8
  import { runProcess } from "./runProcess.js";
9
9
  import { validateConfig } from "./validateConfig.js";
10
+ import { stringify } from "yaml";
11
+ import {
12
+ arcnetConfigPath,
13
+ hasArcnetConfig,
14
+ readArcnetConfig,
15
+ } from "./arcnetConfig.js";
16
+ import { compileVercel } from "./compileArcnet.js";
10
17
 
11
18
  export const runVercel = async (
12
19
  command: string,
@@ -14,9 +21,19 @@ export const runVercel = async (
14
21
  argument?: string,
15
22
  machine = false,
16
23
  ) => {
17
- const path = join(root, ".arcnet/project.json");
24
+ const modern = hasArcnetConfig(root) ? readArcnetConfig(root) : undefined;
25
+
26
+ const path = modern
27
+ ? arcnetConfigPath(root)
28
+ : join(root, ".arcnet/project.json");
29
+
18
30
  const original = readFileSync(path, "utf8");
19
- const config = validateConfig(JSON.parse(original), root);
31
+
32
+ const config = validateConfig(
33
+ modern ? compileVercel(modern) : JSON.parse(original),
34
+ root,
35
+ );
36
+
20
37
  if (command === "check" || command === "plan")
21
38
  return renderPlan(config, root);
22
39
  if (command === "create" && process.env.GITHUB_ACTIONS === "true")
@@ -51,7 +68,16 @@ export const runVercel = async (
51
68
  throw new Error(
52
69
  `Config changed during creation. Recover the created project ID ${next.sites[argument]!.projectId} manually; no local settings overwritten.`,
53
70
  );
54
- writeFileSync(`${path}.new`, JSON.stringify(next, null, 2) + "\n", {
71
+
72
+ const content = modern
73
+ ? stringify({
74
+ ...modern,
75
+ approved: false,
76
+ vercel: { ...modern.vercel, sites: next.sites },
77
+ })
78
+ : JSON.stringify(next, null, 2) + "\n";
79
+
80
+ writeFileSync(`${path}.new`, content, {
55
81
  flag: "wx",
56
82
  });
57
83