Skip to content

Commit 4a6a656

Browse files
Merge pull request #492 from rahulharpal1603/GSoC'25/Frontend-Revamp
Update build pipeline to support the microservice.
2 parents 6ec18af + 49c4d80 commit 4a6a656

File tree

4 files changed

+247
-9
lines changed

4 files changed

+247
-9
lines changed

.github/workflows/build-and-release.yml

Lines changed: 154 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,37 +134,176 @@ jobs:
134134
name: PictoPy-MacOS
135135
path: backend/dist/PictoPy_Server/PictoPy-MacOS.zip
136136

137+
build-sync-microservice-windows:
138+
runs-on: windows-latest
139+
steps:
140+
- name: Checkout code
141+
uses: actions/checkout@v4
142+
143+
- name: Setup Python
144+
uses: actions/setup-python@v4
145+
with:
146+
python-version: 3.12
147+
148+
- name: Install dependencies
149+
run: |
150+
cd sync-microservice
151+
python -m pip install --upgrade pip
152+
pip install -r requirements.txt
153+
pip install pyinstaller
154+
155+
- name: Build executable with PyInstaller
156+
run: |
157+
cd sync-microservice
158+
pyinstaller main.py --name PictoPy_Sync --onedir --distpath dist
159+
160+
- name: Copy app folder
161+
run: |
162+
cd sync-microservice
163+
robocopy app dist\PictoPy_Sync\app /e
164+
if ($LASTEXITCODE -le 1) { exit 0 }
165+
166+
- name: Create ZIP package
167+
run: |
168+
cd sync-microservice/dist/PictoPy_Sync
169+
tar -a -c -f PictoPy-Sync-Windows.zip .
170+
171+
- name: Upload artifact
172+
uses: actions/upload-artifact@v4
173+
with:
174+
name: PictoPy-Sync-Windows
175+
path: sync-microservice/dist/PictoPy_Sync/PictoPy-Sync-Windows.zip
176+
177+
build-sync-microservice-ubuntu:
178+
runs-on: ubuntu-22.04
179+
steps:
180+
- name: Checkout code
181+
uses: actions/checkout@v4
182+
183+
- name: Setup Python
184+
uses: actions/setup-python@v4
185+
with:
186+
python-version: 3.12
187+
188+
- name: Install dependencies
189+
run: |
190+
cd sync-microservice
191+
python -m pip install --upgrade pip
192+
pip install -r requirements.txt
193+
pip install pyinstaller
194+
195+
- name: Build executable with PyInstaller
196+
run: |
197+
cd sync-microservice
198+
pyinstaller main.py --name PictoPy_Sync --onedir --distpath dist
199+
200+
- name: Copy app folder
201+
run: |
202+
cd sync-microservice
203+
mkdir -p dist/PictoPy_Sync/app
204+
cp -r app/* dist/PictoPy_Sync/app/
205+
206+
- name: Create ZIP package
207+
run: |
208+
cd sync-microservice/dist/PictoPy_Sync
209+
zip -r PictoPy-Sync-Ubuntu.zip .
210+
211+
- name: Upload artifact
212+
uses: actions/upload-artifact@v4
213+
with:
214+
name: PictoPy-Sync-Ubuntu
215+
path: sync-microservice/dist/PictoPy_Sync/PictoPy-Sync-Ubuntu.zip
216+
217+
build-sync-microservice-macos:
218+
runs-on: macos-latest
219+
steps:
220+
- name: Checkout code
221+
uses: actions/checkout@v4
222+
223+
- name: Setup Python
224+
uses: actions/setup-python@v4
225+
with:
226+
python-version: 3.12
227+
228+
- name: Install dependencies
229+
run: |
230+
cd sync-microservice
231+
python -m pip install --upgrade pip
232+
pip install -r requirements.txt
233+
pip install pyinstaller
234+
235+
- name: Build executable with PyInstaller
236+
run: |
237+
cd sync-microservice
238+
pyinstaller main.py --name PictoPy_Sync --onedir --distpath dist
239+
240+
- name: Copy app folder
241+
run: |
242+
cd sync-microservice
243+
mkdir -p dist/PictoPy_Sync/app
244+
cp -r app/* dist/PictoPy_Sync/app/
245+
246+
- name: Create ZIP package
247+
run: |
248+
cd sync-microservice/dist/PictoPy_Sync
249+
zip -r PictoPy-Sync-MacOS.zip .
250+
251+
- name: Upload artifact
252+
uses: actions/upload-artifact@v4
253+
with:
254+
name: PictoPy-Sync-MacOS
255+
path: sync-microservice/dist/PictoPy_Sync/PictoPy-Sync-MacOS.zip
256+
137257
publish-tauri:
138258
permissions:
139259
contents: write
140-
needs: [build-server-windows, build-server-ubuntu, build-server-macos]
260+
needs:
261+
[
262+
build-server-windows,
263+
build-server-ubuntu,
264+
build-server-macos,
265+
build-sync-microservice-windows,
266+
build-sync-microservice-ubuntu,
267+
build-sync-microservice-macos,
268+
]
141269
strategy:
142270
fail-fast: false
143271
matrix:
144272
include:
145273
- platform: "macos-latest"
146274
args: "--target aarch64-apple-darwin"
147-
artifact: "PictoPy-MacOS"
275+
server-artifact: "PictoPy-MacOS"
276+
sync-artifact: "PictoPy-Sync-MacOS"
148277
- platform: "ubuntu-22.04"
149278
args: ""
150-
artifact: "PictoPy-Ubuntu"
279+
server-artifact: "PictoPy-Ubuntu"
280+
sync-artifact: "PictoPy-Sync-Ubuntu"
151281
- platform: "windows-latest"
152282
args: ""
153-
artifact: "PictoPy-Windows"
283+
server-artifact: "PictoPy-Windows"
284+
sync-artifact: "PictoPy-Sync-Windows"
154285
runs-on: ${{ matrix.platform }}
155286
steps:
156287
- uses: actions/checkout@v4
157288

158-
- name: Create dist directory
289+
- name: Create dist directories
159290
shell: bash
160-
run: mkdir -p backend/dist
291+
run: |
292+
mkdir -p backend/dist
293+
mkdir -p sync-microservice/dist
161294
162295
- name: Download and extract server artifact
163296
uses: actions/download-artifact@v4
164297
with:
165-
name: ${{ matrix.artifact }}
298+
name: ${{ matrix.server-artifact }}
166299
path: backend/dist
167300

301+
- name: Download and extract sync microservice artifact
302+
uses: actions/download-artifact@v4
303+
with:
304+
name: ${{ matrix.sync-artifact }}
305+
path: sync-microservice/dist
306+
168307
- name: Extract server files
169308
shell: bash
170309
run: |
@@ -173,6 +312,14 @@ jobs:
173312
rm *.zip
174313
ls -l
175314
315+
- name: Extract sync microservice files
316+
shell: bash
317+
run: |
318+
cd sync-microservice/dist
319+
unzip -o *.zip
320+
rm *.zip
321+
ls -l
322+
176323
- name: Setup Node
177324
uses: actions/setup-node@v4
178325
with:

.github/workflows/pr-check-tests.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,22 @@ jobs:
7070
with:
7171
python-version: "3.11"
7272

73-
- name: Install Python Dependencies & Run Tests
73+
- name: Build check(Main backend)
7474
run: |
7575
cd backend
7676
python -m pip install --upgrade pip
7777
pip install -r requirements.txt
7878
pyinstaller main.py --name PictoPy_Server --onedir --distpath dist
79+
80+
- name: Build check(Sync Microservice)
81+
run: |
82+
cd sync-microservice
83+
pip install -r requirements.txt
84+
pyinstaller main.py --name PictoPy_Sync_Microservice --onedir --distpath dist
85+
86+
- name: Run Tests
87+
run: |
88+
cd backend
7989
pytest
8090
8191
# Tauri Test Job

backend/app/utils/microservice.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,88 @@ def microservice_util_start_sync_service(
1616
"""
1717
Start the sync microservice with automatic virtual environment management.
1818
19+
When running as a frozen executable (PyInstaller), it will use the bundled
20+
PictoPy_Sync executable. Otherwise, it uses the development setup with venv.
21+
1922
Args:
2023
sync_service_path: Path to the sync microservice directory.
2124
If None, defaults to 'sync-microservice' relative to project root.
2225
2326
Returns:
2427
bool: True if service started successfully, False otherwise.
2528
"""
29+
try:
30+
# Check if running as a frozen executable (PyInstaller)
31+
if getattr(sys, "frozen", False):
32+
logger.info(
33+
"Running as frozen executable, using bundled sync microservice..."
34+
)
35+
return _start_frozen_sync_service()
36+
37+
# Development mode - use virtual environment setup
38+
logger.info("Running in development mode, using virtual environment...")
39+
return _start_dev_sync_service(sync_service_path)
40+
41+
except Exception as e:
42+
logger.error(f"Error starting sync microservice: {e}")
43+
return False
44+
45+
46+
def _start_frozen_sync_service() -> bool:
47+
"""
48+
Start the sync microservice when running as a frozen executable.
49+
The sync microservice executable should be in the PictoPy_Sync folder.
50+
"""
51+
try:
52+
# Get the directory where the current executable is located
53+
if getattr(sys, "frozen", False):
54+
# When frozen, sys.executable points to the main executable
55+
app_dir = Path(sys.executable).parent
56+
else:
57+
# Fallback (shouldn't happen in this function)
58+
app_dir = Path(__file__).parent.parent.parent.parent
59+
60+
# Look for the PictoPy_Sync directory and executable
61+
sync_dir = app_dir / "PictoPy_Sync"
62+
63+
# Determine executable name based on platform
64+
system = platform.system().lower()
65+
if system == "windows":
66+
sync_executable = sync_dir / "PictoPy_Sync.exe"
67+
else:
68+
sync_executable = sync_dir / "PictoPy_Sync"
69+
70+
if not sync_executable.exists():
71+
logger.error(
72+
f"Sync microservice executable not found at: {sync_executable}"
73+
)
74+
return False
75+
76+
logger.info(f"Starting sync microservice from: {sync_executable}")
77+
78+
# Start the sync microservice executable
79+
process = subprocess.Popen(
80+
[str(sync_executable)],
81+
stdout=subprocess.PIPE,
82+
stderr=subprocess.PIPE,
83+
text=True,
84+
cwd=str(sync_dir), # Set working directory to sync service directory
85+
)
86+
87+
logger.info(f"Sync microservice started with PID: {process.pid}")
88+
logger.info("Service should be available at http://localhost:8001")
89+
90+
return True
91+
92+
except Exception as e:
93+
logger.error(f"Error starting frozen sync microservice: {e}")
94+
return False
95+
96+
97+
def _start_dev_sync_service(sync_service_path: Optional[str] = None) -> bool:
98+
"""
99+
Start the sync microservice in development mode using virtual environment.
100+
"""
26101
try:
27102
# Determine the sync service path
28103
if sync_service_path is None:
@@ -65,7 +140,7 @@ def microservice_util_start_sync_service(
65140
return _start_fastapi_service(python_executable, sync_service_path)
66141

67142
except Exception as e:
68-
logger.error(f"Error starting sync microservice: {e}")
143+
logger.error(f"Error starting dev sync microservice: {e}")
69144
return False
70145

71146

sync-microservice/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from fastapi import FastAPI
2+
from uvicorn import Config, Server
23
from app.core.lifespan import lifespan
34
from app.routes import health, watcher, folders
45

@@ -14,3 +15,8 @@
1415
app.include_router(health.router, prefix="/api/v1")
1516
app.include_router(watcher.router, prefix="/api/v1")
1617
app.include_router(folders.router, prefix="/api/v1")
18+
19+
if __name__ == "__main__":
20+
config = Config(app=app, host="0.0.0.0", port=8001, log_config=None)
21+
server = Server(config)
22+
server.run()

0 commit comments

Comments
 (0)