@xrystal/core 3.55.72 → 3.55.74
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
|
],
|
|
@@ -56,6 +56,13 @@ export function ensureServiceTelepresenceEnv(serviceRoot) {
|
|
|
56
56
|
return { envPath, envRel: SERVICE_TELEPRESENCE_ENV_REL, created }
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** Telepresence + `.env.local` only under x/environments (all gitignored). */
|
|
60
|
+
export function ensureServiceLaptopEnvs(serviceRoot) {
|
|
61
|
+
const telepresence = ensureServiceTelepresenceEnv(serviceRoot)
|
|
62
|
+
const local = ensureServiceLocalEnv(serviceRoot)
|
|
63
|
+
return { telepresence, local }
|
|
64
|
+
}
|
|
65
|
+
|
|
59
66
|
/** Deploy name (configs.service.name) → workspace api folder name */
|
|
60
67
|
export const TELEPRESENCE_DEPLOYMENTS = Object.freeze([
|
|
61
68
|
'general',
|
|
@@ -161,7 +161,32 @@ export function connectTelepresence({
|
|
|
161
161
|
return result.status ?? 1
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
/** Drop one intercept; keeps telepresence connect when possible. */
|
|
165
|
+
export function detachInterceptWorkload({ deploy, ns } = {}) {
|
|
166
|
+
const name = String(deploy ?? '').trim()
|
|
167
|
+
const namespace = String(ns ?? '').trim()
|
|
168
|
+
if (!name || !namespace) return
|
|
169
|
+
ensureTelepresenceOnPath()
|
|
170
|
+
try {
|
|
171
|
+
execSync(`telepresence leave ${name} --namespace ${namespace}`, {
|
|
172
|
+
stdio: 'ignore',
|
|
173
|
+
shell: true,
|
|
174
|
+
})
|
|
175
|
+
return
|
|
176
|
+
} catch {
|
|
177
|
+
/* fall through */
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
execSync(`telepresence detach "${name}" --namespace "${namespace}"`, {
|
|
181
|
+
stdio: 'ignore',
|
|
182
|
+
shell: true,
|
|
183
|
+
})
|
|
184
|
+
} catch {
|
|
185
|
+
/* ignore */
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function detachAllIntercepts() {
|
|
165
190
|
ensureTelepresenceOnPath()
|
|
166
191
|
try {
|
|
167
192
|
const json = execSync('telepresence list --output json 2>/dev/null', {
|
|
@@ -179,18 +204,16 @@ export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
|
179
204
|
const name = it?.name || it?.workload
|
|
180
205
|
const itemNs = it?.namespace || 'dev'
|
|
181
206
|
if (!name) continue
|
|
182
|
-
|
|
183
|
-
execSync(`telepresence detach "${name}" --namespace "${itemNs}"`, {
|
|
184
|
-
stdio: 'ignore',
|
|
185
|
-
shell: true,
|
|
186
|
-
})
|
|
187
|
-
} catch {
|
|
188
|
-
/* ignore */
|
|
189
|
-
}
|
|
207
|
+
detachInterceptWorkload({ deploy: name, ns: itemNs })
|
|
190
208
|
}
|
|
191
209
|
} catch {
|
|
192
210
|
/* no active intercepts */
|
|
193
211
|
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
215
|
+
ensureTelepresenceOnPath()
|
|
216
|
+
detachAllIntercepts()
|
|
194
217
|
try {
|
|
195
218
|
execSync('telepresence quit -s', { stdio: 'ignore', shell: true })
|
|
196
219
|
} catch {
|
|
@@ -206,7 +229,19 @@ export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
|
206
229
|
console.log('Telepresence stopped.')
|
|
207
230
|
}
|
|
208
231
|
|
|
209
|
-
|
|
232
|
+
/** End intercept session: detach workload, remove cluster env snapshot, restore scaffold. */
|
|
233
|
+
export function leaveTelepresenceIntercept({ deploy, ns = 'dev', cwd = process.cwd() } = {}) {
|
|
234
|
+
assertNamespaceAllowed(ns)
|
|
235
|
+
const serviceRoot = path.resolve(cwd)
|
|
236
|
+
const envDir = path.join(serviceRoot, 'x', 'environments')
|
|
237
|
+
finishInterceptEnvSession({ envDir, serviceRoot, deploy, ns })
|
|
238
|
+
console.log(`Intercept ended (${deploy}, ns=${ns}). Cluster connect may still be active — use xry tp stop to quit.`)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function finishInterceptEnvSession({ envDir, serviceRoot, deploy, ns }) {
|
|
242
|
+
if (deploy && ns) {
|
|
243
|
+
detachInterceptWorkload({ deploy, ns })
|
|
244
|
+
}
|
|
210
245
|
if (fs.existsSync(envDir)) {
|
|
211
246
|
cleanupTelepresenceEnvFiles(envDir)
|
|
212
247
|
}
|
|
@@ -215,26 +250,12 @@ function finishInterceptEnvSession({ envDir, serviceRoot }) {
|
|
|
215
250
|
}
|
|
216
251
|
}
|
|
217
252
|
|
|
218
|
-
function runInterceptSession({ envDir, serviceRoot, run }) {
|
|
219
|
-
let exitingOnSignal = false
|
|
220
|
-
const onSignal = (signal) => {
|
|
221
|
-
if (exitingOnSignal) return
|
|
222
|
-
exitingOnSignal = true
|
|
223
|
-
finishInterceptEnvSession({ envDir, serviceRoot })
|
|
224
|
-
const code = signal === 'SIGINT' ? 130 : 143
|
|
225
|
-
process.exit(code)
|
|
226
|
-
}
|
|
227
|
-
process.on('SIGINT', onSignal)
|
|
228
|
-
process.on('SIGTERM', onSignal)
|
|
253
|
+
function runInterceptSession({ envDir, serviceRoot, deploy, ns, run }) {
|
|
229
254
|
let status = 1
|
|
230
255
|
try {
|
|
231
256
|
status = run()
|
|
232
257
|
} finally {
|
|
233
|
-
|
|
234
|
-
process.off('SIGTERM', onSignal)
|
|
235
|
-
if (!exitingOnSignal) {
|
|
236
|
-
finishInterceptEnvSession({ envDir, serviceRoot })
|
|
237
|
-
}
|
|
258
|
+
finishInterceptEnvSession({ envDir, serviceRoot, deploy, ns })
|
|
238
259
|
}
|
|
239
260
|
return status
|
|
240
261
|
}
|
|
@@ -371,6 +392,8 @@ export function runTelepresenceIntercept({
|
|
|
371
392
|
const status = runInterceptSession({
|
|
372
393
|
envDir,
|
|
373
394
|
serviceRoot,
|
|
395
|
+
deploy,
|
|
396
|
+
ns,
|
|
374
397
|
run: () => {
|
|
375
398
|
if (localCmd?.length) {
|
|
376
399
|
const wrap = buildInterceptLocalInvocation(cliName, absEnvFile, localCmd)
|