@forge/tunnel 6.2.2-next.3-experimental-1a0bb6a → 6.3.0-next.5

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/CHANGELOG.md CHANGED
@@ -1,14 +1,24 @@
1
1
  # @forge/tunnel
2
2
 
3
- ## 6.2.2-next.3-experimental-1a0bb6a
3
+ ## 6.3.0-next.5
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [4cc304c]
8
- - Updated dependencies [90ee56f]
9
- - @forge/csp@5.1.1-next.0-experimental-1a0bb6a
10
- - @forge/cli-shared@8.7.2-next.1-experimental-1a0bb6a
11
- - @forge/bundler@6.1.9-next.3-experimental-1a0bb6a
7
+ - @forge/bundler@6.1.9-next.5
8
+ - @forge/cli-shared@8.8.0-next.3
9
+
10
+ ## 6.3.0-next.4
11
+
12
+ ### Minor Changes
13
+
14
+ - 8ff224b: Add automatic spinning up of docker compose stacks for containers when tunneling
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [8ff224b]
19
+ - @forge/runtime@6.1.0-next.0
20
+ - @forge/cli-shared@8.8.0-next.2
21
+ - @forge/bundler@6.1.9-next.4
12
22
 
13
23
  ## 6.2.2-next.3
14
24
 
@@ -30,8 +30,10 @@ export declare class StartTunnelCommand {
30
30
  private cspReporterServer;
31
31
  constructor(getAppConfig: AppConfigProvider, devServer: DevelopmentServer, tunnelFactory: CreateTunnelService, tunnelClient: RegisterTunnelService, functionHost: FunctionChangeWatcher, logger: Logger, configFile: ConfigFile);
32
32
  private stopServices;
33
+ stopDockerComposeStack: (composeFiles?: Record<string, string>) => Promise<void>;
34
+ private deleteDockerComposeFile;
33
35
  private startFaaSTunnelServer;
34
36
  private startResourceBasedTunnelsServers;
35
- execute(options: StartTunnelOptions): Promise<StartTunnelResult>;
37
+ execute(options: StartTunnelOptions, containersDockerComposeFiles?: Record<string, string>): Promise<StartTunnelResult>;
36
38
  }
37
39
  //# sourceMappingURL=start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B,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,eAAe,CAAC,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F;AAED,qBAAa,kBAAkB;IAK3B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAV7B,OAAO,CAAC,aAAa,CAAmE;IACxF,OAAO,CAAC,iBAAiB,CAAgC;gBAGtC,YAAY,EAAE,iBAAiB,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,aAAa,EAAE,mBAAmB,EAClC,YAAY,EAAE,qBAAqB,EACnC,YAAY,EAAE,qBAAqB,EACnC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU;IAGzC,OAAO,CAAC,YAAY,CAclB;IAMK,sBAAsB,kBAAyB,OAAO,MAAM,EAAE,MAAM,CAAC,KAAG,QAAQ,IAAI,CAAC,CAyB1F;IAMF,OAAO,CAAC,uBAAuB,CAY7B;IAEF,OAAO,CAAC,qBAAqB,CAuB3B;IAEF,OAAO,CAAC,gCAAgC,CAiCtC;IAEW,OAAO,CAClB,OAAO,EAAE,kBAAkB,EAC3B,4BAA4B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpD,OAAO,CAAC,iBAAiB,CAAC;CA+C9B"}
@@ -5,6 +5,10 @@ const tslib_1 = require("tslib");
5
5
  const node_cache_1 = tslib_1.__importDefault(require("node-cache"));
6
6
  const portfinder_1 = require("portfinder");
7
7
  const servers_1 = require("../servers");
8
+ const docker_compose_1 = require("docker-compose");
9
+ const cli_shared_1 = require("@forge/cli-shared");
10
+ const path = tslib_1.__importStar(require("path"));
11
+ const fs = tslib_1.__importStar(require("fs"));
8
12
  class StartTunnelCommand {
9
13
  getAppConfig;
10
14
  devServer;
@@ -24,16 +28,48 @@ class StartTunnelCommand {
24
28
  this.logger = logger;
25
29
  this.configFile = configFile;
26
30
  }
27
- stopServices = async (appId, environmentKey) => {
31
+ stopServices = async (appId, environmentKey, containersDockerComposeFiles) => {
28
32
  await Promise.all([
29
33
  this.functionHost.stopWatching(),
30
34
  this.tunnelClient.unregisterTunnels(appId, environmentKey),
31
35
  this.tunnelFactory.closeTunnel(),
32
36
  this.devServer.stop(),
33
37
  ...Object.values(this.tunnelServers).map((server) => server.stop()),
34
- this.cspReporterServer?.stop()
38
+ this.cspReporterServer?.stop(),
39
+ this.stopDockerComposeStack(containersDockerComposeFiles)
35
40
  ]);
36
41
  };
42
+ stopDockerComposeStack = async (composeFiles) => {
43
+ if (!composeFiles || Object.keys(composeFiles).length === 0)
44
+ return;
45
+ const { services } = await this.configFile.readConfig();
46
+ const serviceWithTunnelConfigExists = services?.some((service) => service.containers?.some((container) => {
47
+ return !!container.tunnel;
48
+ }));
49
+ if (!services || services.length === 0 || !serviceWithTunnelConfigExists)
50
+ return;
51
+ await Promise.all(Object.entries(composeFiles).map(async ([serviceKey, file]) => {
52
+ try {
53
+ await (0, docker_compose_1.downAll)({ cwd: '.', log: true, config: file, composeOptions: [`-p${serviceKey}`] });
54
+ await this.deleteDockerComposeFile(file);
55
+ }
56
+ catch (err) {
57
+ throw new Error(cli_shared_1.Text.tunnel.unableToStopDockerComposeStack(serviceKey, err.message ?? 'Unknown Error Occurred.'));
58
+ }
59
+ }));
60
+ };
61
+ deleteDockerComposeFile = async (composeFile) => {
62
+ if (fs.existsSync(composeFile)) {
63
+ fs.unlinkSync(composeFile);
64
+ }
65
+ const hiddenDir = path.join(process.cwd(), '.services');
66
+ if (fs.existsSync(hiddenDir)) {
67
+ const files = fs.readdirSync(hiddenDir);
68
+ if (files.length == 0) {
69
+ fs.rmdirSync(hiddenDir);
70
+ }
71
+ }
72
+ };
37
73
  startFaaSTunnelServer = async ({ port, appId, environmentKey }) => {
38
74
  const { permissions = {}, remotes = [] } = await this.configFile.readConfig();
39
75
  const serverInfo = await this.devServer.start(port, permissions, remotes);
@@ -73,7 +109,7 @@ class StartTunnelCommand {
73
109
  return this.tunnelServers[key].start();
74
110
  }));
75
111
  };
76
- async execute(options) {
112
+ async execute(options, containersDockerComposeFiles) {
77
113
  const { id: appId } = await this.getAppConfig();
78
114
  const { port, environmentKey } = options;
79
115
  const allResources = await this.configFile.getResources();
@@ -92,7 +128,7 @@ class StartTunnelCommand {
92
128
  }))
93
129
  };
94
130
  await this.tunnelClient.registerTunnels(appId, environmentKey, tunnelDefinitions);
95
- const stopFunction = async () => this.stopServices(appId, environmentKey);
131
+ const stopFunction = async () => this.stopServices(appId, environmentKey, containersDockerComposeFiles);
96
132
  const reloadSandboxes = async (bundledCode, tunnelOptions) => {
97
133
  await this.functionHost.stopWatching();
98
134
  await this.functionHost.startWatching(bundledCode, tunnelOptions);
@@ -108,7 +144,7 @@ class StartTunnelCommand {
108
144
  }
109
145
  catch (e) {
110
146
  try {
111
- await this.stopServices(appId, environmentKey);
147
+ await this.stopServices(appId, environmentKey, containersDockerComposeFiles);
112
148
  }
113
149
  catch { }
114
150
  throw e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/tunnel",
3
- "version": "6.2.2-next.3-experimental-1a0bb6a",
3
+ "version": "6.3.0-next.5",
4
4
  "description": "Tunnel functionality for Forge CLI",
5
5
  "author": "Atlassian",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -11,13 +11,14 @@
11
11
  "compile": "tsc -b -v"
12
12
  },
13
13
  "dependencies": {
14
- "@forge/bundler": "6.1.9-next.3-experimental-1a0bb6a",
15
- "@forge/cli-shared": "8.7.2-next.1-experimental-1a0bb6a",
16
- "@forge/csp": "5.1.1-next.0-experimental-1a0bb6a",
17
- "@forge/runtime": "6.0.4",
14
+ "@forge/bundler": "6.1.9-next.5",
15
+ "@forge/cli-shared": "8.8.0-next.3",
16
+ "@forge/csp": "5.1.1-next.0",
17
+ "@forge/runtime": "6.1.0-next.0",
18
18
  "cheerio": "^1.1.0",
19
19
  "chokidar": "^3.6.0",
20
20
  "cloudflared": "^0.7.0",
21
+ "docker-compose": "^1.3.0",
21
22
  "express": "^4.18.3",
22
23
  "express-intercept": "^1.1.1",
23
24
  "http-proxy-middleware": "^2.0.9",
@@ -31,7 +32,7 @@
31
32
  },
32
33
  "devDependencies": {
33
34
  "@atlassian/xen-test-util": "^4.2.0",
34
- "@forge/manifest": "10.7.0-next.0-experimental-1a0bb6a",
35
+ "@forge/manifest": "10.7.0-next.1",
35
36
  "@types/express": "^4.17.21",
36
37
  "@types/jest": "^29.5.14",
37
38
  "@types/node": "20.19.1",