@mp-lb/arcnet 0.3.1 → 0.4.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 (75) hide show
  1. package/README.md +7 -53
  2. package/dist/arcnetConfig.d.ts +62 -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 +2 -0
  29. package/dist/secrets/config.d.ts.map +1 -1
  30. package/dist/secrets/config.js +22 -2
  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 +9 -8
  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.map +1 -1
  37. package/dist/secrets/provisionSource.d.ts.map +1 -1
  38. package/dist/secrets/provisionSource.js +4 -4
  39. package/dist/secrets/provisionSource.js.map +1 -1
  40. package/dist/secrets/syncSecrets.d.ts.map +1 -1
  41. package/dist/secrets/syncSecrets.js +11 -2
  42. package/dist/secrets/syncSecrets.js.map +1 -1
  43. package/dist/secrets/withDeploymentSecrets.d.ts.map +1 -1
  44. package/dist/secrets/withDeploymentSecrets.js +11 -5
  45. package/dist/secrets/withDeploymentSecrets.js.map +1 -1
  46. package/dist/secrets/writeSecretsWorkflow.d.ts.map +1 -1
  47. package/dist/secrets/writeSecretsWorkflow.js +5 -4
  48. package/dist/secrets/writeSecretsWorkflow.js.map +1 -1
  49. package/dist/setup.d.ts.map +1 -1
  50. package/dist/setup.js +12 -0
  51. package/dist/setup.js.map +1 -1
  52. package/dist/setupArcnet.d.ts +2 -0
  53. package/dist/setupArcnet.d.ts.map +1 -0
  54. package/dist/setupArcnet.js +63 -0
  55. package/dist/setupArcnet.js.map +1 -0
  56. package/docs/public/llms-full.txt +7 -53
  57. package/environments/mp-lb.yaml +76 -0
  58. package/package.json +3 -2
  59. package/src/arcnetConfig.ts +68 -0
  60. package/src/ciOutputs.ts +36 -0
  61. package/src/compileArcnet.ts +82 -0
  62. package/src/createCli.ts +45 -11
  63. package/src/environment/grantDomainOwner.ts +16 -3
  64. package/src/resolveEnvironment.ts +50 -0
  65. package/src/runTerraform.ts +75 -10
  66. package/src/runVercel.ts +29 -3
  67. package/src/secrets/config.ts +26 -2
  68. package/src/secrets/createSecretsCommands.ts +25 -31
  69. package/src/secrets/loadSecrets.ts +10 -2
  70. package/src/secrets/provisionSource.ts +12 -10
  71. package/src/secrets/syncSecrets.ts +12 -6
  72. package/src/secrets/withDeploymentSecrets.ts +18 -8
  73. package/src/secrets/writeSecretsWorkflow.ts +7 -5
  74. package/src/setup.ts +19 -0
  75. package/src/setupArcnet.ts +96 -0
@@ -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
 
@@ -1,4 +1,6 @@
1
- import { readFileSync } from "node:fs";
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parse } from "yaml";
2
4
  import { z } from "zod";
3
5
  import { safeTargetPath } from "../safeTargetPath.js";
4
6
 
@@ -75,11 +77,33 @@ export const secretsConfigSchema = z
75
77
  export type SecretsConfig = z.infer<typeof secretsConfigSchema>;
76
78
  export type SecretSource = z.infer<typeof sourceSchema>;
77
79
 
80
+ export const resolveSecretsConfigPath = (root: string, file?: string) =>
81
+ file ??
82
+ (existsSync(join(root, ".arcnet/arcnet.yaml"))
83
+ ? ".arcnet/arcnet.yaml"
84
+ : ".arcnet/secrets.json");
85
+
86
+ export const hasSecretsConfig = (root: string) => {
87
+ const modern = join(root, ".arcnet/arcnet.yaml");
88
+ if (existsSync(modern))
89
+ return Boolean(parse(readFileSync(modern, "utf8"))?.secrets);
90
+ return existsSync(join(root, ".arcnet/secrets.json"));
91
+ };
92
+
78
93
  export const readSecretsConfig = (
79
94
  root: string,
80
- file = ".arcnet/secrets.json",
95
+ file = resolveSecretsConfigPath(root),
81
96
  ): SecretsConfig => {
82
97
  try {
98
+ if (file === ".arcnet/arcnet.yaml") {
99
+ const config = parse(readFileSync(safeTargetPath(root, file), "utf8"));
100
+ return secretsConfigSchema.parse({
101
+ version: 1,
102
+ repository: config.repository,
103
+ ...config.secrets,
104
+ });
105
+ }
106
+
83
107
  return secretsConfigSchema.parse(
84
108
  JSON.parse(readFileSync(safeTargetPath(root, file), "utf8")),
85
109
  );
@@ -1,6 +1,6 @@
1
1
  import { Command } from "commander";
2
2
  import { realpathSync } from "node:fs";
3
- import { readSecretsConfig } from "./config.js";
3
+ import { readSecretsConfig, resolveSecretsConfigPath } from "./config.js";
4
4
  import { loadSecrets } from "./loadSecrets.js";
5
5
  import { provisionSource, type ProvisionOptions } from "./provisionSource.js";
6
6
  import { runWithSecrets } from "./runWithSecrets.js";
@@ -30,11 +30,7 @@ export const createSecretsCommands = (
30
30
  run: "Run a command with selected keys only; withhold child output.",
31
31
  }[action],
32
32
  )
33
- .option(
34
- "--config <file>",
35
- "Secrets source configuration",
36
- ".arcnet/secrets.json",
37
- )
33
+ .option("--config <file>", "Secrets source configuration")
38
34
  .option("--consumer <name>", "Named mapping in the secrets configuration")
39
35
  .option(
40
36
  "--live",
@@ -49,14 +45,19 @@ export const createSecretsCommands = (
49
45
  command.argument("<command...>", "Executable and arguments after --");
50
46
  command.action(async (...args: unknown[]) => {
51
47
  const options = command.opts<{
52
- config: string;
48
+ config?: string;
53
49
  consumer?: string;
54
50
  live?: boolean;
55
51
  password?: boolean;
56
52
  }>();
57
53
 
58
54
  const root = realpathSync(cli.opts().root);
59
- const config = readSecretsConfig(root, options.config);
55
+
56
+ const config = readSecretsConfig(
57
+ root,
58
+ resolveSecretsConfigPath(root, options.config),
59
+ );
60
+
60
61
  if (
61
62
  process.env.GITHUB_ACTIONS === "true" &&
62
63
  (process.env.GITHUB_REPOSITORY !== config.repository ||
@@ -66,12 +67,16 @@ export const createSecretsCommands = (
66
67
  "Secrets commands in CI require the configured repository main branch.",
67
68
  );
68
69
  if (options.password && process.env.GITHUB_ACTIONS === "true")
69
- throw new Error("Password decryption is local-only; CI must use file keys.");
70
+ throw new Error(
71
+ "Password decryption is local-only; CI must use file keys.",
72
+ );
70
73
  if (action !== "check" && !options.consumer)
71
74
  throw new Error("Choose --consumer to explicitly select output keys.");
75
+
72
76
  const password = options.password
73
77
  ? await promptPassword(Boolean(cli.opts().noninteractive))
74
78
  : undefined;
79
+
75
80
  const values = await loadSecrets(
76
81
  config,
77
82
  root,
@@ -145,11 +150,7 @@ export const createSecretsCommands = (
145
150
  "--repository <owner/repo>",
146
151
  "GitHub repository receiving the key",
147
152
  )
148
- .option(
149
- "--config <file>",
150
- "Secrets source configuration",
151
- ".arcnet/secrets.json",
152
- );
153
+ .option("--config <file>", "Secrets source configuration");
153
154
 
154
155
  if (mode === "add")
155
156
  command.option(
@@ -170,7 +171,10 @@ export const createSecretsCommands = (
170
171
  noninteractive: cli.opts().noninteractive,
171
172
  },
172
173
  realpathSync(cli.opts().root),
173
- command.opts().config,
174
+ resolveSecretsConfigPath(
175
+ realpathSync(cli.opts().root),
176
+ command.opts().config,
177
+ ),
174
178
  ),
175
179
  ),
176
180
  );
@@ -181,25 +185,15 @@ export const createSecretsCommands = (
181
185
  .description(
182
186
  "Refresh encrypted snapshots from Forum and regenerate validation CI; no decryption.",
183
187
  )
184
- .option(
185
- "--config <file>",
186
- "Secrets source configuration",
187
- ".arcnet/secrets.json",
188
- )
189
- .action((options: { config: string }) => {
188
+ .option("--config <file>", "Secrets source configuration")
189
+ .action((options: { config?: string }) => {
190
190
  const root = realpathSync(cli.opts().root);
191
191
 
192
- const result = syncSecrets(
193
- readSecretsConfig(root, options.config),
194
- root,
195
- options.config,
196
- );
192
+ const file = resolveSecretsConfigPath(root, options.config);
197
193
 
198
- writeSecretsWorkflow(
199
- readSecretsConfig(root, options.config),
200
- root,
201
- options.config,
202
- );
194
+ const result = syncSecrets(readSecretsConfig(root, file), root, file);
195
+
196
+ writeSecretsWorkflow(readSecretsConfig(root, file), root, file);
203
197
 
204
198
  output(result);
205
199
  });
@@ -37,13 +37,20 @@ export const loadSecrets = async (
37
37
  throw new Error("Snapshot integrity mismatch");
38
38
 
39
39
  let plaintext: string;
40
+
40
41
  if (password) {
41
42
  const temporary = mkdtempSync(join(tmpdir(), "arcnet-decrypt-"));
43
+
42
44
  try {
43
45
  const file = join(temporary, "source.json.enc");
44
46
  writeFileSync(file, text, { mode: 0o600 });
45
- plaintext = secretCommand("fm", ["decrypt", "--file", file], root,
46
- undefined, { ...environment, DOCTRINE_ENCRYPTION_PASSWORD: password });
47
+ plaintext = secretCommand(
48
+ "fm",
49
+ ["decrypt", "--file", file],
50
+ root,
51
+ undefined,
52
+ { ...environment, DOCTRINE_ENCRYPTION_PASSWORD: password },
53
+ );
47
54
  } finally {
48
55
  rmSync(temporary, { recursive: true, force: true });
49
56
  }
@@ -53,6 +60,7 @@ export const loadSecrets = async (
53
60
  recipientSecret: key!,
54
61
  });
55
62
  }
63
+
56
64
  const decoded: unknown = JSON.parse(plaintext);
57
65
 
58
66
  if (!decoded || Array.isArray(decoded) || typeof decoded !== "object")
@@ -10,6 +10,7 @@ import { tmpdir } from "node:os";
10
10
  import { join } from "node:path";
11
11
  import { safeTargetPath } from "../safeTargetPath.js";
12
12
  import {
13
+ hasSecretsConfig,
13
14
  readSecretsConfig,
14
15
  secretsConfigSchema,
15
16
  sourceSchema,
@@ -38,9 +39,9 @@ export const provisionSource = async (
38
39
  root: string,
39
40
  configFile: string,
40
41
  ) => {
41
- if (configFile !== ".arcnet/secrets.json")
42
+ if (![".arcnet/secrets.json", ".arcnet/arcnet.yaml"].includes(configFile))
42
43
  throw new Error(
43
- "Provisioning uses .arcnet/secrets.json so generated CI has a fixed entry point.",
44
+ "Provisioning uses an ArcNet configuration under .arcnet/.",
44
45
  );
45
46
  if (process.env.GITHUB_ACTIONS === "true")
46
47
  throw new Error(
@@ -56,14 +57,15 @@ export const provisionSource = async (
56
57
 
57
58
  const configPath = safeTargetPath(root, configFile);
58
59
 
59
- const config = existsSync(configPath)
60
- ? readSecretsConfig(root, configFile)
61
- : {
62
- version: 1 as const,
63
- repository: options.repository,
64
- sources: [],
65
- consumers: {},
66
- };
60
+ const config =
61
+ existsSync(configPath) && hasSecretsConfig(root)
62
+ ? readSecretsConfig(root, configFile)
63
+ : {
64
+ version: 1 as const,
65
+ repository: options.repository,
66
+ sources: [],
67
+ consumers: {},
68
+ };
67
69
 
68
70
  if (config.repository !== options.repository)
69
71
  throw new Error("Repository differs from secrets configuration.");
@@ -1,10 +1,11 @@
1
1
  import { parseForumEncryptedFilePayload } from "@mp-lb/forum-secrets";
2
2
  import { createHash } from "node:crypto";
3
- import { mkdirSync, renameSync, writeFileSync } from "node:fs";
3
+ import { mkdirSync, renameSync, writeFileSync, readFileSync } from "node:fs";
4
4
  import { dirname } from "node:path";
5
5
  import { safeTargetPath } from "../safeTargetPath.js";
6
6
  import type { SecretsConfig } from "./config.js";
7
7
  import { readRemoteSource } from "./readRemoteSource.js";
8
+ import { parseDocument } from "yaml";
8
9
 
9
10
  export const syncSecrets = (
10
11
  config: SecretsConfig,
@@ -41,11 +42,16 @@ export const syncSecrets = (
41
42
  const target = safeTargetPath(root, file);
42
43
  mkdirSync(dirname(target), { recursive: true });
43
44
  const temporary = safeTargetPath(root, `${file}.tmp`);
44
- writeFileSync(
45
- temporary,
46
- JSON.stringify({ ...config, sources }, null, 2) + "\n",
47
- { mode: 0o600 },
48
- );
45
+ let content = JSON.stringify({ ...config, sources }, null, 2) + "\n";
46
+
47
+ if (file === ".arcnet/arcnet.yaml") {
48
+ const document = parseDocument(readFileSync(target, "utf8"));
49
+ if (document.errors.length) throw new Error("Invalid arcnet.yaml.");
50
+ document.set("secrets", { sources, consumers: config.consumers });
51
+ content = document.toString();
52
+ }
53
+
54
+ writeFileSync(temporary, content, { mode: 0o600 });
49
55
 
50
56
  renameSync(temporary, target);
51
57
  return {
@@ -1,10 +1,12 @@
1
- import { existsSync, readFileSync } from "node:fs";
1
+ import { readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { parse } from "yaml";
4
- import { readSecretsConfig } from "./config.js";
4
+ import { hasSecretsConfig, readSecretsConfig } from "./config.js";
5
5
  import { loadSecrets } from "./loadSecrets.js";
6
6
  import { selectSecrets } from "./selectSecrets.js";
7
7
  import { promptPassword } from "./promptPassword.js";
8
+ import { hasArcnetConfig, readArcnetConfig } from "../arcnetConfig.js";
9
+ import { compileTerraform } from "../compileArcnet.js";
8
10
 
9
11
  export const withDeploymentSecrets = async <T>(
10
12
  root: string,
@@ -13,7 +15,7 @@ export const withDeploymentSecrets = async <T>(
13
15
  usePassword = false,
14
16
  noninteractive = false,
15
17
  ): Promise<T> => {
16
- if (!existsSync(join(root, ".arcnet/secrets.json"))) return action();
18
+ if (!hasSecretsConfig(root)) return action();
17
19
  const config = readSecretsConfig(root);
18
20
  if (
19
21
  process.env.GITHUB_ACTIONS === "true" &&
@@ -24,15 +26,23 @@ export const withDeploymentSecrets = async <T>(
24
26
  "Secrets commands in CI require the configured repository main branch.",
25
27
  );
26
28
  if (usePassword && process.env.GITHUB_ACTIONS === "true")
27
- throw new Error("Password decryption is local-only; CI must use file keys.");
28
- const password = usePassword ? await promptPassword(noninteractive) : undefined;
29
+ throw new Error(
30
+ "Password decryption is local-only; CI must use file keys.",
31
+ );
32
+
33
+ const password = usePassword
34
+ ? await promptPassword(noninteractive)
35
+ : undefined;
36
+
29
37
  const pool = await loadSecrets(config, root, process.env, false, password);
30
38
  const selected = selectSecrets(pool, config, "deploy");
31
39
 
32
40
  if (mode !== "vercel") {
33
- const manifest = parse(readFileSync(join(root, "zap.yaml"), "utf8")) as {
34
- deploy?: { services?: Record<string, { env?: string[] }> };
35
- };
41
+ const manifest = hasArcnetConfig(root)
42
+ ? { deploy: compileTerraform(readArcnetConfig(root)).deployment }
43
+ : (parse(readFileSync(join(root, "zap.yaml"), "utf8")) as {
44
+ deploy?: { services?: Record<string, { env?: string[] }> };
45
+ });
36
46
 
37
47
  const keys = Object.values(manifest.deploy?.services ?? {})
38
48
  .flatMap((service) => service.env ?? [])
@@ -15,16 +15,18 @@ export const writeSecretsWorkflow = (
15
15
  ".github/workflows/validate-arcnet-secrets.yaml",
16
16
  );
17
17
 
18
- const marker =
19
- "# Generated by arcnet secrets; configure sources in .arcnet/secrets.json.\n";
18
+ const marker = `# Generated by arcnet secrets; configure sources in ${configFile}.\n`;
20
19
 
21
- if (existsSync(path) && !readFileSync(path, "utf8").startsWith(marker))
20
+ if (
21
+ existsSync(path) &&
22
+ !readFileSync(path, "utf8").startsWith("# Generated by arcnet secrets;")
23
+ )
22
24
  throw new Error(
23
25
  "Existing validate-arcnet-secrets.yaml is not ArcNet-managed; move it before continuing.",
24
26
  );
25
- if (configFile !== ".arcnet/secrets.json")
27
+ if (![".arcnet/secrets.json", ".arcnet/arcnet.yaml"].includes(configFile))
26
28
  throw new Error(
27
- "Generated CI requires the standard .arcnet/secrets.json location.",
29
+ "Generated CI requires an ArcNet configuration under .arcnet/.",
28
30
  );
29
31
  mkdirSync(dirname(path), { recursive: true });
30
32
 
package/src/setup.ts CHANGED
@@ -19,6 +19,8 @@ import { resolveRepository } from "./resolveRepository.js";
19
19
  import { safeTargetPath } from "./safeTargetPath.js";
20
20
  import { selectNetwork } from "./selectNetwork.js";
21
21
  import { setupVercel } from "./setupVercel.js";
22
+ import { hasArcnetConfig, readArcnetConfig } from "./arcnetConfig.js";
23
+ import { setupArcnet } from "./setupArcnet.js";
22
24
 
23
25
  const home = packageRoot;
24
26
 
@@ -28,6 +30,23 @@ const json = (value: unknown) => JSON.stringify(value, null, 2) + "\n";
28
30
  export const setup = (args: string[], root = process.cwd()) => {
29
31
  const { slug, options, dry } = parseSetupInput(args);
30
32
  root = realpathSync(root);
33
+
34
+ if (hasArcnetConfig(root)) {
35
+ if (
36
+ Object.entries(options).some(
37
+ ([key, value]) => key.startsWith("seen-") && value,
38
+ ) ||
39
+ options.services ||
40
+ options.vercel
41
+ )
42
+ fail(
43
+ "arcnet.yaml owns service selection; do not pass legacy setup flags.",
44
+ );
45
+ const config = readArcnetConfig(root);
46
+ if (config.project !== slug) fail("Slug must match arcnet.yaml project.");
47
+ return setupArcnet(root, dry);
48
+ }
49
+
31
50
  const safe = (name: string) => safeTargetPath(root, name);
32
51
 
33
52
  if (!options.services) {