-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulate_build.py
More file actions
462 lines (382 loc) · 15.3 KB
/
simulate_build.py
File metadata and controls
462 lines (382 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
#!/usr/bin/env python3
"""Simulate and validate LabLink deployment package builds."""
import os
import sys
from pathlib import Path
import json
import hashlib
def print_header(text):
"""Print formatted header."""
print("\n" + "=" * 70)
print(f" {text}")
print("=" * 70)
def print_section(text):
"""Print section header."""
print(f"\n--- {text} ---")
def calculate_size(directory):
"""Calculate directory size."""
total = 0
for root, dirs, files in os.walk(directory):
for file in files:
filepath = os.path.join(root, file)
if os.path.exists(filepath):
total += os.path.getsize(filepath)
return total
def format_size(bytes_size):
"""Format bytes to human readable."""
for unit in ['B', 'KB', 'MB', 'GB']:
if bytes_size < 1024.0:
return f"{bytes_size:.1f} {unit}"
bytes_size /= 1024.0
return f"{bytes_size:.1f} TB"
def validate_dockerfile():
"""Validate Dockerfile."""
print_section("Validating Dockerfile")
dockerfile = Path("Dockerfile")
if not dockerfile.exists():
print("✗ Dockerfile not found")
return False
with open(dockerfile) as f:
content = f.read()
checks = [
("FROM python:3.12", "Base image"),
("WORKDIR /app", "Working directory"),
("COPY server/requirements.txt", "Requirements copy"),
("RUN pip install", "Dependency installation"),
("EXPOSE 8000 8001", "Port exposure"),
("CMD", "Start command"),
("HEALTHCHECK", "Health check"),
]
all_passed = True
for check, description in checks:
if check in content:
print(f" ✓ {description}")
else:
print(f" ✗ {description} - missing '{check}'")
all_passed = False
return all_passed
def validate_docker_compose():
"""Validate docker-compose.yml."""
print_section("Validating docker-compose.yml")
compose_file = Path("docker-compose.yml")
if not compose_file.exists():
print("✗ docker-compose.yml not found")
return False
with open(compose_file) as f:
content = f.read()
checks = [
("version:", "Version specified"),
("services:", "Services defined"),
("lablink-server:", "Server service"),
("ports:", "Port mapping"),
("volumes:", "Volume mounts"),
("restart:", "Restart policy"),
("healthcheck:", "Health check"),
]
all_passed = True
for check, description in checks:
if check in content:
print(f" ✓ {description}")
else:
print(f" ✗ {description}")
all_passed = False
return all_passed
def validate_pyinstaller_spec():
"""Validate PyInstaller spec file."""
print_section("Validating PyInstaller Spec")
spec_file = Path("client/lablink.spec")
if not spec_file.exists():
print("✗ lablink.spec not found")
return False
with open(spec_file) as f:
content = f.read()
checks = [
("Analysis(", "Analysis configuration"),
("['main.py']", "Entry point"),
("PyQt6", "PyQt6 imports"),
("EXE(", "Executable configuration"),
("console=False", "Windowed mode"),
("BUNDLE(", "macOS bundle (optional)"),
]
all_passed = True
for check, description in checks:
if check in content:
print(f" ✓ {description}")
else:
if "optional" not in description:
print(f" ⚠ {description}")
else:
print(f" ○ {description}")
return True
def simulate_docker_build():
"""Simulate Docker build process."""
print_section("Simulating Docker Build")
print("\nBuild Command:")
print(" $ docker build -t lablink-server:0.10.0 .")
print("\nBuild Steps:")
steps = [
("Step 1/12", "FROM python:3.12-slim", "Pulling base image"),
("Step 2/12", "RUN apt-get update", "Installing system dependencies"),
("Step 3/12", "WORKDIR /app", "Setting working directory"),
("Step 4/12", "COPY server/requirements.txt", "Copying requirements"),
("Step 5/12", "RUN pip install", "Installing Python packages (this takes time)"),
("Step 6/12", "COPY server/", "Copying application code"),
("Step 7/12", "RUN mkdir -p", "Creating directories"),
("Step 8/12", "EXPOSE 8000 8001", "Exposing ports"),
("Step 9/12", "ENV LABLINK_", "Setting environment variables"),
("Step 10/12", "RUN useradd", "Creating user"),
("Step 11/12", "USER lablink", "Switching to non-root user"),
("Step 12/12", "CMD [\"python\", \"main.py\"]", "Setting start command"),
]
for step, command, description in steps:
print(f" {step}: {command}")
print(f" → {description}")
print("\nExpected Output:")
print(" Successfully built abc123def456")
print(" Successfully tagged lablink-server:0.10.0")
print("\nEstimated Image Size: 250-350 MB")
print(" • Base image: ~150 MB")
print(" • System deps: ~20 MB")
print(" • Python deps: ~80 MB")
print(" • Application: ~10 MB")
def simulate_pyinstaller_build():
"""Simulate PyInstaller build process."""
print_section("Simulating PyInstaller Build")
print("\nBuild Command:")
print(" $ pyinstaller client/lablink.spec")
print("\nBuild Steps:")
steps = [
("Analyzing", "Reading spec file and dependencies"),
("Building Analysis", "Scanning imports and hidden imports"),
("Building PYZ", "Compressing Python modules"),
("Building EXE", "Creating executable"),
("Building BUNDLE", "Creating macOS app (macOS only)"),
]
for step, description in steps:
print(f" {step}...")
print(f" → {description}")
print("\nExpected Output:")
print(" Successfully built executable")
print(" Location: client/dist/LabLink[.exe]")
print("\nEstimated Executable Sizes:")
print(" • Windows: LabLink.exe ~95 MB")
print(" • macOS: LabLink.app ~110 MB")
print(" • Linux: LabLink ~88 MB")
print("\nIncludes:")
print(" • Python interpreter")
print(" • PyQt6 framework")
print(" • All dependencies (requests, websockets, etc.)")
print(" • Application code")
def generate_package_manifest():
"""Generate package manifest."""
print_section("Package Manifest")
# Calculate actual sizes
server_size = calculate_size("server") if Path("server").exists() else 0
client_size = calculate_size("client") if Path("client").exists() else 0
manifest = {
"project": "LabLink",
"version": "1.0.0",
"server_version": "0.10.0",
"client_version": "1.0.0",
"packages": {
"docker_image": {
"name": "lablink-server:0.10.0",
"type": "Docker Image",
"estimated_size": "250-350 MB",
"build_command": "docker build -t lablink-server:0.10.0 .",
"run_command": "docker run -p 8000:8000 -p 8001:8001 lablink-server:0.10.0",
"includes": [
"Python 3.12 runtime",
"All server dependencies",
"Server application code",
"Health checks",
"Auto-restart configuration"
]
},
"client_windows": {
"name": "LabLink.exe",
"type": "Windows Executable",
"estimated_size": "95 MB",
"build_command": "pyinstaller client/lablink.spec",
"includes": [
"Python interpreter",
"PyQt6 framework",
"All dependencies",
"GUI application"
]
},
"client_macos": {
"name": "LabLink.app",
"type": "macOS Application Bundle",
"estimated_size": "110 MB",
"build_command": "pyinstaller client/lablink.spec",
"includes": [
"Python interpreter",
"PyQt6 framework",
"All dependencies",
"GUI application",
"macOS bundle structure"
]
},
"client_linux": {
"name": "LabLink",
"type": "Linux Executable",
"estimated_size": "88 MB",
"build_command": "pyinstaller client/lablink.spec",
"includes": [
"Python interpreter",
"PyQt6 framework",
"All dependencies",
"GUI application"
]
}
},
"source_code": {
"server_size": format_size(server_size),
"client_size": format_size(client_size),
"total_lines": "20,670+",
"files": 84
}
}
# Save manifest
with open("package_manifest.json", "w") as f:
json.dump(manifest, f, indent=2)
print("\n✓ Package manifest saved to: package_manifest.json")
# Print summary
print("\nPackages to Build:")
for pkg_name, pkg_info in manifest["packages"].items():
print(f"\n {pkg_info['name']}")
print(f" Type: {pkg_info['type']}")
print(f" Size: {pkg_info['estimated_size']}")
print(f" Build: {pkg_info['build_command']}")
def create_build_instructions():
"""Create detailed build instructions."""
print_section("Build Instructions")
instructions = """
╔══════════════════════════════════════════════════════════════════════╗
║ LabLink Build Instructions ║
╚══════════════════════════════════════════════════════════════════════╝
1. BUILD DOCKER IMAGE (Server)
─────────────────────────────────────────────────────────────────
Prerequisites:
• Docker installed (https://docs.docker.com/get-docker/)
Build:
$ ./build_docker.sh
Or manually:
$ docker build -t lablink-server:0.10.0 .
$ docker tag lablink-server:0.10.0 lablink-server:latest
Test:
$ docker run -p 8000:8000 -p 8001:8001 lablink-server:0.10.0
$ curl http://localhost:8000/health
Save for distribution:
$ docker save lablink-server:0.10.0 | gzip > lablink-server-0.10.0.tar.gz
Size: ~250-350 MB compressed
2. BUILD CLIENT EXECUTABLE (GUI)
─────────────────────────────────────────────────────────────────
Prerequisites:
• Python 3.11+
• PyInstaller: pip install pyinstaller
• Client dependencies: cd client && pip install -r requirements.txt
Build:
$ cd client
$ ./build_client.sh
Or manually:
$ cd client
$ pyinstaller lablink.spec
Output:
Windows: client/dist/LabLink.exe (~95 MB)
macOS: client/dist/LabLink.app (~110 MB)
Linux: client/dist/LabLink (~88 MB)
Test:
$ ./dist/LabLink (or LabLink.exe)
Click "Connect to Server..."
Enter: localhost:8000
3. USING DOCKER-COMPOSE (Recommended)
─────────────────────────────────────────────────────────────────
Start server:
$ docker-compose up -d
View logs:
$ docker-compose logs -f
Stop server:
$ docker-compose down
Update:
$ docker-compose pull
$ docker-compose up -d
4. DISTRIBUTION PACKAGE
─────────────────────────────────────────────────────────────────
Create a complete distribution:
LabLink-v1.0.0/
├── Server/
│ ├── lablink-server-0.10.0.tar.gz (Docker image)
│ ├── docker-compose.yml
│ └── README.txt
├── Windows/
│ ├── LabLink.exe
│ └── README.txt
├── macOS/
│ ├── LabLink.dmg
│ └── README.txt
└── Linux/
├── LabLink
└── README.txt
5. VERIFICATION
─────────────────────────────────────────────────────────────────
After building, test:
• Server: curl http://localhost:8000/health
• Client: Launch and connect to localhost
• API Docs: http://localhost:8000/docs
═══════════════════════════════════════════════════════════════════════
For detailed deployment options, see DEPLOYMENT.md
"""
print(instructions)
# Save to file
with open("BUILD_INSTRUCTIONS.txt", "w") as f:
f.write(instructions)
print("\n✓ Build instructions saved to: BUILD_INSTRUCTIONS.txt")
def main():
"""Main function."""
print_header("LabLink Package Build Simulation")
os.chdir(Path(__file__).parent)
# Validate configuration files
print_header("Configuration Validation")
dockerfile_ok = validate_dockerfile()
compose_ok = validate_docker_compose()
spec_ok = validate_pyinstaller_spec()
if all([dockerfile_ok, compose_ok, spec_ok]):
print("\n✓ All configuration files valid!")
else:
print("\n⚠ Some configuration files have issues")
# Simulate builds
print_header("Build Simulation")
simulate_docker_build()
simulate_pyinstaller_build()
# Generate manifest
print_header("Package Manifest")
generate_package_manifest()
# Create instructions
print_header("Build Instructions")
create_build_instructions()
# Summary
print_header("Summary")
print("\n✓ Build simulation complete!")
print("\nGenerated Files:")
print(" • package_manifest.json - Package specifications")
print(" • BUILD_INSTRUCTIONS.txt - Detailed build guide")
print("\nNext Steps:")
print(" 1. Install Docker: https://docs.docker.com/get-docker/")
print(" 2. Build server: ./build_docker.sh")
print(" 3. Build client: cd client && ./build_client.sh")
print("\nDocumentation:")
print(" • DEPLOYMENT.md - Complete deployment guide")
print(" • README.md - Project overview")
print(" • TESTING.md - Testing procedures")
print("\nEstimated Package Sizes:")
print(" • Docker image: 250-350 MB")
print(" • Windows client: ~95 MB")
print(" • macOS client: ~110 MB")
print(" • Linux client: ~88 MB")
print(" • Total distribution: ~550-650 MB")
print("\n" + "=" * 70)
print()
if __name__ == "__main__":
main()