-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: Add Docker support for web, CLI, and CI with usage documentation #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -94,6 +94,86 @@ The defaults are tuned for best translation quality. On metered cloud providers | |||||
|
|
||||||
| Set `NO_COLOR=1` to disable ANSI colors; output auto-falls back to plain lines when piped. | ||||||
|
|
||||||
| ## Docker | ||||||
|
|
||||||
| Both interfaces ship with a `Dockerfile` so you can build and run without installing Node, Angular CLI, Python, or any deps locally. | ||||||
|
|
||||||
| ### Web app | ||||||
|
|
||||||
| ```bash | ||||||
| # from the repo root | ||||||
| docker build -t translora-web ./web | ||||||
| docker run --rm -p 8080:80 translora-web | ||||||
| ``` | ||||||
|
|
||||||
| Open http://localhost:8080. The image is a small `nginx:alpine` serving the production Angular build, with SPA-fallback routing pre-configured. | ||||||
|
||||||
| Open http://localhost:8080. The image is a small `nginx:alpine` serving the production Angular build, with SPA-fallback routing pre-configured. | |
| Open http://localhost:8080. The image is a small `nginx:1.27-alpine-slim` serving the production Angular build, with SPA-fallback routing pre-configured. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| __pycache__ | ||
| **/__pycache__ | ||
| *.pyc | ||
| *.pyo | ||
| .pytest_cache | ||
| .venv | ||
| .vscode | ||
| .git | ||
| .gitignore | ||
| tests | ||
| *.md | ||
| Dockerfile* | ||
| .dockerignore | ||
| uv.lock | ||
| **/*.log |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # syntax=docker/dockerfile:1.7 | ||
|
|
||
| FROM python:3.12-alpine AS runtime | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 \ | ||
| PYTHONDONTWRITEBYTECODE=1 \ | ||
| PYTHONUTF8=1 \ | ||
| PIP_DISABLE_PIP_VERSION_CHECK=1 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install deps first so source-only edits don't bust the pip cache layer. | ||
| # All deps are pure-Python wheels — alpine works without compilers. | ||
| COPY requirements.txt ./ | ||
| RUN --mount=type=cache,target=/root/.cache/pip \ | ||
| pip install --no-compile -r requirements.txt \ | ||
| && find /usr/local/lib/python3.12 -name '__pycache__' -type d -exec rm -rf {} + \ | ||
| && find /usr/local/lib/python3.12 -name 'tests' -type d -exec rm -rf {} + | ||
|
|
||
| COPY core ./core | ||
| COPY translora.py ./translora.py | ||
|
|
||
| # Subtitle files live in the user's mount, not in the image. | ||
| WORKDIR /work | ||
| ENTRYPOINT ["python", "/app/translora.py"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| node_modules | ||
| dist | ||
| .angular | ||
| .vscode | ||
| .git | ||
| .gitignore | ||
| *.md | ||
| Dockerfile* | ||
| .dockerignore | ||
| **/*.log | ||
| .env | ||
| .env.* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # syntax=docker/dockerfile:1.7 | ||
|
|
||
| # ---- build stage --------------------------------------------------------- | ||
| FROM node:20-alpine AS build | ||
| WORKDIR /app | ||
|
|
||
| # Install deps first so source-only changes don't bust the npm cache layer. | ||
| COPY package.json package-lock.json ./ | ||
| RUN --mount=type=cache,target=/root/.npm \ | ||
| npm ci --prefer-offline --no-audit --no-fund | ||
|
|
||
| COPY . . | ||
| RUN npx ng build --configuration production | ||
|
|
||
| # ---- runtime stage ------------------------------------------------------- | ||
| FROM nginx:1.27-alpine-slim AS runtime | ||
| COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
| COPY --from=build /app/dist/web/browser /usr/share/nginx/html | ||
|
|
||
| EXPOSE 80 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| server { | ||
| listen 80; | ||
| server_name _; | ||
| root /usr/share/nginx/html; | ||
| index index.html; | ||
|
|
||
| # SPA fallback: every unknown path resolves to index.html. | ||
| location / { | ||
| try_files $uri $uri/ /index.html; | ||
| } | ||
|
|
||
| # Long-cache hashed static assets. | ||
| location ~* \.(?:js|css|woff2?|ttf|eot|svg|png|jpe?g|gif|ico|webp)$ { | ||
| expires 30d; | ||
| add_header Cache-Control "public, no-transform"; | ||
| try_files $uri =404; | ||
| } | ||
|
|
||
| # Never cache index.html itself — it points at hashed bundles. | ||
| location = /index.html { | ||
| add_header Cache-Control "no-store"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docker-web smoke test only removes the
web-smokecontainer at the end of the script. If any earlier command fails (e.g., curl/grep),set -ewill exit and the container will be left running, which can leak resources and interfere with later steps. Add an EXIT trap (or usedocker run --rmwith a background-friendly pattern) to ensure cleanup happens even on failure.