diff --git a/packages/cli/src/commands/proxy/connect.ts b/packages/cli/src/commands/proxy/connect.ts index bf2ca5b9..2d3779b5 100644 --- a/packages/cli/src/commands/proxy/connect.ts +++ b/packages/cli/src/commands/proxy/connect.ts @@ -21,8 +21,8 @@ export default class Connect extends ProfileCommand { description: 'specify the environment ID for this app', required: false, }), - 'disable-widget': Flags.boolean({ - default: true, + 'enable-widget': Flags.boolean({ + default: false, hidden: true, }), 'livecycle-widget-url': Flags.string({ @@ -92,6 +92,7 @@ export default class Connect extends ProfileCommand { const inspector = commands.proxy.inspectRunningComposeApp(composeProject) const networks = await inspector.getComposeNetworks() const projectDirectory = await inspector.getWorkingDirectory() + const thumbprint = await jwkThumbprint(tunnelingKey) const model = await commands.proxy.initProxyComposeModel({ version: this.config.version, envId, @@ -100,8 +101,8 @@ export default class Connect extends ProfileCommand { tunnelOpts, networks, privateMode: flags['private-env'], - injectLivecycleScript: flags['disable-widget'] ? undefined : flags['livecycle-widget-url'], - tunnelingKeyThumbprint: await jwkThumbprint(tunnelingKey), + injectLivecycleScript: flags['enable-widget'] ? `${flags['livecycle-widget-url']}?profile=${thumbprint}&env=${envId}` : undefined, + tunnelingKeyThumbprint: thumbprint, projectDirectory, }) diff --git a/packages/compose-tunnel-agent/src/docker/services.ts b/packages/compose-tunnel-agent/src/docker/services.ts index a9f6fe66..ea50cafb 100644 --- a/packages/compose-tunnel-agent/src/docker/services.ts +++ b/packages/compose-tunnel-agent/src/docker/services.ts @@ -12,6 +12,9 @@ export type RunningService = { inject: ScriptInjection[] } +const GLOBAL_INJECT_SCRIPTS = process.env.GLOBAL_INJECT_SCRIPTS + ? JSON.parse(process.env.GLOBAL_INJECT_SCRIPTS) as ScriptInjection[] : [] + export const containerToService = ({ container, defaultAccess, @@ -22,5 +25,5 @@ export const containerToService = ({ networks: Object.keys(container.NetworkSettings.Networks), // ports may have both IPv6 and IPv4 addresses, ignoring ports: [...new Set(container.Ports.filter(p => p.Type === 'tcp').filter(portFilter(container)).map(p => p.PrivatePort))], - inject: scriptInjectionFromLabels(container.Labels), + inject: [...scriptInjectionFromLabels(container.Labels), ...GLOBAL_INJECT_SCRIPTS], }) diff --git a/packages/core/src/commands/proxy.ts b/packages/core/src/commands/proxy.ts index 528636c0..bca659a6 100644 --- a/packages/core/src/commands/proxy.ts +++ b/packages/core/src/commands/proxy.ts @@ -2,10 +2,10 @@ import { COMPOSE_TUNNEL_AGENT_PORT, COMPOSE_TUNNEL_AGENT_SERVICE_NAME, tunnelNam import { mkdtemp, writeFile } from 'node:fs/promises' import path from 'node:path' import { tmpdir } from 'node:os' +import { set } from 'lodash' import { Connection } from '../tunneling' import { execPromiseStdout } from '../child-process' import { addComposeTunnelAgentService } from '../compose-tunnel-agent-client' -import { widgetScriptInjector } from '../compose/script-injection' import { ComposeModel } from '../compose' import { TunnelOpts } from '../ssh' import { EnvId } from '../env-id' @@ -63,6 +63,7 @@ export function inspectRunningComposeApp(projectName: string) { getPreevyAgentContainer, getEnvId, getWorkingDirectory, + listAllContainers, } } @@ -93,7 +94,7 @@ export async function initProxyComposeModel(opts: { git: opts.projectDirectory ? await detectGitMetadata(opts.projectDirectory) : undefined, } - let newComposeModel = addComposeTunnelAgentService({ + const newComposeModel = addComposeTunnelAgentService({ tunnelOpts: opts.tunnelOpts, envId: opts.envId, debug: !!opts.debug, @@ -108,8 +109,9 @@ export async function initProxyComposeModel(opts: { }, compose) if (opts.injectLivecycleScript) { - const { inject } = widgetScriptInjector(opts.injectLivecycleScript) - newComposeModel = inject(newComposeModel) + set(newComposeModel, ['services', COMPOSE_TUNNEL_AGENT_SERVICE_NAME, 'environment', 'GLOBAL_INJECT_SCRIPTS'], JSON.stringify([{ + src: opts.injectLivecycleScript, + }])) } return {