jac-scale 0.1.1__py3-none-any.whl

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 (57) hide show
  1. jac_scale/__init__.py +0 -0
  2. jac_scale/abstractions/config/app_config.jac +30 -0
  3. jac_scale/abstractions/config/base_config.jac +26 -0
  4. jac_scale/abstractions/database_provider.jac +51 -0
  5. jac_scale/abstractions/deployment_target.jac +64 -0
  6. jac_scale/abstractions/image_registry.jac +54 -0
  7. jac_scale/abstractions/logger.jac +20 -0
  8. jac_scale/abstractions/models/deployment_result.jac +27 -0
  9. jac_scale/abstractions/models/resource_status.jac +38 -0
  10. jac_scale/config_loader.jac +31 -0
  11. jac_scale/context.jac +14 -0
  12. jac_scale/factories/database_factory.jac +43 -0
  13. jac_scale/factories/deployment_factory.jac +43 -0
  14. jac_scale/factories/registry_factory.jac +32 -0
  15. jac_scale/factories/utility_factory.jac +34 -0
  16. jac_scale/impl/config_loader.impl.jac +131 -0
  17. jac_scale/impl/context.impl.jac +24 -0
  18. jac_scale/impl/memory_hierarchy.main.impl.jac +63 -0
  19. jac_scale/impl/memory_hierarchy.mongo.impl.jac +239 -0
  20. jac_scale/impl/memory_hierarchy.redis.impl.jac +186 -0
  21. jac_scale/impl/serve.impl.jac +1785 -0
  22. jac_scale/jserver/__init__.py +0 -0
  23. jac_scale/jserver/impl/jfast_api.impl.jac +731 -0
  24. jac_scale/jserver/impl/jserver.impl.jac +79 -0
  25. jac_scale/jserver/jfast_api.jac +162 -0
  26. jac_scale/jserver/jserver.jac +101 -0
  27. jac_scale/memory_hierarchy.jac +138 -0
  28. jac_scale/plugin.jac +218 -0
  29. jac_scale/plugin_config.jac +175 -0
  30. jac_scale/providers/database/kubernetes_mongo.jac +137 -0
  31. jac_scale/providers/database/kubernetes_redis.jac +110 -0
  32. jac_scale/providers/registry/dockerhub.jac +64 -0
  33. jac_scale/serve.jac +118 -0
  34. jac_scale/targets/kubernetes/kubernetes_config.jac +215 -0
  35. jac_scale/targets/kubernetes/kubernetes_target.jac +841 -0
  36. jac_scale/targets/kubernetes/utils/kubernetes_utils.impl.jac +519 -0
  37. jac_scale/targets/kubernetes/utils/kubernetes_utils.jac +85 -0
  38. jac_scale/tests/__init__.py +0 -0
  39. jac_scale/tests/conftest.py +29 -0
  40. jac_scale/tests/fixtures/test_api.jac +159 -0
  41. jac_scale/tests/fixtures/todo_app.jac +68 -0
  42. jac_scale/tests/test_abstractions.py +88 -0
  43. jac_scale/tests/test_deploy_k8s.py +265 -0
  44. jac_scale/tests/test_examples.py +484 -0
  45. jac_scale/tests/test_factories.py +149 -0
  46. jac_scale/tests/test_file_upload.py +444 -0
  47. jac_scale/tests/test_k8s_utils.py +156 -0
  48. jac_scale/tests/test_memory_hierarchy.py +247 -0
  49. jac_scale/tests/test_serve.py +1835 -0
  50. jac_scale/tests/test_sso.py +711 -0
  51. jac_scale/utilities/loggers/standard_logger.jac +40 -0
  52. jac_scale/utils.jac +16 -0
  53. jac_scale-0.1.1.dist-info/METADATA +658 -0
  54. jac_scale-0.1.1.dist-info/RECORD +57 -0
  55. jac_scale-0.1.1.dist-info/WHEEL +5 -0
  56. jac_scale-0.1.1.dist-info/entry_points.txt +3 -0
  57. jac_scale-0.1.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,40 @@
1
+ """Standard logger implementation using jac console."""
2
+ import from typing { Any }
3
+ import from jac_scale.abstractions.logger { Logger }
4
+ import from jaclang.cli.console { console }
5
+
6
+ """Standard logger using jac console for Rich-styled output."""
7
+ class StandardLogger(Logger) {
8
+ def init(self: StandardLogger, config: dict[str, Any] = {}) -> None { }
9
+ def info(self: StandardLogger, message: str, context: dict[str, Any] = {}) -> None {
10
+ if context {
11
+ console.info(f"{message} | Context: {context}");
12
+ } else {
13
+ console.info(message);
14
+ }
15
+ }
16
+
17
+ def error(self: StandardLogger, message: str, context: dict[str, Any] = {}) -> None {
18
+ if context {
19
+ console.error(f"{message} | Context: {context}");
20
+ } else {
21
+ console.error(message);
22
+ }
23
+ }
24
+
25
+ def warn(self: StandardLogger, message: str, context: dict[str, Any] = {}) -> None {
26
+ if context {
27
+ console.warning(f"{message} | Context: {context}");
28
+ } else {
29
+ console.warning(message);
30
+ }
31
+ }
32
+
33
+ def debug(self: StandardLogger, message: str, context: dict[str, Any] = {}) -> None {
34
+ if context {
35
+ console.print(f"[DEBUG] {message} | Context: {context}", style="muted");
36
+ } else {
37
+ console.print(f"[DEBUG] {message}", style="muted");
38
+ }
39
+ }
40
+ }
jac_scale/utils.jac ADDED
@@ -0,0 +1,16 @@
1
+ import random;
2
+ import string;
3
+
4
+ """Generate a random password with specified length.
5
+
6
+ Args:
7
+ length: The length of the password to generate (default: 8)
8
+
9
+ Returns:
10
+ A random password string containing letters, digits, and special characters
11
+ """
12
+ def generate_random_password(length: int = 8) -> str {
13
+ characters = string.ascii_letters + string.digits + string.punctuation;
14
+ password_chars = [random.choice(characters) for _ in range(length)];
15
+ return ''.join(password_chars);
16
+ }
@@ -0,0 +1,658 @@
1
+ Metadata-Version: 2.4
2
+ Name: jac-scale
3
+ Version: 0.1.1
4
+ Author-email: Jason Mars <jason@mars.ninja>
5
+ Requires-Python: >=3.12
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: jaclang>=0.9.10
8
+ Requires-Dist: python-dotenv<2.0.0,>=1.2.1
9
+ Requires-Dist: docker<8.0.0,>=7.1.0
10
+ Requires-Dist: kubernetes<35.0.0,>=34.1.0
11
+ Requires-Dist: pymongo<5.0.0,>=4.15.4
12
+ Requires-Dist: redis<8.0.0,>=7.1.0
13
+ Requires-Dist: fastapi<0.122.0,>=0.121.3
14
+ Requires-Dist: uvicorn<0.39.0,>=0.38.0
15
+ Requires-Dist: pyjwt
16
+ Requires-Dist: fastapi-sso<1.0.0,>=0.18.0
17
+ Requires-Dist: python-multipart<1.0.0,>=0.0.21
18
+
19
+ # JAC Scale Deployment Guide
20
+
21
+ ## Overview
22
+
23
+ `jac start --scale` is a comprehensive deployment and scaling solution for JAC applications that provides three powerful capabilities:
24
+
25
+ ### 1. Multi-Layer Memory Architecture
26
+
27
+ - **Caching Layer**: Redis for high-speed data access and session management
28
+ - **Persistence Storage**: MongoDB for reliable, long-term data storage
29
+ - **Optimized Performance**: Intelligent caching strategy to minimize database load and maximize response times
30
+
31
+ ### 2. FastAPI Integration with Swagger Documentation
32
+
33
+ - Automatically converts JAC walkers and functions into RESTful FastAPI endpoints
34
+ - Built-in Swagger/OpenAPI documentation for easy API exploration and testing
35
+ - Interactive API interface accessible at `/docs` endpoint
36
+
37
+ ### 3. Kubernetes Deployment & Auto-Scaling
38
+
39
+ - **Easy Deployment**: One-command deployment to Kubernetes clusters
40
+ - **Auto-Scaling**: Scale your application based on demand
41
+ - **Database Auto-Provisioning**: Automatically spawns and configures Redis and MongoDB instances
42
+ - **Production-Ready**: Built-in health checks, persistent storage, and service discovery
43
+
44
+ Whether you're developing locally with `jac start` or deploying to production with `jac start --scale`, you get the same powerful features with the flexibility to choose your deployment strategy.
45
+
46
+ ## Prerequisites
47
+
48
+ - kubenetes(K8s) installed
49
+ - [Minikube Kubernetes](https://minikube.sigs.k8s.io/docs/start/?arch=%2Fwindows%2Fx86-64%2Fstable%2F.exe+download/) (for Windows/Linux)
50
+ - [Docker Desktop with Kubernetes](https://www.docker.com/resources/kubernetes-and-docker/) (alternative for Windows - easier setup)
51
+
52
+ **Note:** Kubernetes is only needed if you are planning to use `jac start --scale`. If you only want to use `jac start`, Kubernetes is not required.
53
+
54
+ ## Quick Start: Running the Travel Planner Demo Application
55
+
56
+ Follow these steps to set up and test the Travel Planner JAC application
57
+
58
+ ### 1. Clone the Jaseci Repository
59
+
60
+ First, clone the main Jaseci repository which contains JAC and JAC-Scale:
61
+
62
+ ```bash
63
+ git clone https://github.com/jaseci-labs/jaseci.git
64
+ cd jaseci
65
+ git submodule update --init --recursive
66
+ ```
67
+
68
+ ### 2. Create Python Virtual Environment
69
+
70
+ ```bash
71
+ python -m venv venv
72
+ ```
73
+
74
+ ### 3. Activate the Virtual Environment
75
+
76
+ **Linux/Mac:**
77
+
78
+ ```bash
79
+ source venv/bin/activate
80
+ ```
81
+
82
+ **Windows:**
83
+
84
+ ```bash
85
+ venv\Scripts\activate
86
+ ```
87
+
88
+ ### 4. Install JAC and JAC-Scale
89
+
90
+ Install both packages in editable mode from the cloned repository:
91
+
92
+ ```bash
93
+ pip install -e ./jac
94
+ pip install -e ./jac-scale
95
+ ```
96
+
97
+ ### 5. Download the Demo Application
98
+
99
+ Download the Travel Planner demo application from GitHub:
100
+
101
+ **Option A: Using Git Clone (Recommended)**
102
+
103
+ ```bash
104
+ # Navigate back to parent directory or choose a location
105
+ cd ..
106
+
107
+ # Clone the entire repository
108
+ git clone https://github.com/jaseci-labs/Agentic-AI.git
109
+
110
+ # Navigate to the Travel Planner backend and rename
111
+ mv Agentic-AI/Travel_planner/BE traveller
112
+ cd traveller
113
+ ```
114
+
115
+ **Option B: Download Specific Folder**
116
+
117
+ If you only want the Travel Planner backend:
118
+
119
+ ```bash
120
+ # Navigate back to parent directory
121
+ cd ..
122
+
123
+ # Install GitHub CLI if not already installed
124
+ # For Linux/Mac with Homebrew:
125
+ brew install gh
126
+
127
+ # For Windows with Chocolatey:
128
+ choco install gh
129
+
130
+ # Clone only the specific folder
131
+ gh repo clone jaseci-labs/Agentic-AI
132
+ mv Agentic-AI/Travel_planner/BE traveller
133
+ cd traveller
134
+ ```
135
+
136
+ **Option C: Manual Download**
137
+
138
+ 1. Go to https://github.com/jaseci-labs/Agentic-AI/tree/main/Travel_planner/BE
139
+ 2. Click on the green "Code" button
140
+ 3. Select "Download ZIP"
141
+ 4. Extract the ZIP file
142
+ 5. Rename the `BE` folder to `traveller`
143
+ 6. Navigate into the folder:
144
+
145
+ ```bash
146
+ cd traveller
147
+ ```
148
+
149
+ ### 6. Configure Environment Variables
150
+
151
+ You should now be in the `traveller` folder. Create a `.env` file:
152
+
153
+ ```bash
154
+ # Verify you're in the correct directory
155
+ pwd # Should show path ending in /traveller
156
+
157
+ # Create .env file
158
+ touch .env # Linux/Mac
159
+ # OR
160
+ type nul > .env # Windows CMD
161
+ # OR
162
+ New-Item .env # Windows PowerShell
163
+ ```
164
+
165
+ Add the following to your `.env` file:
166
+
167
+ ```env
168
+ OPENAI_API_KEY=your-openai-api-key-here
169
+ ```
170
+
171
+ ### 7. Install Demo Application Requirements
172
+
173
+ ```bash
174
+ pip install byllm python-dotenv
175
+ ```
176
+
177
+ ### 8. Run the Application with JAC Start
178
+
179
+ To run your application using FastAPI with ShelfStorage (no Kubernetes required):
180
+
181
+ ```bash
182
+ jac start main.jac
183
+ ```
184
+
185
+ **What this does:**
186
+
187
+ - Starts your JAC application as a FastAPI server
188
+ - Uses ShelfStorage for persisting anchors (lightweight, file-based storage)
189
+ - No database setup required
190
+ - Ideal for development and testing
191
+
192
+ **Access your application:**
193
+
194
+ - Application: http://localhost:8000
195
+ - Swagger Documentation: http://localhost:8000/docs
196
+
197
+ ### 9. Set Up Kubernetes (For JAC Scale)
198
+
199
+ To use `jac start --scale`, you need Kubernetes installed on your machine.
200
+
201
+ **Option A: MicroK8s (Windows/Linux/Mac)**
202
+
203
+ - [Official MicroK8s installation guide](https://microk8s.io/)
204
+ - [ubunutu installation guide](https://www.digitalocean.com/community/tutorials/how-to-setup-a-microk8s-kubernetes-cluster-on-ubuntu-22-04)
205
+
206
+ **Option B: Docker Desktop with Kubernetes (Windows - Recommended)**
207
+
208
+ - Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
209
+ - Enable Kubernetes in Docker Desktop settings (easier setup)
210
+
211
+ ### 10. Deploy with JAC Scale
212
+
213
+ Once Kubernetes is running, you have two deployment methods:
214
+
215
+ #### Method A: Deploy Without Building (Faster)
216
+
217
+ Deploy your application to Kubernetes without building a Docker image:
218
+
219
+ ```bash
220
+ jac start main.jac --scale
221
+ ```
222
+
223
+ **What this does:**
224
+
225
+ - Deploys your JAC application to Kubernetes
226
+ - Automatically provisions Redis and MongoDB as persistence storage
227
+ - Creates necessary Kubernetes resources (Deployments, Services, StatefulSets)
228
+ - Exposes your application via NodePort
229
+
230
+ **Access your application:**
231
+
232
+ - Application: http://localhost:30001
233
+ - Swagger Documentation: http://localhost:30001/docs
234
+
235
+ **Use this when:**
236
+
237
+ - You want faster deployments without rebuilding
238
+ - You're testing configuration changes
239
+ - You're in development mode
240
+
241
+ #### Method B: Build, Push, and Deploy (Production)
242
+
243
+ Build your application as a Docker container and deploy it:
244
+
245
+ **Prerequisites:**
246
+
247
+ 1. Create a `Dockerfile` in your `traveller` directory
248
+ 2. Add Docker credentials to your `.env` file:
249
+
250
+ ```env
251
+ OPENAI_API_KEY=your-openai-api-key-here
252
+ DOCKER_USERNAME=your-dockerhub-username
253
+ DOCKER_PASSWORD=your-dockerhub-password-or-token
254
+ ```
255
+
256
+ **Deploy with build:**
257
+
258
+ ```bash
259
+ jac start main.jac --scale --build
260
+ ```
261
+
262
+ **What this does:**
263
+
264
+ - Builds a Docker image of your JAC application
265
+ - Pushes the image to DockerHub
266
+ - Deploys the image to Kubernetes
267
+ - Sets up Redis and MongoDB for persistence
268
+
269
+ **Access your application:**
270
+
271
+ - Application: http://localhost:30001
272
+ - Swagger Documentation: http://localhost:30001/docs
273
+
274
+ **Use this when:**
275
+
276
+ - Deploying to production
277
+ - You want to version and host your Docker image
278
+ - Sharing your application with others
279
+ - Creating reproducible deployments
280
+
281
+ ### 11. Clean Up Kubernetes Resources
282
+
283
+ When you're done testing, remove all created Kubernetes resources:
284
+
285
+ ```bash
286
+ jac destroy main.jac
287
+ ```
288
+
289
+ **What this does:**
290
+
291
+ - Deletes all Kubernetes deployments, services, and StatefulSets
292
+ - Removes persistent volumes and claims
293
+ - Cleans up the namespace (if custom namespace was used)
294
+
295
+ ## Quick Start: Running Todo application with frontend
296
+
297
+ Follow these steps to set up and test the Todo application with frontend
298
+
299
+ ### 1. Clone the Jaseci Repository
300
+
301
+ First, clone the main Jaseci repository which contains JAC and JAC-Scale:
302
+
303
+ ```bash
304
+ git clone https://github.com/jaseci-labs/jaseci.git
305
+ cd jaseci
306
+ git submodule update --init --recursive
307
+ ```
308
+
309
+ ### 2. Create Python Virtual Environment
310
+
311
+ ```bash
312
+ python -m venv venv
313
+ ```
314
+
315
+ ### 3. Activate the Virtual Environment
316
+
317
+ **Linux/Mac:**
318
+
319
+ ```bash
320
+ source venv/bin/activate
321
+ ```
322
+
323
+ **Windows:**
324
+
325
+ ```bash
326
+ venv\Scripts\activate
327
+ ```
328
+
329
+ ### 4. Install JAC, JAC-Scale and JAC-Client
330
+
331
+ Install the packages in editable mode from the cloned repository:
332
+
333
+ ```bash
334
+ pip install -e ./jac
335
+ pip install -e ./jac-scale
336
+ pip install -e ./jac-client
337
+ ```
338
+
339
+ ### 5. Create Todo application using jac-client
340
+
341
+ Lets create the todo application using jac client.For that lets run following command
342
+
343
+ ```bash
344
+ jac create_jac_app todo
345
+ ```
346
+
347
+ Then lets copy the todo fully implemented jac code available inside jac-scale/examples/todo to our newly created /todo folder
348
+
349
+ ```bash
350
+ cp jac-scale/examples/todo/app.jac todo/app.jac
351
+ cd todo
352
+ ```
353
+
354
+ ### 8. Run the Application Locally
355
+
356
+ To run your application run the following command
357
+
358
+ ```bash
359
+ jac start app.jac
360
+ ```
361
+
362
+ **Access your application:**
363
+
364
+ - Frontend: http://localhost:8000/cl/app
365
+ - Backend: http://localhost:8000
366
+ - Swagger Documentation: http://localhost:8000/docs
367
+
368
+ you can add new todo tasks
369
+ from the frontend at http://localhost:8000/cl/app
370
+
371
+ ### 9. Set Up Kubernetes (For JAC Scale)
372
+
373
+ To use `jac start --scale`, you need Kubernetes installed on your machine.
374
+
375
+ **Option A: MicroK8 (Windows/Linux/Mac)**
376
+
377
+ - [Official MicroK8 installation guide](https://microk8s.io/)
378
+ - [ubunutu installation guide](https://www.digitalocean.com/community/tutorials/how-to-setup-a-microk8s-kubernetes-cluster-on-ubuntu-22-04)
379
+
380
+ **Option B: Docker Desktop with Kubernetes (Windows - Recommended)**
381
+
382
+ - Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
383
+ - Enable Kubernetes in Docker Desktop settings (easier setup)
384
+
385
+ ### 10. Deploy with JAC Scale
386
+
387
+ Once Kubernetes is running, you have two deployment methods:
388
+
389
+ #### Method A: Deploy Without Building (Faster)
390
+
391
+ Deploy your application to Kubernetes without building a Docker image:
392
+
393
+ ```bash
394
+ jac start app.jac --scale
395
+ ```
396
+
397
+ **Access your application:**
398
+
399
+ - Frontend: http://localhost:30001/cl/app
400
+ - Backend: http://localhost:30001
401
+ - Swagger Documentation: http://localhost:30001/docs
402
+
403
+ **Use this when:**
404
+
405
+ - You want faster deployments without rebuilding
406
+ - You're testing configuration changes
407
+ - You're in development mode
408
+
409
+ #### Method B: Build, Push, and Deploy (Production)
410
+
411
+ To Build your application as a Docker container and deploy it you can run
412
+
413
+ ```bash
414
+ jac start app.jac --scale --build
415
+ ```
416
+
417
+ **Access your application:**
418
+
419
+ - Frontend: http://localhost:30001/cl/app
420
+ - Backend: http://localhost:30001
421
+ - Swagger Documentation: http://localhost:30001/docs
422
+
423
+ **Use this when:**
424
+
425
+ - Deploying to production
426
+ - You want to version and host your Docker image
427
+ - Sharing your application with others
428
+ - Creating reproducible deployments
429
+
430
+ ### 11. Clean Up Kubernetes Resources
431
+
432
+ When you're done testing, remove all created Kubernetes resources:
433
+
434
+ ```bash
435
+ jac destroy app.jac
436
+ ```
437
+
438
+ **What this does:**
439
+
440
+ - Deletes all Kubernetes deployments, services, and StatefulSets
441
+ - Removes persistent volumes and claims
442
+ - Cleans up the namespace (if custom namespace was used)
443
+
444
+ ## Async Walkers
445
+
446
+ JAC Scale supports async walkers for non-blocking operations like external API calls, database queries, and file I/O.
447
+
448
+ ```
449
+ import asyncio;
450
+
451
+ async walker FetchData {
452
+ has url: str;
453
+
454
+ async can fetch with `root entry {
455
+ report {"status": "fetching"};
456
+ await asyncio.sleep(0.1); # Simulate API call
457
+ report {"status": "completed", "data": "result"};
458
+ }
459
+ }
460
+ ```
461
+
462
+ ## Configuration Options
463
+
464
+ ### Optional Environment Variables
465
+
466
+ | Parameter | Description | Default |
467
+ |-----------|-------------|---------|
468
+ | `APP_NAME` | Name of your JAC application | `jaseci` |
469
+ | `DOCKER_USERNAME` | DockerHub username for pushing the image | - |
470
+ | `DOCKER_PASSWORD` | DockerHub password or access token | - |
471
+ | `K8s_NAMESPACE` | Kubernetes namespace to deploy the application | `default` |
472
+ | `K8s_NODE_PORT` | Port in which your local kubernetes application will run on| `30001` |
473
+ | `K8s_CPU_REQUEST` | CPU request for the application container | - |
474
+ | `K8s_CPU_LIMIT` | CPU limit for the application container | - |
475
+ | `K8s_MEMORY_REQUEST` | Memory request for the application container | - |
476
+ | `K8s_MEMORY_LIMIT` | Memory limit for the application container | - |
477
+ | `K8s_READINESS_INITIAL_DELAY` | Seconds before readiness probe first checks the pod | `10` |
478
+ | `K8s_READINESS_PERIOD` | Seconds between readiness probe checks | `20` |
479
+ | `K8s_LIVENESS_INITIAL_DELAY` | Seconds before liveness probe first checks the pod | `10` |
480
+ | `K8s_LIVENESS_PERIOD` | Seconds between liveness probe checks | `20` |
481
+ | `K8s_LIVENESS_FAILURE_THRESHOLD` | Consecutive liveness probe failures before restart | `80` |
482
+ | `K8s_MONGODB` | Whether MongoDB is needed (`True`/`False`) | `True` |
483
+ | `K8s_REDIS` | Whether Redis is needed (`True`/`False`) | `True` |
484
+ | `MONGODB_URI` | URL of MongoDB database | - |
485
+ | `REDIS_URL` | URL of Redis database | - |
486
+ | `JWT_EXP_DELTA_DAYS` | Number of days until JWT token expires | `7` |
487
+ | `JWT_SECRET` | Secret key used for JWT token signing and verification | `'supersecretkey'` |
488
+ | `JWT_ALGORITHM` | Algorithm used for JWT token encoding/decoding | `'HS256'` |
489
+ | `SSO_HOST` | SSO host URL | `'http://localhost:8000/sso'` |
490
+ | `SSO_GOOGLE_CLIENT_ID` | Google OAuth client ID | - |
491
+ | `SSO_GOOGLE_CLIENT_SECRET` | Google OAuth client secret | - |
492
+
493
+ ## Deployment Modes
494
+
495
+ ### Mode 1: Deploy Without Building (Default)
496
+
497
+ Deploys your JAC application to Kubernetes without building a Docker image.
498
+
499
+ ```bash
500
+ jac start main.jac --scale
501
+ ```
502
+
503
+ **Use this when:**
504
+
505
+ - You want faster deployments without rebuilding
506
+ - You're testing configuration changes
507
+ - You're in development mode
508
+
509
+ ### Mode 2: Build, Push, and Deploy
510
+
511
+ Builds a new Docker image, pushes it to DockerHub, then deploys to Kubernetes.
512
+
513
+ ```bash
514
+ jac start main.jac --scale --build
515
+ ```
516
+
517
+ **Requirements for Build Mode:**
518
+
519
+ - A `Dockerfile` in your application directory
520
+ - Environment variables set:
521
+ - `DOCKER_USERNAME` - Your DockerHub username
522
+ - `DOCKER_PASSWORD` - Your DockerHub password/access token
523
+
524
+ **Use this when:**
525
+
526
+ - Deploying to production
527
+ - You want to version and host your Docker image
528
+ - Sharing your application with others
529
+
530
+ ## Important Notes
531
+
532
+ ### Implementation
533
+
534
+ - The jac-scale plugin is implemented using **Python and Kubernetes Python client libraries**
535
+ - **No custom Kubernetes controllers** are used → easier to deploy and maintain
536
+
537
+ ### Database Provisioning
538
+
539
+ - Databases are created as **StatefulSets** with persistent storage
540
+ - Databases are **only created on the first run**
541
+ - Subsequent `jac start --scale` calls only update application deployments
542
+ - This ensures persistent storage and avoids recreating databases unnecessarily
543
+
544
+ ### Performance
545
+
546
+ - **First-time deployment** may take longer due to database provisioning and image downloading
547
+ - **Subsequent deployments** are faster since:
548
+ - Only the application's final Docker layer is pushed and pulled
549
+ - Only deployments are updated (databases remain unchanged)
550
+
551
+ ## Deployment Process
552
+
553
+ When you run `jac start --scale`, the following steps are executed:
554
+
555
+ ### 1. Create JAC Application Docker Image
556
+
557
+ - Build the application image from the source directory
558
+ - Tag the image with DockerHub repository
559
+
560
+ ### 2. Push Docker Image to DockerHub (Build Mode Only)
561
+
562
+ - Authenticate using `DOCKER_USERNAME` and `DOCKER_PASSWORD`
563
+ - Push the image to DockerHub
564
+ - Subsequent pushes are faster since only the final image layer is pushed
565
+
566
+ ### 3. Deploy to Kubernetes
567
+
568
+ - Create or update Kubernetes namespace
569
+ - Deploy Redis and MongoDB (first run only)
570
+ - Create application deployment
571
+ - Create services and expose via NodePort
572
+
573
+ ## Architecture
574
+
575
+ ### K8s pods structure
576
+
577
+ ![K8s pod structure](assets/jac-scale-architecture.svg)
578
+
579
+ ## Troubleshooting
580
+
581
+ ### Common Issues
582
+
583
+ **Kubernetes cluster not accessible:**
584
+
585
+ - Ensure Kubernetes is running: `kubectl cluster-info`
586
+ - Check your kubeconfig: `kubectl config view`
587
+
588
+ **DockerHub authentication fails:**
589
+
590
+ - Verify your `DOCKER_USERNAME` and `DOCKER_PASSWORD` are correct
591
+ - Ensure you're using an access token (not password) if 2FA is enabled
592
+
593
+ **Namespace doesn't exist:**
594
+
595
+ - The plugin creates namespaces automatically
596
+ - If using a custom namespace, ensure proper permissions
597
+
598
+ **Database connection issues:**
599
+
600
+ - Verify StatefulSets are running: `kubectl get statefulsets -n <namespace>`
601
+ - Check pod logs: `kubectl logs <pod-name> -n <namespace>`
602
+ - Ensure persistent volumes are bound: `kubectl get pvc -n <namespace>`
603
+
604
+ **Application not accessible:**
605
+
606
+ - Check service exposure: `kubectl get svc -n <namespace>`
607
+ - Verify NodePort is not blocked by firewall
608
+ - For Minikube, use: `minikube service <service-name> -n <namespace>`
609
+
610
+ **Build failures:**
611
+
612
+ - Ensure Dockerfile exists in your application directory
613
+ - Check Docker daemon is running
614
+ - Verify sufficient disk space for image building
615
+
616
+ ### Getting Help
617
+
618
+ If you encounter issues:
619
+
620
+ 1. Check pod status: `kubectl get pods -n <namespace>`
621
+ 2. View pod logs: `kubectl logs <pod-name> -n <namespace>`
622
+ 3. Describe resources: `kubectl describe <resource-type> <resource-name> -n <namespace>`
623
+
624
+ ## Tested Examples
625
+
626
+ You can find more working examples in the examples directory:
627
+
628
+ <!-- - [basic](../jac-client/jac_client/examples/basic/) - Minimal JAC application -->
629
+ <!-- - [basic-full-stack](../jac-client/jac_client/examples/basic-full-stack/) - Basic full-stack application -->
630
+ - [all-in-one](../jac-client/jac_client/examples/all-in-one/) - Complete example with all features
631
+ - [with-router](../jac-client/jac_client/examples/with-router/) - Application with routing
632
+ <!-- - [nested-folders/nested-basic](../jac-client/jac_client/examples/nested-folders/nested-basic/) - Basic nested folder structure -->
633
+ - [nested-folders/nested-advance](../jac-client/jac_client/examples/nested-folders/nested-advance/) - Advanced nested folder structure
634
+ - [basic-auth](../jac-client/jac_client/examples/basic-auth/) - Basic authentication
635
+ - [basic-auth-with-router](../jac-client/jac_client/examples/basic-auth-with-router/) - Authentication with routing
636
+ <!-- - [full-stack-with-auth](../jac-client/jac_client/examples/full-stack-with-auth/) - Full-stack app with authentication -->
637
+ - [css-styling/js-styling](../jac-client/jac_client/examples/css-styling/js-styling/) - JavaScript styling example
638
+ - [css-styling/material-ui](../jac-client/jac_client/examples/css-styling/material-ui/) - Material-UI styling example
639
+ - [css-styling/pure-css](../jac-client/jac_client/examples/css-styling/pure-css/) - Pure CSS styling example
640
+ - [css-styling/sass-example](../jac-client/jac_client/examples/css-styling/sass-example/) - SASS styling example
641
+ - [css-styling/styled-components](../jac-client/jac_client/examples/css-styling/styled-components/) - Styled Components example
642
+ - [css-styling/tailwind-example](../jac-client/jac_client/examples/css-styling/tailwind-example/) - Tailwind CSS example
643
+ - [asset-serving/css-with-image](../jac-client/jac_client/examples/asset-serving/css-with-image/) - CSS with image assets
644
+ - [asset-serving/image-asset](../jac-client/jac_client/examples/asset-serving/image-asset/) - Image asset serving
645
+ - [asset-serving/import-alias](../jac-client/jac_client/examples/asset-serving/import-alias/) - Import alias example
646
+ <!-- - [little-x](../jac-client/jac_client/examples/little-x/) - Little X application example -->
647
+
648
+ Each example includes complete source code and can be run with `jac start`.
649
+
650
+ ## Next Steps
651
+
652
+ After successfully running the demo:
653
+
654
+ - **For local development (`jac start`)**: Access your application at http://localhost:8000 and explore the Swagger documentation at http://localhost:8000/docs
655
+ - **For Kubernetes (`jac start --scale`)**: Access your application at http://localhost:30001 and explore the Swagger documentation at http://localhost:30001/docs
656
+ - Modify the JAC application and redeploy
657
+ - Experiment with different configuration options
658
+ - Try deploying to a production Kubernetes cluster