@xrystal/core 3.55.72 → 3.55.75
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/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path'
|
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
|
|
6
6
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
7
|
+
import { ensureServiceLaptopEnvs } from '../helpers/telepresence-layout.mjs'
|
|
7
8
|
import {
|
|
8
9
|
isCorePackageName,
|
|
9
10
|
readTmpBuildContext,
|
|
@@ -53,6 +54,7 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
53
54
|
.description('Watch TypeScript entry with dev env files (service repo only — not workspace root)')
|
|
54
55
|
.action(() => {
|
|
55
56
|
runWithServiceRoot((root) => {
|
|
57
|
+
ensureServiceLaptopEnvs(root)
|
|
56
58
|
const { layout, runtime } = readTmpBuildContext(root)
|
|
57
59
|
const entry = resolveDevEntry(root, layout)
|
|
58
60
|
const envFiles = resolveDevRunnerEnvFiles(layout.pathsAbs.environments)
|
|
@@ -8,11 +8,13 @@ import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
|
8
8
|
import { resolveTelepresenceInstallScript } from '../helpers/telepresence-install.mjs'
|
|
9
9
|
import {
|
|
10
10
|
connectTelepresence,
|
|
11
|
+
leaveTelepresenceIntercept,
|
|
11
12
|
quitTelepresence,
|
|
12
13
|
runTelepresenceEnvRewrite,
|
|
13
14
|
runTelepresenceIntercept,
|
|
14
15
|
} from '../helpers/telepresence-runtime.mjs'
|
|
15
16
|
import {
|
|
17
|
+
ensureServiceLaptopEnvs,
|
|
16
18
|
ensureServiceTelepresenceEnv,
|
|
17
19
|
resolveTelepresenceDeployFromCwd,
|
|
18
20
|
resolveTelepresenceServiceDir,
|
|
@@ -104,9 +106,10 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
104
106
|
${cliName} tp intercept
|
|
105
107
|
${cliName} tp intercept gateway 3000 --ns dev
|
|
106
108
|
${cliName} tp stop
|
|
109
|
+
${cliName} tp leave gateway --ns dev
|
|
107
110
|
${cliName} tp install
|
|
108
111
|
|
|
109
|
-
${chalk.gray('start/stop')}
|
|
112
|
+
${chalk.gray('start/stop/leave')} = connect / quit all / end intercept only
|
|
110
113
|
${chalk.gray('intercept')} = omit deploy in service repo → configs.service.name from x/tmp.yml
|
|
111
114
|
${chalk.gray('--ns')} = Kubernetes namespace (default: dev)
|
|
112
115
|
${chalk.gray('<deploy>')} = optional — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
|
|
@@ -126,6 +129,27 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
126
129
|
.alias('quit')
|
|
127
130
|
.action(() => runQuit({ cliName, commandLabel: 'tp stop' }))
|
|
128
131
|
|
|
132
|
+
tp.command('leave')
|
|
133
|
+
.description('End intercept only — detach workload + env snapshot; stay connected')
|
|
134
|
+
.argument('[deploy]', `Deployment (default: configs.service.name in x/tmp.yml)`)
|
|
135
|
+
.option('--ns <namespace>', 'Kubernetes namespace', 'dev')
|
|
136
|
+
.action((deploy, options) => {
|
|
137
|
+
const version = readCliPackageJson().version
|
|
138
|
+
const ns = String(options.ns ?? 'dev').trim() || 'dev'
|
|
139
|
+
let deployName = String(deploy ?? '').trim()
|
|
140
|
+
if (!deployName) {
|
|
141
|
+
deployName = resolveTelepresenceDeployFromCwd(process.cwd()).deploy
|
|
142
|
+
}
|
|
143
|
+
printCommandHeader({ cliName, command: `tp leave ${deployName}`, version })
|
|
144
|
+
try {
|
|
145
|
+
leaveTelepresenceIntercept({ deploy: deployName, ns, cwd: process.cwd() })
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error(chalk.red(`\n✗ ${err.message}\n`))
|
|
148
|
+
process.exit(1)
|
|
149
|
+
}
|
|
150
|
+
printCommandFooter({ version })
|
|
151
|
+
})
|
|
152
|
+
|
|
129
153
|
tp.command('rewrite-env')
|
|
130
154
|
.description('Rewrite /etc/tls/infra/* → ~/.xrystal/certificates/* in .env.telepresence (flat PEM names)')
|
|
131
155
|
.argument('[envFile]', 'Path to .env.telepresence (default: service x/environments)')
|
|
@@ -185,7 +209,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
185
209
|
svcDir = process.cwd()
|
|
186
210
|
}
|
|
187
211
|
|
|
188
|
-
const env =
|
|
212
|
+
const env = ensureServiceLaptopEnvs(svcDir).telepresence
|
|
189
213
|
process.env.NS = ns
|
|
190
214
|
if (workspaceRoot) process.env.XRYSTAL_WORKSPACE = workspaceRoot
|
|
191
215
|
|
|
@@ -53,6 +53,10 @@ function commandGroups() {
|
|
|
53
53
|
{ cmd: 'watch install', desc: 'OS service — survives reboot (launchd / systemd user)' },
|
|
54
54
|
{ cmd: 'tp start --ns dev', aliases: 'tp connect', desc: 'Connect Telepresence to cluster namespace' },
|
|
55
55
|
{ cmd: 'tp stop', aliases: 'tp quit', desc: 'Disconnect Telepresence' },
|
|
56
|
+
{
|
|
57
|
+
cmd: 'tp leave [deploy] --ns dev',
|
|
58
|
+
desc: 'End intercept only (detach + env cleanup; stay connected)',
|
|
59
|
+
},
|
|
56
60
|
{ cmd: 'tp intercept [deploy] --ns dev', aliases: 'tp dev', desc: 'Intercept — omit deploy in service repo (uses x/tmp.yml configs.service.name)' },
|
|
57
61
|
{ cmd: 'telepresence install', aliases: 'tp install', desc: 'Install Telepresence OSS client (~2.31.x)' },
|
|
58
62
|
],
|
|
@@ -30,6 +30,21 @@ export function writeWorkspaceTelepresenceFiles(workspaceRoot) {
|
|
|
30
30
|
export const SERVICE_TELEPRESENCE_ENV_REL = path.join('x', 'environments', '.env.telepresence')
|
|
31
31
|
export const SERVICE_LOCAL_ENV_REL = path.join('x', 'environments', '.env.local')
|
|
32
32
|
|
|
33
|
+
/** Retired laptop scaffolds — removed on `xry dev` / intercept (never loaded by CLI). */
|
|
34
|
+
export const LEGACY_LAPTOP_ENV_NAMES = Object.freeze(['.global.env', '.dev.env'])
|
|
35
|
+
|
|
36
|
+
export function pruneLegacyLaptopEnvFiles(serviceRoot) {
|
|
37
|
+
const envDir = path.join(path.resolve(serviceRoot), 'x', 'environments')
|
|
38
|
+
const removed = []
|
|
39
|
+
for (const name of LEGACY_LAPTOP_ENV_NAMES) {
|
|
40
|
+
const filePath = path.join(envDir, name)
|
|
41
|
+
if (!fs.existsSync(filePath)) continue
|
|
42
|
+
fs.unlinkSync(filePath)
|
|
43
|
+
removed.push(name)
|
|
44
|
+
}
|
|
45
|
+
return removed
|
|
46
|
+
}
|
|
47
|
+
|
|
33
48
|
const SERVICE_LOCAL_ENV_SCAFFOLD = `# Local-only overrides (gitignored) — BM hosts, feature flags, extra keys
|
|
34
49
|
# Loaded after .env.telepresence on xry dev / start (laptop only)
|
|
35
50
|
`
|
|
@@ -56,6 +71,14 @@ export function ensureServiceTelepresenceEnv(serviceRoot) {
|
|
|
56
71
|
return { envPath, envRel: SERVICE_TELEPRESENCE_ENV_REL, created }
|
|
57
72
|
}
|
|
58
73
|
|
|
74
|
+
/** Telepresence + `.env.local` only under x/environments (all gitignored). */
|
|
75
|
+
export function ensureServiceLaptopEnvs(serviceRoot) {
|
|
76
|
+
const removedLegacy = pruneLegacyLaptopEnvFiles(serviceRoot)
|
|
77
|
+
const telepresence = ensureServiceTelepresenceEnv(serviceRoot)
|
|
78
|
+
const local = ensureServiceLocalEnv(serviceRoot)
|
|
79
|
+
return { telepresence, local, removedLegacy }
|
|
80
|
+
}
|
|
81
|
+
|
|
59
82
|
/** Deploy name (configs.service.name) → workspace api folder name */
|
|
60
83
|
export const TELEPRESENCE_DEPLOYMENTS = Object.freeze([
|
|
61
84
|
'general',
|
|
@@ -3,7 +3,11 @@ import fs from 'node:fs'
|
|
|
3
3
|
import os from 'node:os'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
ensureServiceLocalEnv,
|
|
8
|
+
pruneLegacyLaptopEnvFiles,
|
|
9
|
+
SERVICE_TELEPRESENCE_ENV_REL,
|
|
10
|
+
} from './telepresence-layout.mjs'
|
|
7
11
|
import {
|
|
8
12
|
cleanupTelepresenceEnvFiles,
|
|
9
13
|
rewriteTelepresenceEnvFileInPlace,
|
|
@@ -161,7 +165,32 @@ export function connectTelepresence({
|
|
|
161
165
|
return result.status ?? 1
|
|
162
166
|
}
|
|
163
167
|
|
|
164
|
-
|
|
168
|
+
/** Drop one intercept; keeps telepresence connect when possible. */
|
|
169
|
+
export function detachInterceptWorkload({ deploy, ns } = {}) {
|
|
170
|
+
const name = String(deploy ?? '').trim()
|
|
171
|
+
const namespace = String(ns ?? '').trim()
|
|
172
|
+
if (!name || !namespace) return
|
|
173
|
+
ensureTelepresenceOnPath()
|
|
174
|
+
try {
|
|
175
|
+
execSync(`telepresence leave ${name} --namespace ${namespace}`, {
|
|
176
|
+
stdio: 'ignore',
|
|
177
|
+
shell: true,
|
|
178
|
+
})
|
|
179
|
+
return
|
|
180
|
+
} catch {
|
|
181
|
+
/* fall through */
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
execSync(`telepresence detach "${name}" --namespace "${namespace}"`, {
|
|
185
|
+
stdio: 'ignore',
|
|
186
|
+
shell: true,
|
|
187
|
+
})
|
|
188
|
+
} catch {
|
|
189
|
+
/* ignore */
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function detachAllIntercepts() {
|
|
165
194
|
ensureTelepresenceOnPath()
|
|
166
195
|
try {
|
|
167
196
|
const json = execSync('telepresence list --output json 2>/dev/null', {
|
|
@@ -179,18 +208,16 @@ export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
|
179
208
|
const name = it?.name || it?.workload
|
|
180
209
|
const itemNs = it?.namespace || 'dev'
|
|
181
210
|
if (!name) continue
|
|
182
|
-
|
|
183
|
-
execSync(`telepresence detach "${name}" --namespace "${itemNs}"`, {
|
|
184
|
-
stdio: 'ignore',
|
|
185
|
-
shell: true,
|
|
186
|
-
})
|
|
187
|
-
} catch {
|
|
188
|
-
/* ignore */
|
|
189
|
-
}
|
|
211
|
+
detachInterceptWorkload({ deploy: name, ns: itemNs })
|
|
190
212
|
}
|
|
191
213
|
} catch {
|
|
192
214
|
/* no active intercepts */
|
|
193
215
|
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
219
|
+
ensureTelepresenceOnPath()
|
|
220
|
+
detachAllIntercepts()
|
|
194
221
|
try {
|
|
195
222
|
execSync('telepresence quit -s', { stdio: 'ignore', shell: true })
|
|
196
223
|
} catch {
|
|
@@ -206,35 +233,58 @@ export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
|
206
233
|
console.log('Telepresence stopped.')
|
|
207
234
|
}
|
|
208
235
|
|
|
209
|
-
|
|
236
|
+
/** End intercept session: detach workload, remove cluster env snapshot, restore scaffold. */
|
|
237
|
+
export function leaveTelepresenceIntercept({ deploy, ns = 'dev', cwd = process.cwd() } = {}) {
|
|
238
|
+
assertNamespaceAllowed(ns)
|
|
239
|
+
const serviceRoot = path.resolve(cwd)
|
|
240
|
+
const envDir = path.join(serviceRoot, 'x', 'environments')
|
|
241
|
+
finishInterceptEnvSession({ envDir, serviceRoot, deploy, ns })
|
|
242
|
+
console.log(`Intercept ended (${deploy}, ns=${ns}). Cluster connect may still be active — use xry tp stop to quit.`)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Detach intercept + delete cluster env snapshot (.env.telepresence). `.env.local` is kept. */
|
|
246
|
+
export function finishInterceptEnvSession({ envDir, serviceRoot, deploy, ns }) {
|
|
247
|
+
if (deploy && ns) {
|
|
248
|
+
detachInterceptWorkload({ deploy, ns })
|
|
249
|
+
}
|
|
250
|
+
const removed = []
|
|
210
251
|
if (fs.existsSync(envDir)) {
|
|
252
|
+
const tpEnv = path.join(path.resolve(envDir), '.env.telepresence')
|
|
253
|
+
if (fs.existsSync(tpEnv)) removed.push(SERVICE_TELEPRESENCE_ENV_REL)
|
|
211
254
|
cleanupTelepresenceEnvFiles(envDir)
|
|
212
255
|
}
|
|
213
256
|
if (serviceRoot) {
|
|
214
|
-
|
|
257
|
+
for (const name of pruneLegacyLaptopEnvFiles(serviceRoot)) {
|
|
258
|
+
removed.push(path.join('x', 'environments', name))
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (removed.length) {
|
|
262
|
+
console.log(`Removed laptop env snapshot: ${removed.join(', ')}`)
|
|
215
263
|
}
|
|
216
264
|
}
|
|
217
265
|
|
|
218
|
-
function runInterceptSession({ envDir, serviceRoot, run }) {
|
|
219
|
-
let
|
|
220
|
-
const
|
|
221
|
-
if (
|
|
222
|
-
|
|
223
|
-
finishInterceptEnvSession({ envDir, serviceRoot })
|
|
224
|
-
const code = signal === 'SIGINT' ? 130 : 143
|
|
225
|
-
process.exit(code)
|
|
266
|
+
function runInterceptSession({ envDir, serviceRoot, deploy, ns, run }) {
|
|
267
|
+
let sessionEnded = false
|
|
268
|
+
const endSession = () => {
|
|
269
|
+
if (sessionEnded) return
|
|
270
|
+
sessionEnded = true
|
|
271
|
+
finishInterceptEnvSession({ envDir, serviceRoot, deploy, ns })
|
|
226
272
|
}
|
|
273
|
+
|
|
274
|
+
const onSignal = () => {
|
|
275
|
+
endSession()
|
|
276
|
+
}
|
|
277
|
+
|
|
227
278
|
process.on('SIGINT', onSignal)
|
|
228
279
|
process.on('SIGTERM', onSignal)
|
|
280
|
+
|
|
229
281
|
let status = 1
|
|
230
282
|
try {
|
|
231
283
|
status = run()
|
|
232
284
|
} finally {
|
|
233
|
-
process.
|
|
234
|
-
process.
|
|
235
|
-
|
|
236
|
-
finishInterceptEnvSession({ envDir, serviceRoot })
|
|
237
|
-
}
|
|
285
|
+
process.removeListener('SIGINT', onSignal)
|
|
286
|
+
process.removeListener('SIGTERM', onSignal)
|
|
287
|
+
endSession()
|
|
238
288
|
}
|
|
239
289
|
return status
|
|
240
290
|
}
|
|
@@ -371,6 +421,8 @@ export function runTelepresenceIntercept({
|
|
|
371
421
|
const status = runInterceptSession({
|
|
372
422
|
envDir,
|
|
373
423
|
serviceRoot,
|
|
424
|
+
deploy,
|
|
425
|
+
ns,
|
|
374
426
|
run: () => {
|
|
375
427
|
if (localCmd?.length) {
|
|
376
428
|
const wrap = buildInterceptLocalInvocation(cliName, absEnvFile, localCmd)
|