@oussema_mili/test-pkg-123 1.1.22
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.
Potentially problematic release.
This version of @oussema_mili/test-pkg-123 might be problematic. Click here for more details.
- package/LICENSE +29 -0
- package/README.md +220 -0
- package/auth-callback.html +97 -0
- package/auth.js +276 -0
- package/cli-commands.js +1923 -0
- package/containerManager.js +304 -0
- package/daemon/agentRunner.js +429 -0
- package/daemon/daemonEntry.js +64 -0
- package/daemon/daemonManager.js +271 -0
- package/daemon/logManager.js +227 -0
- package/dist/styles.css +504 -0
- package/docker-actions/apps.js +3938 -0
- package/docker-actions/config-transformer.js +380 -0
- package/docker-actions/containers.js +355 -0
- package/docker-actions/general.js +171 -0
- package/docker-actions/images.js +1128 -0
- package/docker-actions/logs.js +224 -0
- package/docker-actions/metrics.js +270 -0
- package/docker-actions/registry.js +1100 -0
- package/docker-actions/setup-tasks.js +859 -0
- package/docker-actions/terminal.js +247 -0
- package/docker-actions/volumes.js +696 -0
- package/helper-functions.js +193 -0
- package/index.html +83 -0
- package/index.js +341 -0
- package/package.json +82 -0
- package/postcss.config.mjs +5 -0
- package/scripts/release.sh +212 -0
- package/setup/setupWizard.js +403 -0
- package/store/agentSessionStore.js +51 -0
- package/store/agentStore.js +113 -0
- package/store/configStore.js +171 -0
- package/store/daemonStore.js +217 -0
- package/store/deviceCredentialStore.js +107 -0
- package/store/npmTokenStore.js +65 -0
- package/store/registryStore.js +329 -0
- package/store/setupState.js +147 -0
- package/styles.css +1 -0
- package/utils/appLogger.js +223 -0
- package/utils/deviceInfo.js +98 -0
- package/utils/ecrAuth.js +225 -0
- package/utils/encryption.js +112 -0
- package/utils/envSetup.js +44 -0
- package/utils/errorHandler.js +327 -0
- package/utils/portUtils.js +59 -0
- package/utils/prerequisites.js +323 -0
- package/utils/prompts.js +318 -0
- package/utils/ssl-certificates.js +256 -0
- package/websocket-server.js +415 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import { spawn, exec } from 'child_process';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { loadConfig } from './store/configStore.js';
|
|
6
|
+
|
|
7
|
+
// Load configuration
|
|
8
|
+
const config = loadConfig();
|
|
9
|
+
const CONTAINER_NAME = config.containerName;
|
|
10
|
+
const AGENT_ROOT_DIR = config.agentRootDir;
|
|
11
|
+
const REGISTRIES_DIR = config.registriesDir;
|
|
12
|
+
const HOST_DATA_DIR = path.join(os.homedir(), AGENT_ROOT_DIR, REGISTRIES_DIR);
|
|
13
|
+
const HOST_FW_DIR = path.join(os.homedir(), AGENT_ROOT_DIR);
|
|
14
|
+
const CONTAINER_DATA_DIR = config.containerDataDir;
|
|
15
|
+
const CONTAINER_FW_DIR = '/app/.fenwave';
|
|
16
|
+
const APP_PORT = config.containerPort;
|
|
17
|
+
const WS_PORT = config.wsPort;
|
|
18
|
+
const DOCKER_IMAGE = config.dockerImage;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Container Manager for Fenwave DevApp
|
|
22
|
+
*/
|
|
23
|
+
class ContainerManager {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.isRunning = false;
|
|
26
|
+
this.containerProcess = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if Docker is available
|
|
31
|
+
*/
|
|
32
|
+
async checkDockerAvailable() {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
exec('docker --version', (error) => {
|
|
35
|
+
resolve(!error);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if container is already running
|
|
42
|
+
*/
|
|
43
|
+
async isContainerRunning() {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
exec(
|
|
46
|
+
`docker ps --filter name=${CONTAINER_NAME} --format "{{.Names}}"`,
|
|
47
|
+
(error, stdout) => {
|
|
48
|
+
if (error) {
|
|
49
|
+
resolve(false);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
resolve(stdout.trim() === CONTAINER_NAME);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Stop and remove existing container
|
|
60
|
+
*/
|
|
61
|
+
async stopContainer() {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
exec(
|
|
64
|
+
`docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}`,
|
|
65
|
+
(error) => {
|
|
66
|
+
// Don't worry if container doesn't exist
|
|
67
|
+
resolve();
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Check if image exists locally
|
|
75
|
+
*/
|
|
76
|
+
async imageExistsLocally() {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
exec(
|
|
79
|
+
`docker images -q ${DOCKER_IMAGE}`,
|
|
80
|
+
(error, stdout) => {
|
|
81
|
+
resolve(stdout.trim().length > 0);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Pull the Fenwave DevApp image from GHCR
|
|
89
|
+
*/
|
|
90
|
+
async pullImage() {
|
|
91
|
+
return new Promise(async (resolve, reject) => {
|
|
92
|
+
try {
|
|
93
|
+
// Check if image exists locally
|
|
94
|
+
const imageExists = await this.imageExistsLocally();
|
|
95
|
+
if (imageExists) {
|
|
96
|
+
console.log(chalk.green('â
Image already exists locally, checking for updates...'));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log(chalk.blue('đĨ Pulling Fenwave DevApp image...'));
|
|
100
|
+
console.log(chalk.gray(` Image: ${DOCKER_IMAGE}`));
|
|
101
|
+
|
|
102
|
+
const pullProcess = spawn('docker', ['pull', DOCKER_IMAGE], {
|
|
103
|
+
stdio: 'pipe',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
let output = '';
|
|
107
|
+
let errorOutput = '';
|
|
108
|
+
|
|
109
|
+
pullProcess.stdout.on('data', (data) => {
|
|
110
|
+
output += data.toString();
|
|
111
|
+
// Show pull progress for important lines
|
|
112
|
+
const lines = data
|
|
113
|
+
.toString()
|
|
114
|
+
.split('\n')
|
|
115
|
+
.filter((line) => line.trim());
|
|
116
|
+
lines.forEach((line) => {
|
|
117
|
+
if (
|
|
118
|
+
line.includes('Pulling from') ||
|
|
119
|
+
line.includes('Digest:') ||
|
|
120
|
+
line.includes('Status:') ||
|
|
121
|
+
line.includes('Downloaded')
|
|
122
|
+
) {
|
|
123
|
+
console.log(chalk.gray(` ${line.trim()}`));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
pullProcess.stderr.on('data', (data) => {
|
|
129
|
+
errorOutput += data.toString();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
pullProcess.on('close', (code) => {
|
|
133
|
+
if (code === 0) {
|
|
134
|
+
console.log(chalk.green('â
Image pulled successfully'));
|
|
135
|
+
resolve();
|
|
136
|
+
} else {
|
|
137
|
+
console.error(chalk.red('â Failed to pull image:'));
|
|
138
|
+
console.error(errorOutput);
|
|
139
|
+
reject(new Error(`Pull failed with code ${code}`));
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
} catch (error) {
|
|
143
|
+
reject(error);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Start the Fenwave DevApp container
|
|
150
|
+
*/
|
|
151
|
+
async startContainer() {
|
|
152
|
+
try {
|
|
153
|
+
// Check Docker availability
|
|
154
|
+
const dockerAvailable = await this.checkDockerAvailable();
|
|
155
|
+
if (!dockerAvailable) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
'Docker is not available. Please install Docker and try again.'
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Stop existing container if running
|
|
162
|
+
await this.stopContainer();
|
|
163
|
+
|
|
164
|
+
// Pull image from GHCR (public registry, no auth required)
|
|
165
|
+
try {
|
|
166
|
+
await this.pullImage();
|
|
167
|
+
} catch (pullError) {
|
|
168
|
+
console.log(chalk.yellow('â ī¸ Image pull failed, checking for local image...'));
|
|
169
|
+
const imageExists = await this.imageExistsLocally();
|
|
170
|
+
if (!imageExists) {
|
|
171
|
+
throw new Error('No local image available and pull failed. Please check your network connection.');
|
|
172
|
+
}
|
|
173
|
+
console.log(chalk.green('â
Using cached local image'));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Determine WebSocket URL based on platform
|
|
177
|
+
let wsUrl = `ws://host.docker.internal:${WS_PORT}`;
|
|
178
|
+
if (os.platform() === 'linux') {
|
|
179
|
+
// On Linux, use host network or get host IP
|
|
180
|
+
wsUrl = `ws://172.17.0.1:${WS_PORT}`; // Docker default bridge IP
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
console.log(chalk.blue('đ Starting Fenwave DevApp container...'));
|
|
184
|
+
|
|
185
|
+
const runArgs = [
|
|
186
|
+
'run',
|
|
187
|
+
'-d', // Detached mode
|
|
188
|
+
'--name',
|
|
189
|
+
CONTAINER_NAME,
|
|
190
|
+
'-p',
|
|
191
|
+
`${APP_PORT}:${APP_PORT}`,
|
|
192
|
+
// Mount registry data directory
|
|
193
|
+
'-v',
|
|
194
|
+
`${HOST_DATA_DIR}:${CONTAINER_DATA_DIR}:rw`,
|
|
195
|
+
// Mount .fenwave directory for WebSocket token access
|
|
196
|
+
'-v',
|
|
197
|
+
`${HOST_FW_DIR}:${CONTAINER_FW_DIR}:ro`,
|
|
198
|
+
'-e',
|
|
199
|
+
`PORT=${APP_PORT}`,
|
|
200
|
+
'-e',
|
|
201
|
+
`NEXT_PUBLIC_WS_URL=${wsUrl}`,
|
|
202
|
+
'--restart',
|
|
203
|
+
'unless-stopped',
|
|
204
|
+
DOCKER_IMAGE,
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
const runProcess = spawn('docker', runArgs, {
|
|
209
|
+
stdio: 'pipe',
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
let output = '';
|
|
213
|
+
let errorOutput = '';
|
|
214
|
+
|
|
215
|
+
runProcess.stdout.on('data', (data) => {
|
|
216
|
+
output += data.toString();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
runProcess.stderr.on('data', (data) => {
|
|
220
|
+
errorOutput += data.toString();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
runProcess.on('close', (code) => {
|
|
224
|
+
if (code === 0) {
|
|
225
|
+
this.isRunning = true;
|
|
226
|
+
console.log(chalk.green('â
Container started successfully'));
|
|
227
|
+
console.log(chalk.gray(` Image: ${DOCKER_IMAGE}`));
|
|
228
|
+
console.log(chalk.gray(` Container: ${CONTAINER_NAME}`));
|
|
229
|
+
console.log(chalk.gray(` Port: ${APP_PORT}`));
|
|
230
|
+
console.log(chalk.gray(` Data volume: ${HOST_DATA_DIR} -> ${CONTAINER_DATA_DIR}`));
|
|
231
|
+
console.log(chalk.gray(` Token volume: ${HOST_FW_DIR} -> ${CONTAINER_FW_DIR}`));
|
|
232
|
+
resolve();
|
|
233
|
+
} else {
|
|
234
|
+
console.error(chalk.red('â Failed to start container:'));
|
|
235
|
+
if (errorOutput) {
|
|
236
|
+
console.error(errorOutput);
|
|
237
|
+
}
|
|
238
|
+
reject(new Error(`Container start failed with code ${code}`));
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
} catch (error) {
|
|
243
|
+
console.error(
|
|
244
|
+
chalk.red('â Failed to start Fenwave DevApp:'),
|
|
245
|
+
error.message
|
|
246
|
+
);
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Stop the Fenwave DevApp container
|
|
253
|
+
*/
|
|
254
|
+
async stopContainerGracefully() {
|
|
255
|
+
try {
|
|
256
|
+
const running = await this.isContainerRunning();
|
|
257
|
+
if (!running) {
|
|
258
|
+
console.log(chalk.yellow('âšī¸ Container is not running'));
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
await this.stopContainer();
|
|
263
|
+
this.isRunning = false;
|
|
264
|
+
} catch (error) {
|
|
265
|
+
console.error(chalk.red('â Failed to stop container:'), error.message);
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Get container status
|
|
272
|
+
*/
|
|
273
|
+
async getStatus() {
|
|
274
|
+
const running = await this.isContainerRunning();
|
|
275
|
+
return {
|
|
276
|
+
isRunning: running,
|
|
277
|
+
containerName: CONTAINER_NAME,
|
|
278
|
+
port: APP_PORT,
|
|
279
|
+
dataDirectory: HOST_DATA_DIR,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Show container logs
|
|
285
|
+
*/
|
|
286
|
+
showLogs(follow = false) {
|
|
287
|
+
const args = ['logs'];
|
|
288
|
+
if (follow) {
|
|
289
|
+
args.push('-f');
|
|
290
|
+
}
|
|
291
|
+
args.push(CONTAINER_NAME);
|
|
292
|
+
|
|
293
|
+
const logsProcess = spawn('docker', args, {
|
|
294
|
+
stdio: 'inherit',
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
return logsProcess;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Singleton instance
|
|
302
|
+
const containerManager = new ContainerManager();
|
|
303
|
+
|
|
304
|
+
export default containerManager;
|