@fenwave/agent 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/README.md +32 -398
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,434 +1,68 @@
1
1
  # Fenwave Agent
2
2
 
3
- The Fenwave Agent is a command-line tool that runs locally on developer machines to manage Docker containers, registries, and local development environments. It communicates with the Fenwave Backstage platform for authentication and session management.
4
-
5
- ## Table of Contents
6
-
7
- - [Architecture](#architecture)
8
- - [Prerequisites](#prerequisites)
9
- - [Installation](#installation)
10
- - [Configuration](#configuration)
11
- - [Usage](#usage)
12
- - [Security](#security)
13
- - [Troubleshooting](#troubleshooting)
14
- - [Development](#development)
15
-
16
- ## Architecture
17
-
18
- The Fenwave Agent consists of three main components:
19
-
20
- 1. **Agent CLI** - Command-line interface for managing the agent and Docker operations
21
- 2. **WebSocket Server** - Handles real-time communication with the Fenwave DevApp web application
22
- 3. **Fenwave DevApp** - Next.js web application that provides a dashboard for managing containers, images, volumes, and more
23
-
24
- ### Communication Flow
25
-
26
- ```
27
- ┌─────────────────────┐
28
- │ Backstage Backend │
29
- │ (Authentication) │
30
- └──────────┬──────────┘
31
-
32
- │ HTTPS (Session Creation)
33
-
34
-
35
- ┌──────────────┐ WebSocket (Port 3001) ┌─────────────────┐
36
- │ Agent CLI │◄────────────────────────────────────►│ Fenwave DevApp │
37
- │ (Node.js) │ │ (Next.js) │
38
- └──────┬───────┘ └────────┬────────┘
39
- │ │
40
- │ Docker API │ HTTP API
41
- │ │
42
- ▼ ▼
43
- ┌─────────────┐ ┌─────────────────┐
44
- │ Docker │ │ Browser UI │
45
- │ Engine │ │ (localhost) │
46
- └─────────────┘ └─────────────────┘
47
- ```
48
-
49
- ### WebSocket Authentication
50
-
51
- The agent uses token-based authentication for WebSocket connections:
52
-
53
- 1. **Token Generation**: Agent generates a cryptographically secure 256-bit random token on startup
54
- 2. **Token Storage**: Token is saved to `~/.fenwave/ws-token` with restricted permissions (0600)
55
- 3. **Token Sharing**: The token file is mounted as a read-only volume in the Fenwave DevApp Docker container
56
- 4. **Authentication Flow**:
57
- - Client connects to WebSocket → Server sends `auth_required` challenge
58
- - Client reads token from `/api/ws-token` endpoint → Sends `auth` message with token
59
- - Server validates token → Responds with `auth_success` or `auth_error`
60
- - Only authenticated clients can send/receive messages
3
+ The Fenwave Agent is a CLI tool for managing Docker containers and local development environments. It integrates with the Fenwave platform for seamless developer experience.
61
4
 
62
5
  ## Prerequisites
63
6
 
64
- Before installing the Fenwave Agent, ensure you have:
65
-
66
7
  - **Docker Desktop** (version 20.10 or later)
67
- - Download: https://www.docker.com/products/docker-desktop
68
- - Verify: `docker --version`
69
-
70
8
  - **Node.js** (version 18 or later)
71
- - Download: https://nodejs.org
72
- - Verify: `node --version`
73
-
74
- - **AWS CLI** (for ECR authentication)
75
- - Download: https://aws.amazon.com/cli/
76
- - Verify: `aws --version`
77
- - Configure AWS credentials with ECR access
78
-
79
- - **Backstage Access**
80
- - Access to your organization's Fenwave Backstage instance
81
- - Valid user credentials
9
+ - **Fenwave Platform Access** - Valid credentials from your organization
82
10
 
83
11
  ## Installation
84
12
 
85
- ### Option 1: Via Backstage (Recommended)
86
-
87
- 1. Log in to your Fenwave Backstage instance
88
- 2. Navigate to the Agent Installer page
89
- 3. Click "Generate Installation Token"
90
- 4. Follow the platform-specific installation instructions
91
- 5. The installer will:
92
- - Download the agent binary
93
- - Configure AWS credentials
94
- - Authenticate with Backstage
95
- - Pull the Fenwave DevApp Docker image
96
- - Start the agent
97
-
98
- ### Option 2: Manual Installation
99
-
100
- 1. **Clone the repository**:
101
- ```bash
102
- git clone <repository-url>
103
- cd local-env/agent
104
- ```
105
-
106
- 2. **Install dependencies**:
107
- ```bash
108
- npm install
109
- ```
110
-
111
- 3. **Configure environment**:
112
- ```bash
113
- cp .env.example .env
114
- # Edit .env with your configuration
115
- ```
116
-
117
- 4. **Link the CLI globally** (optional):
118
- ```bash
119
- npm link
120
- ```
121
-
122
- 5. **Configure AWS credentials**:
123
- ```bash
124
- aws configure
125
- # Enter your AWS Access Key ID and Secret Access Key
126
- ```
127
-
128
- ## Configuration
129
-
130
- The agent stores its configuration in `~/.fenwave/config/agent.json`. Configuration is set during the `fenwave init` command and persists across agent restarts and npm package updates.
131
-
132
- **Configuration file location:** `~/.fenwave/config/agent.json`
133
-
134
- **Available options:**
135
-
136
- | Option | Description | Default |
137
- |--------|-------------|---------|
138
- | `backendUrl` | Backstage backend URL | `http://localhost:7007` |
139
- | `frontendUrl` | Backstage frontend URL | `http://localhost:3000` |
140
- | `appBuilderUrl` | App Builder API URL | Same as `backendUrl` |
141
- | `containerName` | Docker container name for Fenwave DevApp | `fenwave-devapp` |
142
- | `containerPort` | Port for Fenwave DevApp HTTP server | `3003` |
143
- | `wsPort` | Port for WebSocket server | `3001` |
144
- | `agentRootDir` | Directory for agent data (relative to home) | `.fenwave` |
145
- | `registriesDir` | Subdirectory for registry data | `registries` |
146
- | `containerDataDir` | Container data mount path | `/data` |
147
- | `awsRegion` | AWS region for ECR | `eu-west-1` |
148
- | `awsAccountId` | AWS account ID for ECR | Set from Backstage |
149
- | `dockerImage` | Docker image to use | Computed from AWS config |
150
- | `authTimeoutMs` | Authentication timeout in milliseconds | `60000` |
151
-
152
- **Configure during initialization:**
153
- ```bash
154
- fenwave init \
155
- --token <registration-token> \
156
- --backend-url http://localhost:7007 \
157
- --frontend-url http://localhost:3000 \
158
- --aws-region eu-west-1
159
- ```
160
-
161
- Note: The AWS Account ID is automatically retrieved from Backstage during device registration.
162
-
163
- **View current configuration:**
164
13
  ```bash
165
- cat ~/.fenwave/config/agent.json
14
+ npm install -g @fenwave/agent
166
15
  ```
167
16
 
168
- **Environment variable fallback:** If the configuration file doesn't exist, the agent will fall back to environment variables (for backwards compatibility).
17
+ ## Quick Start
169
18
 
170
- ### Directory Structure
19
+ ### 1. Initialize the Agent
171
20
 
172
- The agent creates the following directory structure in your home directory:
173
-
174
- ```
175
- ~/.fenwave/
176
- ├── config/
177
- │ └── agent.json # Agent configuration (0600 permissions)
178
- ├── session/
179
- │ └── config.json # Backstage session information
180
- ├── device/
181
- │ └── credential.json # Device credentials (encrypted)
182
- ├── setup/
183
- │ └── state.json # Setup wizard state
184
- ├── agent/
185
- │ └── info.json # Agent runtime information
186
- ├── npm/
187
- │ └── token # NPM authentication token
188
- ├── ws-token # WebSocket authentication token (0600 permissions)
189
- └── registries/ # Docker registry configurations
190
- ├── dockerhub.json
191
- ├── ecr.json
192
- └── ...
193
- ```
194
-
195
- ## Usage
196
-
197
- ### Starting the Agent
21
+ Get your registration token from the Fenwave platform, then run:
198
22
 
199
23
  ```bash
200
- # Start the agent (authenticates with Backstage)
201
- fenwave login
202
-
203
- # The agent will:
204
- # 1. Open your browser for Backstage authentication
205
- # 2. Create a session with the Backstage backend
206
- # 3. Authenticate with AWS ECR
207
- # 4. Pull the latest Fenwave DevApp Docker image
208
- # 5. Start the Fenwave DevApp container
209
- # 6. Start the WebSocket server
210
-
211
- # After successful startup, you'll see:
212
- # ✅ Fenwave Agent Started Successfully
213
- # 🌐 Fenwave DevApp Dashboard: http://localhost:3003
214
- # 🔌 WebSocket Server: ws://localhost:3001
215
- # 👤 User: user:default/your-username
24
+ fenwave init --token <your-registration-token>
216
25
  ```
217
26
 
218
- ### Accessing the Dashboard
219
-
220
- Once the agent is running, open your browser to:
221
-
222
- ```
223
- http://localhost:3003
224
- ```
225
-
226
- The dashboard provides:
227
- - **Containers**: View, start, stop, restart, and delete containers
228
- - **Images**: Pull, push, tag, and delete Docker images
229
- - **Volumes**: Create, backup, restore, and delete volumes
230
- - **Apps**: Deploy and manage multi-container applications
231
- - **Registries**: Connect to Docker registries (Docker Hub, ECR, private registries)
232
- - **Logs**: Stream real-time container logs
233
- - **Metrics**: View system and container resource usage
234
- - **Terminal**: Execute commands in running containers
235
-
236
- ### Agent Commands
27
+ ### 2. Start the Agent
237
28
 
238
29
  ```bash
239
- # Start agent and authenticate
240
30
  fenwave login
241
-
242
- # Logout and clear session
243
- fenwave logout
244
-
245
- # Check agent status
246
- fenwave status
247
-
248
- # Show agent version
249
- fenwave --version
250
-
251
- # Get help
252
- fenwave --help
253
31
  ```
254
32
 
255
- ### Docker Operations
256
-
257
- All Docker operations are performed through the web dashboard at `http://localhost:3003`. The agent provides a WebSocket API for:
258
-
259
- - Container management (start, stop, restart, delete, create, inspect)
260
- - Image management (pull, push, tag, delete, inspect)
261
- - Volume management (create, delete, inspect, backup, restore)
262
- - Registry management (connect, disconnect, list images)
263
- - Log streaming (real-time container logs)
264
- - Metrics collection (system and container stats)
265
- - Terminal sessions (exec into containers)
33
+ ### 3. Access the Dashboard
266
34
 
267
- ## Security
35
+ Open your browser to `http://localhost:3003`
268
36
 
269
- ### Authentication & Authorization
37
+ ## Commands
270
38
 
271
- 1. **Backstage Authentication**: Users must authenticate with Backstage before using the agent
272
- 2. **Session Management**: Sessions are stored locally with expiration timestamps
273
- 3. **WebSocket Token**: Cryptographically secure random token for WebSocket authentication
274
- 4. **File Permissions**: Sensitive files (session.json, ws-token) use restrictive permissions (0600)
39
+ | Command | Description |
40
+ |---------|-------------|
41
+ | `fenwave init` | Initialize and configure the agent |
42
+ | `fenwave login` | Start the agent and authenticate |
43
+ | `fenwave logout` | Stop the agent and clear session |
44
+ | `fenwave status` | Check agent and registration status |
45
+ | `fenwave --help` | Show all available commands |
275
46
 
276
- ### Network Security
47
+ ## Dashboard Features
277
48
 
278
- 1. **Local-Only Communication**: WebSocket server only accepts connections from localhost
279
- 2. **No External Exposure**: The agent does not expose any ports to the internet
280
- 3. **TLS for Backstage**: Communication with Backstage backend uses HTTPS
281
- 4. **ECR Authentication**: AWS credentials required for Docker image pulling
282
-
283
- ### Best Practices
284
-
285
- 1. **Never share your session token** - Each user has a unique session
286
- 2. **Keep Docker updated** - Use the latest Docker Desktop version
287
- 3. **Rotate AWS credentials regularly** - Follow your organization's security policies
288
- 4. **Monitor agent logs** - Check for suspicious activity
289
- 5. **Use strong Backstage passwords** - Enable 2FA if available
49
+ - Container management (start, stop, restart, logs)
50
+ - Docker image management
51
+ - Volume management
52
+ - Registry connections
53
+ - Real-time metrics
290
54
 
291
55
  ## Troubleshooting
292
56
 
293
- ### Agent won't start
294
-
295
- **Problem**: Agent fails to start with authentication errors
296
-
297
- **Solutions**:
298
- 1. Check Backstage is running: `curl http://localhost:7007/api/health`
299
- 2. Clear existing session: `rm ~/.fenwave/session.json`
300
- 3. Verify internet connectivity
301
- 4. Check firewall settings
302
-
303
- ### Docker image pull fails
304
-
305
- **Problem**: Failed to pull local-env image from ECR
306
-
307
- **Solutions**:
308
- 1. Verify AWS credentials: `aws sts get-caller-identity`
309
- 2. Check ECR access: `aws ecr describe-repositories --region eu-west-1`
310
- 3. Authenticate manually: `aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.eu-west-1.amazonaws.com`
311
- 4. Check network/VPN connection
312
-
313
- ### WebSocket connection fails
314
-
315
- **Problem**: Fenwave DevApp cannot connect to agent
316
-
317
- **Solutions**:
318
- 1. Check agent is running: `docker ps | grep fenwave-devapp`
319
- 2. Verify WebSocket server is listening: `lsof -i :3001`
320
- 3. Check token file exists: `ls -la ~/.fenwave/ws-token`
321
- 4. Restart the agent: `fenwave logout && fenwave login`
322
- 5. Check browser console for detailed error messages
323
-
324
- ### Container won't start
325
-
326
- **Problem**: Fenwave DevApp container fails to start
327
-
328
- **Solutions**:
329
- 1. Check Docker is running: `docker info`
330
- 2. Verify port 3003 is available: `lsof -i :3003`
331
- 3. Check container logs: `docker logs fenwave-devapp`
332
- 4. Remove existing container: `docker rm -f fenwave-devapp`
333
- 5. Pull latest image: `docker pull <ecr-image>`
334
-
335
- ### Session expired
336
-
337
- **Problem**: Agent reports session expired
338
-
339
- **Solutions**:
340
- 1. Logout and login again: `fenwave logout && fenwave login`
341
- 2. Check Backstage backend is accessible
342
- 3. Verify system clock is synchronized
343
-
344
- ## Development
345
-
346
- ### Running in Development Mode
347
-
348
- ```bash
349
- # Install dependencies
350
- npm install
351
-
352
- # Set up environment
353
- cp .env.example .env
354
-
355
- # Run the agent locally (without Docker)
356
- node index.js login
357
-
358
- # For Fenwave DevApp development (build from source)
359
- # Set DOCKER_IMAGE=fenwave-devapp in .env
360
- # Build image: docker build -t fenwave-devapp ..
361
- ```
362
-
363
- ### Building the Docker Image
364
-
365
- ```bash
366
- # Build production image
367
- cd ../ # Go to local-env root
368
- docker build -f Dockerfile.prod -t fenwave-devapp:latest .
369
-
370
- # Test the image
371
- docker run -d \
372
- --name fenwave-devapp-test \
373
- -p 3003:3003 \
374
- -v ~/.fenwave:/app/.fenwave:ro \
375
- -e NEXT_PUBLIC_WS_URL=ws://host.docker.internal:3001 \
376
- fenwave-devapp:latest
377
-
378
- # Check logs
379
- docker logs -f fenwave-devapp-test
380
- ```
381
-
382
- ### Publishing to ECR
383
-
384
- ```bash
385
- # Run the publish script
386
- cd ../ # Go to local-env root
387
- ./scripts/publish-image.sh v1.0.0
388
-
389
- # The script will:
390
- # 1. Authenticate with AWS ECR
391
- # 2. Build the Docker image
392
- # 3. Tag with version and 'latest'
393
- # 4. Push to ECR
394
- ```
395
-
396
- ### Project Structure
397
-
398
- ```
399
- agent/
400
- ├── index.js # Main entry point
401
- ├── auth.js # Authentication & session management
402
- ├── containerManager.js # Docker container operations
403
- ├── websocket-server.js # WebSocket server setup
404
- ├── cli-commands.js # CLI command definitions
405
- ├── docker-actions/ # WebSocket action handlers
406
- │ ├── containers.js # Container operations
407
- │ ├── images.js # Image operations
408
- │ ├── volumes.js # Volume operations
409
- │ ├── apps.js # Application management
410
- │ ├── registry.js # Registry operations
411
- │ ├── logs.js # Log streaming
412
- │ ├── metrics.js # Metrics collection
413
- │ ├── terminal.js # Terminal sessions
414
- │ └── general.js # General utilities
415
- ├── store/ # Persistent storage
416
- │ ├── agentStore.js # Agent info storage
417
- │ └── registryStore.js # Registry configurations
418
- ├── package.json # Dependencies
419
- ├── .env.example # Environment template
420
- └── README.md # This file
421
- ```
422
-
423
- ## Support
424
-
425
- For issues, questions, or feature requests:
57
+ **Agent won't start?**
58
+ - Ensure Docker Desktop is running
59
+ - Check your network connection
60
+ - Try `fenwave logout` then `fenwave login`
426
61
 
427
- 1. Check the [Troubleshooting](#troubleshooting) section
428
- 2. Review the [Fenwave documentation](https://docs.fenwave.com)
429
- 3. Contact your Fenwave administrator
430
- 4. File an issue in the repository (if applicable)
62
+ **Need help?**
63
+ - Run `fenwave --help` for command options
64
+ - Contact your Fenwave administrator
431
65
 
432
66
  ## License
433
67
 
434
- Copyright © 2025 Fenwave. All rights reserved.
68
+ Copyright 2025 Fenwave. All rights reserved. See [LICENSE](LICENSE) for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fenwave/agent",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Fenwave Docker Agent and CLI",
5
5
  "keywords": [
6
6
  "fenwave",