@crossdelta/infrastructure 0.12.1 → 0.12.3
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.
- package/bin/generate-env.mjs +12 -1
- package/bin/generate-env.ts +19 -9
- package/dist/index.cjs +2 -6
- package/dist/index.js +2 -6
- package/package.json +1 -1
package/bin/generate-env.mjs
CHANGED
|
@@ -94,6 +94,13 @@ var getLocalUrl = (config) => {
|
|
|
94
94
|
}
|
|
95
95
|
return `http://localhost:${port}`;
|
|
96
96
|
};
|
|
97
|
+
var isDeploymentUrl = (value) => value.startsWith("https://") && !value.includes("localhost") && !value.includes("${");
|
|
98
|
+
var warnIfDeploymentUrl = (serviceName, key, value) => {
|
|
99
|
+
if (!isDeploymentUrl(value))
|
|
100
|
+
return;
|
|
101
|
+
console.warn(`⚠️ ${serviceName}: ${key}=${value} looks like a deployment URL and will be written to .env.local.
|
|
102
|
+
` + ` If this value is only meaningful in the deployed container, use containerEnv: instead of env:.`);
|
|
103
|
+
};
|
|
97
104
|
var buildServiceEnvLines = (serviceConfigs) => {
|
|
98
105
|
const lines = [];
|
|
99
106
|
lines.push("", "# Service URLs");
|
|
@@ -113,6 +120,7 @@ var buildServiceEnvLines = (serviceConfigs) => {
|
|
|
113
120
|
lines.push("", "# Service Environment");
|
|
114
121
|
for (const config of envLiteralConfigs) {
|
|
115
122
|
for (const [key, value] of Object.entries(config.envLiterals)) {
|
|
123
|
+
warnIfDeploymentUrl(config.name, key, value);
|
|
116
124
|
lines.push(`${key}=${value}`);
|
|
117
125
|
}
|
|
118
126
|
}
|
|
@@ -132,7 +140,10 @@ var findWorkspaceRoot = () => {
|
|
|
132
140
|
};
|
|
133
141
|
var loadPulumiConfig = async (infraDirectory, stack) => {
|
|
134
142
|
try {
|
|
135
|
-
const stdout = execSync(`pulumi config --show-secrets --json --stack ${stack} --cwd ${infraDirectory}`, {
|
|
143
|
+
const stdout = execSync(`pulumi config --show-secrets --json --stack ${stack} --cwd ${infraDirectory}`, {
|
|
144
|
+
encoding: "utf-8",
|
|
145
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
146
|
+
});
|
|
136
147
|
const config = JSON.parse(stdout);
|
|
137
148
|
return Object.entries(config).filter(([key]) => key.includes(":")).filter(([, entry]) => entry.value !== undefined && entry.value !== null && entry.value !== "undefined").map(([fullKey, entry]) => {
|
|
138
149
|
const [, rawKey] = fullKey.split(":");
|
package/bin/generate-env.ts
CHANGED
|
@@ -85,6 +85,17 @@ const getLocalUrl = (config: MinimalServiceConfig): string | undefined => {
|
|
|
85
85
|
return `http://localhost:${port}`
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
const isDeploymentUrl = (value: string): boolean =>
|
|
89
|
+
value.startsWith('https://') && !value.includes('localhost') && !value.includes('${')
|
|
90
|
+
|
|
91
|
+
const warnIfDeploymentUrl = (serviceName: string, key: string, value: string): void => {
|
|
92
|
+
if (!isDeploymentUrl(value)) return
|
|
93
|
+
console.warn(
|
|
94
|
+
`⚠️ ${serviceName}: ${key}=${value} looks like a deployment URL and will be written to .env.local.\n` +
|
|
95
|
+
` If this value is only meaningful in the deployed container, use containerEnv: instead of env:.`,
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
const buildServiceEnvLines = (serviceConfigs: MinimalServiceConfig[]): string[] => {
|
|
89
100
|
const lines: string[] = []
|
|
90
101
|
|
|
@@ -108,6 +119,7 @@ const buildServiceEnvLines = (serviceConfigs: MinimalServiceConfig[]): string[]
|
|
|
108
119
|
lines.push('', '# Service Environment')
|
|
109
120
|
for (const config of envLiteralConfigs) {
|
|
110
121
|
for (const [key, value] of Object.entries(config.envLiterals)) {
|
|
122
|
+
warnIfDeploymentUrl(config.name, key, value)
|
|
111
123
|
lines.push(`${key}=${value}`)
|
|
112
124
|
}
|
|
113
125
|
}
|
|
@@ -116,8 +128,7 @@ const buildServiceEnvLines = (serviceConfigs: MinimalServiceConfig[]): string[]
|
|
|
116
128
|
return lines
|
|
117
129
|
}
|
|
118
130
|
|
|
119
|
-
const hasLockFile = (directory: string): boolean =>
|
|
120
|
-
LOCK_FILES.some((file) => existsSync(join(directory, file)))
|
|
131
|
+
const hasLockFile = (directory: string): boolean => LOCK_FILES.some((file) => existsSync(join(directory, file)))
|
|
121
132
|
|
|
122
133
|
const findWorkspaceRoot = (): string => {
|
|
123
134
|
let directory = process.cwd()
|
|
@@ -131,10 +142,10 @@ const findWorkspaceRoot = (): string => {
|
|
|
131
142
|
|
|
132
143
|
const loadPulumiConfig = async (infraDirectory: string, stack: string): Promise<string[]> => {
|
|
133
144
|
try {
|
|
134
|
-
const stdout = execSync(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
)
|
|
145
|
+
const stdout = execSync(`pulumi config --show-secrets --json --stack ${stack} --cwd ${infraDirectory}`, {
|
|
146
|
+
encoding: 'utf-8',
|
|
147
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
148
|
+
})
|
|
138
149
|
|
|
139
150
|
const config = JSON.parse(stdout) as Record<string, PulumiConfigEntry>
|
|
140
151
|
|
|
@@ -160,8 +171,7 @@ const discoverServices = (servicesDirectory: string): MinimalServiceConfig[] =>
|
|
|
160
171
|
|
|
161
172
|
// Extract port from ports() API: ports().http(4001) or ports().primary(4222)
|
|
162
173
|
const portsApiMatch =
|
|
163
|
-
content.match(/ports\(\)\.(?:http|https|grpc|primary)\((\d+)\)/) ||
|
|
164
|
-
content.match(/ports\(\)\.add\((\d+)/)
|
|
174
|
+
content.match(/ports\(\)\.(?:http|https|grpc|primary)\((\d+)\)/) || content.match(/ports\(\)\.add\((\d+)/)
|
|
165
175
|
|
|
166
176
|
return {
|
|
167
177
|
name: extract.string(content, /name:\s*['"]([^'"]+)['"]/) ?? file.replace('.ts', ''),
|
|
@@ -193,7 +203,7 @@ const main = async () => {
|
|
|
193
203
|
}
|
|
194
204
|
|
|
195
205
|
const serviceConfigs = discoverServices(servicesDirectory)
|
|
196
|
-
|
|
206
|
+
|
|
197
207
|
if (serviceConfigs.length > 0) {
|
|
198
208
|
envLines.push(...buildServiceEnvLines(serviceConfigs))
|
|
199
209
|
console.log(`✅ Discovered ${serviceConfigs.length} services`)
|
package/dist/index.cjs
CHANGED
|
@@ -1170,11 +1170,8 @@ var generateHandleBlock = (handle, level, basicAuth) => {
|
|
|
1170
1170
|
${inner}
|
|
1171
1171
|
}`, level);
|
|
1172
1172
|
};
|
|
1173
|
-
var generateRouteBlock = (route, encode
|
|
1173
|
+
var generateRouteBlock = (route, encode) => {
|
|
1174
1174
|
const body = [];
|
|
1175
|
-
if (useOnDemandTls) {
|
|
1176
|
-
body.push(" tls {", " on_demand", " }");
|
|
1177
|
-
}
|
|
1178
1175
|
if (!route.redirect && encode?.length) {
|
|
1179
1176
|
body.push(` encode ${encode.join(" ")}`);
|
|
1180
1177
|
}
|
|
@@ -1233,10 +1230,9 @@ var generateCaddyfile = (config) => {
|
|
|
1233
1230
|
const healthCheckBlock = `:${healthCheck.port} {
|
|
1234
1231
|
respond ${healthCheck.path} 200
|
|
1235
1232
|
}`;
|
|
1236
|
-
const useOnDemandTls = config.onDemandTls != null;
|
|
1237
1233
|
const blocks = [
|
|
1238
1234
|
generateGlobalBlock(config),
|
|
1239
|
-
...config.routes.map((route) => generateRouteBlock(route, config.encode
|
|
1235
|
+
...config.routes.map((route) => generateRouteBlock(route, config.encode)),
|
|
1240
1236
|
healthCheckBlock,
|
|
1241
1237
|
...config.catchAllUpstream && config.onDemandTls ? [generateCatchAllBlock(config.catchAllUpstream, config.encode)] : []
|
|
1242
1238
|
];
|
package/dist/index.js
CHANGED
|
@@ -1074,11 +1074,8 @@ var generateHandleBlock = (handle, level, basicAuth) => {
|
|
|
1074
1074
|
${inner}
|
|
1075
1075
|
}`, level);
|
|
1076
1076
|
};
|
|
1077
|
-
var generateRouteBlock = (route, encode
|
|
1077
|
+
var generateRouteBlock = (route, encode) => {
|
|
1078
1078
|
const body = [];
|
|
1079
|
-
if (useOnDemandTls) {
|
|
1080
|
-
body.push(" tls {", " on_demand", " }");
|
|
1081
|
-
}
|
|
1082
1079
|
if (!route.redirect && encode?.length) {
|
|
1083
1080
|
body.push(` encode ${encode.join(" ")}`);
|
|
1084
1081
|
}
|
|
@@ -1137,10 +1134,9 @@ var generateCaddyfile = (config) => {
|
|
|
1137
1134
|
const healthCheckBlock = `:${healthCheck.port} {
|
|
1138
1135
|
respond ${healthCheck.path} 200
|
|
1139
1136
|
}`;
|
|
1140
|
-
const useOnDemandTls = config.onDemandTls != null;
|
|
1141
1137
|
const blocks = [
|
|
1142
1138
|
generateGlobalBlock(config),
|
|
1143
|
-
...config.routes.map((route) => generateRouteBlock(route, config.encode
|
|
1139
|
+
...config.routes.map((route) => generateRouteBlock(route, config.encode)),
|
|
1144
1140
|
healthCheckBlock,
|
|
1145
1141
|
...config.catchAllUpstream && config.onDemandTls ? [generateCatchAllBlock(config.catchAllUpstream, config.encode)] : []
|
|
1146
1142
|
];
|