Skip to content

Commit 0e40315

Browse files
committed
added docker
1 parent 0c8020b commit 0e40315

7 files changed

Lines changed: 152 additions & 0 deletions

File tree

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.git
2+
.gitignore
3+
.pytest_cache
4+
.ruff_cache
5+
.mypy_cache
6+
.venv
7+
__pycache__
8+
*.py[cod]
9+
*.egg-info
10+
11+
backend/.env
12+
backend/__pycache__
13+
backend/**/*.py[cod]
14+
backend/**/__pycache__
15+
16+
opencad_viewport/.env
17+
opencad_viewport/node_modules
18+
opencad_viewport/dist
19+
opencad_viewport/tsconfig.tsbuildinfo
20+
21+
*.log

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,47 @@ The viewport uses **mock geometry/solver data** by default (no backend required
102102
Chat targets the live agent service by default; set `VITE_USE_CHAT_MOCK=true` if you explicitly want mocked chat output.
103103
Set `VITE_USE_MOCK=false` to connect the rest of the viewport to the live services above.
104104

105+
### 5. Run with Docker
106+
107+
Build the backend image from the repository root so Docker can see the Python
108+
project metadata and backend package files:
109+
110+
```bash
111+
docker build -f backend/Dockerfile -t opencad-backend .
112+
```
113+
114+
Build the frontend image from the viewport directory:
115+
116+
```bash
117+
docker build -f opencad_viewport/Dockerfile -t opencad-frontend opencad_viewport
118+
```
119+
120+
Run the backend API on port `8000`:
121+
122+
```bash
123+
docker run --rm -p 8000:8000 opencad-backend
124+
```
125+
126+
Run the frontend on port `5173`:
127+
128+
```bash
129+
docker run --rm -p 5173:80 opencad-frontend
130+
```
131+
132+
By default, the frontend image is built with `VITE_BASE_URL=http://localhost:8000`
133+
and live API calls enabled. To point the frontend at another API URL or enable
134+
mock mode, pass build args:
135+
136+
```bash
137+
docker build \
138+
-f opencad_viewport/Dockerfile \
139+
-t opencad-frontend \
140+
--build-arg VITE_BASE_URL=http://localhost:8000 \
141+
--build-arg VITE_USE_MOCK=false \
142+
--build-arg VITE_USE_CHAT_MOCK=false \
143+
opencad_viewport
144+
```
145+
105146
## Configuration
106147

107148
Runtime defaults are documented in `.env.example`.

backend/Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.11-slim AS runtime
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
PIP_NO_CACHE_DIR=1 \
8+
OPENCAD_KERNEL_BACKEND=occt \
9+
OPENCAD_SOLVER_BACKEND=auto \
10+
OPENCAD_CORS_ALLOW_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
11+
12+
WORKDIR /app
13+
14+
RUN apt-get update \
15+
&& apt-get install -y --no-install-recommends \
16+
ca-certificates \
17+
libgl1 \
18+
libglib2.0-0 \
19+
libgomp1 \
20+
libsm6 \
21+
libxext6 \
22+
libxrender1 \
23+
&& rm -rf /var/lib/apt/lists/*
24+
25+
COPY pyproject.toml README.md ./
26+
COPY backend ./backend
27+
28+
RUN python -m pip install --upgrade pip \
29+
&& python -m pip install ".[full]"
30+
31+
EXPOSE 8000
32+
33+
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
34+
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/kernel/healthz', timeout=3).read()" || exit 1
35+
36+
CMD ["python", "-m", "uvicorn", "api:app", "--app-dir", "backend", "--host", "0.0.0.0", "--port", "8000"]

opencad_viewport/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.env
2+
dist
3+
node_modules
4+
tsconfig.tsbuildinfo
5+
*.log

opencad_viewport/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM node:20-alpine AS build
4+
5+
WORKDIR /app
6+
7+
RUN corepack enable
8+
9+
COPY package.json pnpm-lock.yaml ./
10+
RUN pnpm install --frozen-lockfile
11+
12+
COPY . .
13+
14+
ARG VITE_BASE_URL=http://localhost:8000
15+
ARG VITE_USE_MOCK=false
16+
ARG VITE_USE_CHAT_MOCK=false
17+
18+
ENV VITE_BASE_URL=${VITE_BASE_URL} \
19+
VITE_USE_MOCK=${VITE_USE_MOCK} \
20+
VITE_USE_CHAT_MOCK=${VITE_USE_CHAT_MOCK}
21+
22+
RUN pnpm build
23+
24+
FROM nginx:1.27-alpine AS runtime
25+
26+
COPY nginx.conf /etc/nginx/conf.d/default.conf
27+
COPY --from=build /app/dist /usr/share/nginx/html
28+
29+
EXPOSE 80
30+
31+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
32+
CMD wget -qO- http://127.0.0.1/ >/dev/null || exit 1

opencad_viewport/nginx.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
8+
location / {
9+
try_files $uri $uri/ /index.html;
10+
}
11+
}

opencad_viewport/src/mock/mockData.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export const mockFeatureTree: FeatureTreeView = {
7474
typed_parameters: {},
7575
parameter_bindings: [],
7676
sketch_id: "sketch-base",
77+
parent_id: null,
78+
tool_refs: [],
7779
depends_on: [],
7880
shape_id: "shape-base-plate",
7981
status: "built",
@@ -86,6 +88,8 @@ export const mockFeatureTree: FeatureTreeView = {
8688
parameters: { tool: "cutout-tool" },
8789
typed_parameters: {},
8890
parameter_bindings: [],
91+
parent_id: "base",
92+
tool_refs: ["cutout-tool"],
8993
depends_on: ["base"],
9094
shape_id: "shape-cutout",
9195
status: "stale",
@@ -98,6 +102,8 @@ export const mockFeatureTree: FeatureTreeView = {
98102
parameters: { radius: 1.5 },
99103
typed_parameters: {},
100104
parameter_bindings: [],
105+
parent_id: "cutout",
106+
tool_refs: [],
101107
depends_on: ["cutout"],
102108
shape_id: null,
103109
status: "pending",

0 commit comments

Comments
 (0)