Skip to content

Commit 025f7db

Browse files
committed
fix: remove map frontend check and optimize docker image
1 parent 4f006ed commit 025f7db

2 files changed

Lines changed: 23 additions & 50 deletions

File tree

Dockerfile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# syntax=docker/dockerfile:1
2+
13
# Stage 1: Builder stage
24
FROM python:3.13-slim AS builder
35

@@ -35,19 +37,18 @@ RUN apt-get update && apt-get install -y \
3537
libnetcdf22 \
3638
&& rm -rf /var/lib/apt/lists/*
3739

38-
# Copy from builder stage
39-
COPY --from=builder /root/.local/bin/uv /usr/local/bin/uv
40-
COPY --from=builder /app/.venv /app/.venv
41-
COPY --from=builder /app/src /app/src
42-
43-
COPY pyproject.toml uv.lock MANIFEST.in ./
44-
4540
# Create non-root user for running the application
4641
RUN groupadd -r appuser -g 1000 && \
47-
useradd -r -u 1000 -g appuser -m -s /bin/bash appuser
42+
useradd -r -u 1000 -g appuser -m -s /bin/bash appuser && \
43+
mkdir -p /data/networks && \
44+
chown -R appuser:appuser /data
45+
46+
# Copy from builder stage with correct ownership
47+
COPY --from=builder --chown=appuser:appuser /root/.local/bin/uv /usr/local/bin/uv
48+
COPY --from=builder --chown=appuser:appuser /app/.venv /app/.venv
49+
COPY --from=builder --chown=appuser:appuser /app/src /app/src
4850

49-
RUN mkdir -p /data/networks && \
50-
chown -R appuser:appuser /app /data
51+
COPY --chown=appuser:appuser pyproject.toml uv.lock MANIFEST.in ./
5152

5253
USER appuser
5354

@@ -77,7 +78,7 @@ RUN npm ci && \
7778
# Stage 4: Full stack (adds built frontend to backend base)
7879
FROM backend AS full
7980

80-
COPY --from=app-builder /frontend/build/ src/pypsa_app/backend/static/app/
81+
COPY --from=app-builder --chown=appuser:appuser /frontend/build/ src/pypsa_app/backend/static/app/
8182

8283
# Copy package.json for version detection
83-
COPY --from=app-builder /frontend/package.json frontend/app/package.json
84+
COPY --from=app-builder --chown=appuser:appuser /frontend/package.json frontend/app/package.json

src/pypsa_app/cli.py

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,15 @@ def serve(
6060
click.echo(f" Application: http://{host}:{port}")
6161
click.echo(f" API docs: http://{host}:{port}/api/docs")
6262

63-
# Check if frontends are built (prod mode)
63+
# Check if frontend is built (prod mode)
6464
if not dev:
6565
static_dir = Path(__file__).parent / "backend" / "static"
6666
app_dir = static_dir / "app"
67-
map_dir = static_dir / "map"
6867

69-
missing = []
7068
if not app_dir.exists() or not (app_dir / "index.html").exists():
71-
missing.append(
72-
("App frontend", "cd frontend/app && npm ci && npm run build")
73-
)
74-
if not map_dir.exists() or not (map_dir / "index.html").exists():
75-
missing.append(
76-
("Map frontend", "cd frontend/map && npm ci && npm run build")
77-
)
78-
79-
if missing:
80-
click.echo(
81-
f"Warning: {', '.join(m[0] for m in missing)} not built!", err=True
82-
)
69+
click.echo("Error: App frontend not built!", err=True)
8370
click.echo(" Build with:", err=True)
84-
for _, cmd in missing:
85-
click.echo(f" {cmd}", err=True)
71+
click.echo(" cd frontend/app && npm ci && npm run build", err=True)
8672
click.echo(" Or use --dev flag for API-only mode", err=True)
8773
sys.exit(1)
8874

@@ -106,30 +92,16 @@ def info() -> None:
10692
click.echo(f"Python: {sys.version.split()[0]}")
10793
click.echo(f"Python executable: {sys.executable}")
10894

109-
# Check frontends
95+
# Check frontend
11096
static_dir = Path(__file__).parent / "backend" / "static"
111-
frontends = [
112-
("App", static_dir / "app"),
113-
("Map", static_dir / "map"),
114-
]
97+
app_dir = static_dir / "app"
98+
app_built = app_dir.exists() and (app_dir / "index.html").exists()
11599

116-
built = [
117-
(name, d.exists() and (d / "index.html").exists()) for name, d in frontends
118-
]
119-
120-
if all(status for _, status in built):
121-
click.echo("\nFrontends: Both built and ready")
100+
if app_built:
101+
click.echo("\nFrontend: Built and ready")
122102
else:
123-
click.echo("\nFrontends:")
124-
for (name, _), is_built in zip(frontends, built, strict=True):
125-
if is_built:
126-
click.echo(f" {name}: Built")
127-
else:
128-
click.echo(
129-
f" {name}: Not built"
130-
f" (run: cd frontend/{name.lower()}"
131-
" && npm ci && npm run build)"
132-
)
103+
click.echo("\nFrontend: Not built")
104+
click.echo(" Run: cd frontend/app && npm ci && npm run build")
133105

134106
click.echo("\nEnvironment variables:")
135107
for key in [

0 commit comments

Comments
 (0)