@xrystal/core 3.55.68 → 3.55.72
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/README.md +46 -2
- package/package.json +1 -1
- package/x/bin/commands/config.mjs +102 -19
- package/x/bin/commands/telepresence.mjs +30 -16
- package/x/bin/helpers/.generated/tmp-schema.mjs +39 -34
- package/x/bin/helpers/build-config.mjs +7 -7
- package/x/bin/helpers/cli-help.mjs +1 -1
- package/x/bin/helpers/config-sync.mjs +145 -0
- package/x/bin/helpers/resolve-tls-bundle.mjs +109 -0
- package/x/bin/helpers/telepresence-install.mjs +16 -0
- package/x/bin/helpers/telepresence-layout.mjs +24 -6
- package/x/bin/helpers/telepresence-runtime.mjs +109 -66
- package/x/bin/helpers/telepresence-tls-path-rewrite.mjs +69 -0
- package/x/bin/helpers/workspace-scaffold.mjs +4 -1
- package/x/bin/helpers/xrystal-config.mjs +55 -13
- package/x/bin/scripts/telepresence-client-install.sh +27 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +6 -1
- package/x/templates/api-service/docker/Dockerfile +2 -2
- package/x/templates/api-service/docker/Dockerfile.dev +2 -2
- package/x/templates/api-service/docker/docker-compose.dev.yml +2 -2
- package/x/templates/api-service/docker/docker-compose.yml +1 -1
- package/x/bin/helpers/resolve-infra-helper.mjs +0 -90
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { getCliConfigTlsDir } from './xrystal-config.mjs'
|
|
6
|
+
import { resolveUserHome } from './xrystal-registry.mjs'
|
|
7
|
+
|
|
8
|
+
export function defaultCertificatesDir() {
|
|
9
|
+
return path.join(resolveUserHome(), 'certificates')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function expandHome(filePath) {
|
|
13
|
+
const raw = String(filePath ?? '').trim()
|
|
14
|
+
if (!raw) return raw
|
|
15
|
+
if (raw.startsWith('~/')) return path.join(os.homedir(), raw.slice(2))
|
|
16
|
+
if (raw === '~') return os.homedir()
|
|
17
|
+
return raw
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isTlsTreeRoot(root) {
|
|
21
|
+
if (!root) return false
|
|
22
|
+
return fs.existsSync(path.join(root, 'root', 'ca.crt'))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isTlsFlatBundle(dir) {
|
|
26
|
+
if (!dir) return false
|
|
27
|
+
return fs.existsSync(path.join(dir, 'ca.crt'))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function tryTlsRoot(root) {
|
|
31
|
+
if (!root) return null
|
|
32
|
+
const resolved = path.resolve(expandHome(root))
|
|
33
|
+
if (isTlsTreeRoot(resolved)) return { kind: 'tree', root: resolved }
|
|
34
|
+
if (isTlsFlatBundle(resolved)) return { kind: 'flat', root: resolved }
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Operator SoT only — explicit env, config tlsDir, or ~/.xrystal/certificates (no repo fallbacks).
|
|
40
|
+
* @returns {{ kind: 'tree'|'flat', root: string } | null}
|
|
41
|
+
*/
|
|
42
|
+
export function resolveTlsSource() {
|
|
43
|
+
const fromExplicit = tryTlsRoot(process.env.XRY_TLS_SOURCE || process.env.TELEPRESENCE_CERT_ROOT)
|
|
44
|
+
if (fromExplicit) return fromExplicit
|
|
45
|
+
|
|
46
|
+
const fromConfig = tryTlsRoot(getCliConfigTlsDir())
|
|
47
|
+
if (fromConfig) return fromConfig
|
|
48
|
+
|
|
49
|
+
const home = defaultCertificatesDir()
|
|
50
|
+
if (isTlsFlatBundle(home)) return { kind: 'flat', root: home }
|
|
51
|
+
if (isTlsTreeRoot(home)) return { kind: 'tree', root: home }
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const FLAT_FILES = [
|
|
56
|
+
['ca.crt', ['root/ca.crt', 'ca.crt']],
|
|
57
|
+
['mongodb.pem', ['services/mongodb/mongodb.pem', 'mongodb.pem']],
|
|
58
|
+
['mongodb.crt', ['services/mongodb/mongodb.crt', 'mongodb.crt']],
|
|
59
|
+
['redis.pem', ['services/redis/redis.pem', 'redis.pem']],
|
|
60
|
+
['redis.crt', ['services/redis/redis.crt', 'redis.crt']],
|
|
61
|
+
['kafka.crt', ['services/kafka/kafka.crt', 'kafka.crt']],
|
|
62
|
+
['truststore.jks', ['services/kafka/truststore.jks', 'truststore.jks']],
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
function resolveSourcePath(source, relPaths) {
|
|
66
|
+
for (const rel of relPaths) {
|
|
67
|
+
const p = path.join(source.root, rel)
|
|
68
|
+
if (fs.existsSync(p)) return p
|
|
69
|
+
}
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function bundleIsFreshAtDest(dest, source) {
|
|
74
|
+
const caSrc = resolveSourcePath(source, FLAT_FILES[0][1])
|
|
75
|
+
const caDest = path.join(dest, 'ca.crt')
|
|
76
|
+
if (!caSrc || !fs.existsSync(caDest)) return false
|
|
77
|
+
try {
|
|
78
|
+
if (fs.statSync(caDest).mtimeMs < fs.statSync(caSrc).mtimeMs) return false
|
|
79
|
+
} catch {
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
for (const [destName, srcRels] of FLAT_FILES.slice(1)) {
|
|
83
|
+
const src = resolveSourcePath(source, srcRels)
|
|
84
|
+
if (!src) continue
|
|
85
|
+
const destFile = path.join(dest, destName)
|
|
86
|
+
if (!fs.existsSync(destFile)) return false
|
|
87
|
+
try {
|
|
88
|
+
if (fs.statSync(destFile).mtimeMs < fs.statSync(src).mtimeMs) return false
|
|
89
|
+
} catch {
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function syncTlsBundleFast(dest, source) {
|
|
97
|
+
fs.mkdirSync(dest, { recursive: true })
|
|
98
|
+
for (const [destName, srcRels] of FLAT_FILES) {
|
|
99
|
+
const src = resolveSourcePath(source, srcRels)
|
|
100
|
+
if (!src) continue
|
|
101
|
+
fs.copyFileSync(src, path.join(dest, destName))
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function needsTlsDestRefresh(dests, source) {
|
|
106
|
+
return dests.some((dest) => !bundleIsFreshAtDest(dest, source))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const K8S_TLS_MOUNT = '/etc/tls/infra'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
const BUNDLED_SCRIPT = path.join(
|
|
6
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
7
|
+
'..',
|
|
8
|
+
'scripts',
|
|
9
|
+
'telepresence-client-install.sh',
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
export function resolveTelepresenceInstallScript() {
|
|
13
|
+
const resolved = path.resolve(BUNDLED_SCRIPT)
|
|
14
|
+
if (fs.existsSync(resolved)) return resolved
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
@@ -3,6 +3,8 @@ import path from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import yaml from 'yaml'
|
|
5
5
|
|
|
6
|
+
import { resolveTmpDeploymentName } from './tmp-schema.mjs'
|
|
7
|
+
|
|
6
8
|
const TELEPRESENCE_ENV_EXAMPLE = `# Telepresence intercept env — copied to x/environments/.env.telepresence per service
|
|
7
9
|
# Used by: telepresence intercept --env-file .env.telepresence
|
|
8
10
|
NS=dev
|
|
@@ -10,9 +12,9 @@ TELEPRESENCE_INTERCEPT_HEADER=x-intercept-who
|
|
|
10
12
|
# TELEPRESENCE_DEV_ID=your-id
|
|
11
13
|
`
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
/** Gitignored — Telepresence overwrites with cluster pod env on intercept; not hand-maintained dev .env */
|
|
16
|
+
const SERVICE_TELEPRESENCE_ENV = `# Scaffold only until first intercept — then Telepresence fills from cluster
|
|
14
17
|
NS=dev
|
|
15
|
-
NODE_ENV=dev
|
|
16
18
|
TELEPRESENCE_INTERCEPT_HEADER=x-intercept-who
|
|
17
19
|
`
|
|
18
20
|
|
|
@@ -26,6 +28,22 @@ export function writeWorkspaceTelepresenceFiles(workspaceRoot) {
|
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export const SERVICE_TELEPRESENCE_ENV_REL = path.join('x', 'environments', '.env.telepresence')
|
|
31
|
+
export const SERVICE_LOCAL_ENV_REL = path.join('x', 'environments', '.env.local')
|
|
32
|
+
|
|
33
|
+
const SERVICE_LOCAL_ENV_SCAFFOLD = `# Local-only overrides (gitignored) — BM hosts, feature flags, extra keys
|
|
34
|
+
# Loaded after .env.telepresence on xry dev / start (laptop only)
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
export function ensureServiceLocalEnv(serviceRoot) {
|
|
38
|
+
const root = path.resolve(serviceRoot)
|
|
39
|
+
const envPath = path.join(root, SERVICE_LOCAL_ENV_REL)
|
|
40
|
+
fs.mkdirSync(path.dirname(envPath), { recursive: true })
|
|
41
|
+
const created = !fs.existsSync(envPath)
|
|
42
|
+
if (created) {
|
|
43
|
+
fs.writeFileSync(envPath, SERVICE_LOCAL_ENV_SCAFFOLD)
|
|
44
|
+
}
|
|
45
|
+
return { envPath, envRel: SERVICE_LOCAL_ENV_REL, created }
|
|
46
|
+
}
|
|
29
47
|
|
|
30
48
|
export function ensureServiceTelepresenceEnv(serviceRoot) {
|
|
31
49
|
const root = path.resolve(serviceRoot)
|
|
@@ -38,7 +56,7 @@ export function ensureServiceTelepresenceEnv(serviceRoot) {
|
|
|
38
56
|
return { envPath, envRel: SERVICE_TELEPRESENCE_ENV_REL, created }
|
|
39
57
|
}
|
|
40
58
|
|
|
41
|
-
/** Deploy name (
|
|
59
|
+
/** Deploy name (configs.service.name) → workspace api folder name */
|
|
42
60
|
export const TELEPRESENCE_DEPLOYMENTS = Object.freeze([
|
|
43
61
|
'general',
|
|
44
62
|
'gateway',
|
|
@@ -62,7 +80,7 @@ export function findServiceRootFromCwd(cwd = process.cwd()) {
|
|
|
62
80
|
return null
|
|
63
81
|
}
|
|
64
82
|
|
|
65
|
-
/**
|
|
83
|
+
/** configs.service.name from inner x/tmp.yml — must match TELEPRESENCE_DEPLOYMENTS. */
|
|
66
84
|
export function readDeployNameFromServiceRoot(serviceRoot) {
|
|
67
85
|
const tmpPath = path.join(path.resolve(serviceRoot), 'x', 'tmp.yml')
|
|
68
86
|
if (!fs.existsSync(tmpPath)) return null
|
|
@@ -72,11 +90,11 @@ export function readDeployNameFromServiceRoot(serviceRoot) {
|
|
|
72
90
|
} catch {
|
|
73
91
|
return null
|
|
74
92
|
}
|
|
75
|
-
const name =
|
|
93
|
+
const name = resolveTmpDeploymentName(doc)
|
|
76
94
|
if (!name) return null
|
|
77
95
|
if (!TELEPRESENCE_DEPLOYMENTS.includes(name)) {
|
|
78
96
|
throw new Error(
|
|
79
|
-
`tmp
|
|
97
|
+
`tmp configs.service.name "${name}" is not a known deploy (${TELEPRESENCE_DEPLOYMENTS.join(', ')}).`,
|
|
80
98
|
)
|
|
81
99
|
}
|
|
82
100
|
return name
|
|
@@ -3,8 +3,14 @@ import fs from 'node:fs'
|
|
|
3
3
|
import os from 'node:os'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { ensureServiceLocalEnv, ensureServiceTelepresenceEnv } from './telepresence-layout.mjs'
|
|
7
|
+
import {
|
|
8
|
+
cleanupTelepresenceEnvFiles,
|
|
9
|
+
rewriteTelepresenceEnvFileInPlace,
|
|
10
|
+
} from './telepresence-tls-path-rewrite.mjs'
|
|
11
|
+
import { defaultCertificatesDir } from './resolve-tls-bundle.mjs'
|
|
12
|
+
import { getCliConfigKubeconfig } from './xrystal-config.mjs'
|
|
13
|
+
import { resolveUserHome } from './xrystal-registry.mjs'
|
|
8
14
|
import { findWorkspaceRoot, resolveWorkspaceOuterTmp } from './workspace-resolve.mjs'
|
|
9
15
|
|
|
10
16
|
const ALLOWED_NS = new Set(['dev', 'test'])
|
|
@@ -32,7 +38,7 @@ function parseKubeconfigLine(tmpPath) {
|
|
|
32
38
|
return expandHome(value)
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
/** Laptop kubeconfig —
|
|
41
|
+
/** Laptop kubeconfig — env / workspace tmp / ~/.xrystal config / ~/.kube only. */
|
|
36
42
|
export function resolveKubeconfig(cwd = process.cwd()) {
|
|
37
43
|
const fromEnv = process.env.KUBECONFIG
|
|
38
44
|
if (fromEnv) {
|
|
@@ -51,16 +57,17 @@ export function resolveKubeconfig(cwd = process.cwd()) {
|
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
const candidate =
|
|
57
|
-
if (fs.existsSync(candidate)) return candidate
|
|
60
|
+
const fromEnvPath = process.env.XRY_KUBECONFIG
|
|
61
|
+
if (fromEnvPath) {
|
|
62
|
+
const candidate = expandHome(fromEnvPath)
|
|
63
|
+
if (candidate && fs.existsSync(candidate)) return candidate
|
|
58
64
|
}
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
const fromConfig = getCliConfigKubeconfig()
|
|
67
|
+
if (fromConfig && fs.existsSync(fromConfig)) return fromConfig
|
|
68
|
+
|
|
69
|
+
const xrystalKube = path.join(resolveUserHome(), 'kubeconfig')
|
|
70
|
+
if (fs.existsSync(xrystalKube)) return xrystalKube
|
|
64
71
|
|
|
65
72
|
const defaultPath = path.join(os.homedir(), '.kube', 'config')
|
|
66
73
|
if (fs.existsSync(defaultPath)) return defaultPath
|
|
@@ -138,7 +145,7 @@ export function connectTelepresence({
|
|
|
138
145
|
const kubeconfig = resolveKubeconfig(cwd)
|
|
139
146
|
if (!kubeconfig) {
|
|
140
147
|
throw new Error(
|
|
141
|
-
'Kubeconfig not found — set KUBECONFIG, workspace tmp kubeconfig:,
|
|
148
|
+
'Kubeconfig not found — set KUBECONFIG, workspace tmp kubeconfig:, xry config kubeconfig, or ~/.kube/config',
|
|
142
149
|
)
|
|
143
150
|
}
|
|
144
151
|
resetDaemonIfExecutableMismatch()
|
|
@@ -154,7 +161,7 @@ export function connectTelepresence({
|
|
|
154
161
|
return result.status ?? 1
|
|
155
162
|
}
|
|
156
163
|
|
|
157
|
-
export function quitTelepresence() {
|
|
164
|
+
export function quitTelepresence({ cwd = process.cwd() } = {}) {
|
|
158
165
|
ensureTelepresenceOnPath()
|
|
159
166
|
try {
|
|
160
167
|
const json = execSync('telepresence list --output json 2>/dev/null', {
|
|
@@ -193,63 +200,82 @@ export function quitTelepresence() {
|
|
|
193
200
|
/* ignore */
|
|
194
201
|
}
|
|
195
202
|
}
|
|
203
|
+
const serviceRoot = path.resolve(cwd)
|
|
204
|
+
const envDir = path.join(serviceRoot, 'x', 'environments')
|
|
205
|
+
finishInterceptEnvSession({ envDir, serviceRoot })
|
|
196
206
|
console.log('Telepresence stopped.')
|
|
197
207
|
}
|
|
198
208
|
|
|
199
|
-
function
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
if (fs.existsSync(root)) return root
|
|
203
|
-
}
|
|
204
|
-
const configuredInfra = getCliConfigInfraDir()
|
|
205
|
-
if (configuredInfra) {
|
|
206
|
-
const candidate = path.join(configuredInfra, 'data', 'certificates')
|
|
207
|
-
if (fs.existsSync(candidate)) return candidate
|
|
209
|
+
function finishInterceptEnvSession({ envDir, serviceRoot }) {
|
|
210
|
+
if (fs.existsSync(envDir)) {
|
|
211
|
+
cleanupTelepresenceEnvFiles(envDir)
|
|
208
212
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (fs.existsSync(candidate)) return candidate
|
|
213
|
+
if (serviceRoot) {
|
|
214
|
+
ensureServiceTelepresenceEnv(serviceRoot)
|
|
212
215
|
}
|
|
213
|
-
return null
|
|
214
216
|
}
|
|
215
217
|
|
|
216
|
-
function
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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)
|
|
221
226
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
process.on('SIGINT', onSignal)
|
|
228
|
+
process.on('SIGTERM', onSignal)
|
|
229
|
+
let status = 1
|
|
230
|
+
try {
|
|
231
|
+
status = run()
|
|
232
|
+
} finally {
|
|
233
|
+
process.off('SIGINT', onSignal)
|
|
234
|
+
process.off('SIGTERM', onSignal)
|
|
235
|
+
if (!exitingOnSignal) {
|
|
236
|
+
finishInterceptEnvSession({ envDir, serviceRoot })
|
|
237
|
+
}
|
|
227
238
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
239
|
+
return status
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function runTelepresenceEnvRewrite(envFilePath) {
|
|
243
|
+
const abs = path.resolve(envFilePath)
|
|
244
|
+
const updated = rewriteTelepresenceEnvFileInPlace(abs)
|
|
245
|
+
if (updated) {
|
|
246
|
+
console.log(`Rewrote TLS paths in ${abs} → ${defaultCertificatesDir()}`)
|
|
235
247
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
ensureServiceLocalEnvAfterIntercept(abs)
|
|
249
|
+
return updated
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function ensureServiceLocalEnvAfterIntercept(envFilePath) {
|
|
253
|
+
if (!fs.existsSync(envFilePath)) return
|
|
254
|
+
const text = fs.readFileSync(envFilePath, 'utf8')
|
|
255
|
+
const assignmentLines = text.split(/\r?\n/).filter((line) => {
|
|
256
|
+
const t = line.trim()
|
|
257
|
+
return t && !t.startsWith('#') && t.includes('=')
|
|
258
|
+
})
|
|
259
|
+
if (assignmentLines.length < 3) return
|
|
260
|
+
const serviceRoot = path.resolve(path.dirname(envFilePath), '..', '..')
|
|
261
|
+
ensureServiceLocalEnv(serviceRoot)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function shellQuote(arg) {
|
|
265
|
+
const s = String(arg)
|
|
266
|
+
if (process.platform === 'win32') {
|
|
267
|
+
return `"${s.replace(/"/g, '\\"')}"`
|
|
243
268
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
269
|
+
return `'${s.replace(/'/g, `'\\''`)}'`
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function buildInterceptLocalInvocation(cliName, absEnvFile, localCmd) {
|
|
273
|
+
const rewrite = `${cliName} tp rewrite-env ${shellQuote(absEnvFile)}`
|
|
274
|
+
const child = localCmd.map(shellQuote).join(' ')
|
|
275
|
+
if (process.platform === 'win32') {
|
|
276
|
+
return { file: 'cmd.exe', args: ['/d', '/s', '/c', `${rewrite} && ${child}`] }
|
|
277
|
+
}
|
|
278
|
+
return { file: 'sh', args: ['-c', `${rewrite} && exec ${child}`] }
|
|
253
279
|
}
|
|
254
280
|
|
|
255
281
|
function preflightReadyDeployment({ deploy, ns, cwd }) {
|
|
@@ -295,6 +321,7 @@ export function runTelepresenceIntercept({
|
|
|
295
321
|
envFile,
|
|
296
322
|
localCmd,
|
|
297
323
|
cwd = process.cwd(),
|
|
324
|
+
cliName = process.env.XRY_CLI_NAME || 'xry',
|
|
298
325
|
}) {
|
|
299
326
|
assertNamespaceAllowed(ns)
|
|
300
327
|
ensureTelepresenceOnPath()
|
|
@@ -311,7 +338,6 @@ export function runTelepresenceIntercept({
|
|
|
311
338
|
}
|
|
312
339
|
|
|
313
340
|
preflightReadyDeployment({ deploy, ns, cwd })
|
|
314
|
-
syncTlsForLocalIntercept(cwd)
|
|
315
341
|
|
|
316
342
|
const rawId = process.env.TELEPRESENCE_DEV_ID || process.env.USER || 'dev'
|
|
317
343
|
const devId = process.env.TELEPRESENCE_DEV_ID ? rawId : rawId.replace(/\./g, '-')
|
|
@@ -339,11 +365,28 @@ export function runTelepresenceIntercept({
|
|
|
339
365
|
absEnvFile,
|
|
340
366
|
]
|
|
341
367
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
368
|
+
const envDir = path.dirname(absEnvFile)
|
|
369
|
+
const serviceRoot = path.resolve(cwd)
|
|
370
|
+
|
|
371
|
+
const status = runInterceptSession({
|
|
372
|
+
envDir,
|
|
373
|
+
serviceRoot,
|
|
374
|
+
run: () => {
|
|
375
|
+
if (localCmd?.length) {
|
|
376
|
+
const wrap = buildInterceptLocalInvocation(cliName, absEnvFile, localCmd)
|
|
377
|
+
const result = spawnSync(
|
|
378
|
+
'telepresence',
|
|
379
|
+
[...tpArgs, '--', wrap.file, ...wrap.args],
|
|
380
|
+
{ stdio: 'inherit', cwd, env: process.env },
|
|
381
|
+
)
|
|
382
|
+
if (result.signal) return result.signal === 'SIGINT' ? 130 : 143
|
|
383
|
+
return result.status ?? 1
|
|
384
|
+
}
|
|
385
|
+
const result = spawnSync('telepresence', tpArgs, { stdio: 'inherit', cwd, env: process.env })
|
|
386
|
+
if (result.signal) return result.signal === 'SIGINT' ? 130 : 143
|
|
387
|
+
return result.status ?? 1
|
|
388
|
+
},
|
|
389
|
+
})
|
|
346
390
|
|
|
347
|
-
|
|
348
|
-
process.exit(result.status ?? 1)
|
|
391
|
+
process.exit(status)
|
|
349
392
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { defaultCertificatesDir, isTlsFlatBundle, K8S_TLS_MOUNT } from './resolve-tls-bundle.mjs'
|
|
5
|
+
|
|
6
|
+
/** Retired sidecar — removed after in-place rewrite. */
|
|
7
|
+
export const TELEPRESENCE_PATHS_ENV = '.env.telepresence.paths'
|
|
8
|
+
|
|
9
|
+
const PEM_FILE_RE = /\/etc\/tls\/infra\/([A-Za-z0-9._-]+)/g
|
|
10
|
+
|
|
11
|
+
function localPemPath(fileName) {
|
|
12
|
+
return path.join(defaultCertificatesDir(), fileName).split(path.sep).join('/')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function pemExistsInHome(fileName) {
|
|
16
|
+
return fs.existsSync(path.join(defaultCertificatesDir(), fileName))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function rewriteClusterTlsPathsInValue(value) {
|
|
20
|
+
const raw = String(value ?? '')
|
|
21
|
+
if (!raw.includes(K8S_TLS_MOUNT)) return raw
|
|
22
|
+
return raw.replace(PEM_FILE_RE, (match, file) => {
|
|
23
|
+
if (!pemExistsInHome(file)) return match
|
|
24
|
+
return localPemPath(file)
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function rewriteLine(line) {
|
|
29
|
+
if (!line.includes(K8S_TLS_MOUNT)) return line
|
|
30
|
+
return rewriteClusterTlsPathsInValue(line)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function removeLegacyTlsEnvSidecar(envDir) {
|
|
34
|
+
const legacy = path.join(path.resolve(envDir), TELEPRESENCE_PATHS_ENV)
|
|
35
|
+
if (fs.existsSync(legacy)) fs.unlinkSync(legacy)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Rewrite `/etc/tls/infra/<file>` → `~/.xrystal/certificates/<file>` in place when PEM exists (flat SoT).
|
|
40
|
+
* @returns {boolean} whether file was updated
|
|
41
|
+
*/
|
|
42
|
+
export function rewriteTelepresenceEnvFileInPlace(envFilePath) {
|
|
43
|
+
const envPath = path.resolve(envFilePath)
|
|
44
|
+
if (!fs.existsSync(envPath)) return false
|
|
45
|
+
|
|
46
|
+
const certHome = defaultCertificatesDir()
|
|
47
|
+
if (!isTlsFlatBundle(certHome)) return false
|
|
48
|
+
|
|
49
|
+
const original = fs.readFileSync(envPath, 'utf8')
|
|
50
|
+
const next = original
|
|
51
|
+
.split(/\r?\n/)
|
|
52
|
+
.map((line) => rewriteLine(line))
|
|
53
|
+
.join('\n')
|
|
54
|
+
|
|
55
|
+
if (next === original) return false
|
|
56
|
+
|
|
57
|
+
fs.writeFileSync(envPath, next.endsWith('\n') ? next : `${next}\n`)
|
|
58
|
+
removeLegacyTlsEnvSidecar(path.dirname(envPath))
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** After intercept ends — remove cluster snapshot + legacy sidecar. */
|
|
63
|
+
export function cleanupTelepresenceEnvFiles(envDir) {
|
|
64
|
+
const dir = path.resolve(envDir)
|
|
65
|
+
removeLegacyTlsEnvSidecar(dir)
|
|
66
|
+
const tpEnv = path.join(dir, '.env.telepresence')
|
|
67
|
+
if (fs.existsSync(tpEnv)) fs.unlinkSync(tpEnv)
|
|
68
|
+
}
|
|
69
|
+
|
|
@@ -24,7 +24,10 @@ export function scaffoldWorkspace(targetPath, projectName, {
|
|
|
24
24
|
|
|
25
25
|
fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName))
|
|
26
26
|
ensureTmpSchemaVersion(tmpPath)
|
|
27
|
-
fs.writeFileSync(
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
path.join(resolved, '.gitignore'),
|
|
29
|
+
'.env.telepresence\n.env.telepresence.paths\n.env.local\n.env.private\nnode_modules/\n',
|
|
30
|
+
)
|
|
28
31
|
|
|
29
32
|
writeWorkspaceTelepresenceFiles(resolved)
|
|
30
33
|
|
|
@@ -31,10 +31,12 @@ export function readXrystalConfig() {
|
|
|
31
31
|
export function writeXrystalConfig(next) {
|
|
32
32
|
ensureUserHome()
|
|
33
33
|
const current = readXrystalConfig()
|
|
34
|
+
const { infraDir: _legacyInfra, ...cliBase } = current.cli ?? {}
|
|
35
|
+
const { infraDir: _dropInfra, ...cliNext } = next.cli ?? {}
|
|
34
36
|
const merged = {
|
|
35
37
|
version: CONFIG_VERSION,
|
|
36
38
|
updatedAt: new Date().toISOString(),
|
|
37
|
-
cli: { ...
|
|
39
|
+
cli: { ...cliBase, ...cliNext },
|
|
38
40
|
}
|
|
39
41
|
fs.writeFileSync(configFilePath(), `${JSON.stringify(merged, null, 2)}\n`)
|
|
40
42
|
return merged
|
|
@@ -52,28 +54,68 @@ export function setCliConfigLang(lang) {
|
|
|
52
54
|
return normalized
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
-
const trimmed =
|
|
57
|
+
function readCliPathKey(key) {
|
|
58
|
+
const value = readXrystalConfig().cli?.[key]
|
|
59
|
+
if (!value || typeof value !== 'string') return null
|
|
60
|
+
const trimmed = value.trim()
|
|
59
61
|
return trimmed || null
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
export function
|
|
63
|
-
|
|
64
|
+
export function getCliConfigTlsDir() {
|
|
65
|
+
return readCliPathKey('tlsDir')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function getCliConfigKubeconfig() {
|
|
69
|
+
return readCliPathKey('kubeconfig')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getCliConfigSyncTlsFrom() {
|
|
73
|
+
return readCliPathKey('syncTlsFrom')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getCliConfigSyncKubeconfigFrom() {
|
|
77
|
+
return readCliPathKey('syncKubeconfigFrom')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function setCliConfigSyncTlsFrom(syncTlsFrom) {
|
|
81
|
+
const resolved = path.resolve(String(syncTlsFrom ?? '').trim())
|
|
82
|
+
writeXrystalConfig({ cli: { syncTlsFrom: resolved } })
|
|
83
|
+
return resolved
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function setCliConfigSyncKubeconfigFrom(syncKubeconfigFrom) {
|
|
87
|
+
const resolved = path.resolve(String(syncKubeconfigFrom ?? '').trim())
|
|
88
|
+
writeXrystalConfig({ cli: { syncKubeconfigFrom: resolved } })
|
|
89
|
+
return resolved
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function setCliConfigTlsDir(tlsDir) {
|
|
93
|
+
const resolved = path.resolve(String(tlsDir ?? '').trim())
|
|
64
94
|
if (!fs.existsSync(resolved)) {
|
|
65
|
-
throw new Error(`
|
|
95
|
+
throw new Error(`TLS directory not found: ${resolved}`)
|
|
66
96
|
}
|
|
67
|
-
|
|
68
|
-
|
|
97
|
+
writeXrystalConfig({ cli: { tlsDir: resolved } })
|
|
98
|
+
return resolved
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function setCliConfigKubeconfig(kubeconfigPath) {
|
|
102
|
+
const resolved = path.resolve(String(kubeconfigPath ?? '').trim())
|
|
103
|
+
if (!fs.existsSync(resolved)) {
|
|
104
|
+
throw new Error(`Kubeconfig not found: ${resolved}`)
|
|
69
105
|
}
|
|
70
|
-
writeXrystalConfig({ cli: {
|
|
106
|
+
writeXrystalConfig({ cli: { kubeconfig: resolved } })
|
|
71
107
|
return resolved
|
|
72
108
|
}
|
|
73
109
|
|
|
74
|
-
export function
|
|
110
|
+
export function clearCliConfigTlsDir() {
|
|
111
|
+
const current = readXrystalConfig()
|
|
112
|
+
const { tlsDir: _removed, ...rest } = current.cli ?? {}
|
|
113
|
+
writeXrystalConfig({ cli: rest })
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function clearCliConfigKubeconfig() {
|
|
75
117
|
const current = readXrystalConfig()
|
|
76
|
-
const {
|
|
118
|
+
const { kubeconfig: _removed, ...rest } = current.cli ?? {}
|
|
77
119
|
writeXrystalConfig({ cli: rest })
|
|
78
120
|
}
|
|
79
121
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Telepresence OSS client (~2.31.x) — bundled with @xrystal/core (no external repo)
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
VERSION="${TELEPRESENCE_VERSION:-2.31.2}"
|
|
6
|
+
DEST="${TELEPRESENCE_BIN:-${HOME}/.local/bin/telepresence}"
|
|
7
|
+
|
|
8
|
+
case "$(uname -s)-$(uname -m)" in
|
|
9
|
+
Darwin-arm64) ASSET=telepresence-darwin-arm64 ;;
|
|
10
|
+
Darwin-x86_64) ASSET=telepresence-darwin-amd64 ;;
|
|
11
|
+
Linux-x86_64) ASSET=telepresence-linux-amd64 ;;
|
|
12
|
+
Linux-aarch64|Linux-arm64) ASSET=telepresence-linux-arm64 ;;
|
|
13
|
+
*)
|
|
14
|
+
echo "Unsupported platform: $(uname -s) $(uname -m)" >&2
|
|
15
|
+
exit 1
|
|
16
|
+
;;
|
|
17
|
+
esac
|
|
18
|
+
|
|
19
|
+
URL="https://github.com/telepresenceio/telepresence/releases/download/v${VERSION}/${ASSET}"
|
|
20
|
+
mkdir -p "$(dirname "$DEST")"
|
|
21
|
+
echo "Downloading Telepresence v${VERSION} (${ASSET})..."
|
|
22
|
+
curl -fsSL "$URL" -o "$DEST"
|
|
23
|
+
chmod +x "$DEST"
|
|
24
|
+
"$DEST" version
|
|
25
|
+
echo
|
|
26
|
+
echo "Installed: $DEST"
|
|
27
|
+
echo "Add to PATH if needed: export PATH=\"${HOME}/.local/bin:\$PATH\""
|