mirror of
https://github.com/Azure/co-op-translator
synced 2026-08-09 12:00:08 +00:00
Build: Add Dockerfile and GHCR publish workflow (#257)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.pyo
|
||||
*.pyd
|
||||
|
||||
# Environments
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
# Builds
|
||||
build/
|
||||
dist/
|
||||
.eggs/
|
||||
*.egg-info/
|
||||
htmlcov/
|
||||
|
||||
# Git/CI
|
||||
.git/
|
||||
.github/
|
||||
.gitignore
|
||||
|
||||
# IDE/editor
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
|
||||
# Local config
|
||||
.env
|
||||
.env.*
|
||||
|
||||
# Generated project outputs
|
||||
translated_images/
|
||||
translations/
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,52 @@
|
||||
name: Publish Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main", "docker" ]
|
||||
tags: [ "v*.*.*" ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ghcr.io/${{ github.repository }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=sha
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64
|
||||
provenance: false
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
# Multi-stage build for Co‑op Translator
|
||||
# Builder stage: build wheel using Poetry
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
ENV PIP_NO_CACHE_DIR=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# System deps required for build steps
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
curl \
|
||||
git \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Poetry
|
||||
RUN pip install --no-cache-dir poetry==1.8.3
|
||||
|
||||
# Copy only dependency files first for better caching
|
||||
COPY pyproject.toml poetry.lock* ./
|
||||
|
||||
# Export env to ensure Poetry installs with the same Python
|
||||
ENV POETRY_VIRTUALENVS_CREATE=false
|
||||
|
||||
# Pre-fetch dependencies into wheel cache (optional; speeds up build)
|
||||
RUN poetry install --no-interaction --no-ansi --only main
|
||||
|
||||
# Now copy the application source
|
||||
COPY src ./src
|
||||
COPY README.md ./
|
||||
|
||||
# Build a wheel from the current source
|
||||
RUN poetry build --no-interaction --format wheel
|
||||
|
||||
|
||||
# Runtime stage: minimal image with just runtime libs and the package wheel
|
||||
FROM python:3.12-slim AS runtime
|
||||
|
||||
ENV PIP_NO_CACHE_DIR=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PATH="/usr/local/bin:${PATH}"
|
||||
|
||||
# Install minimal runtime system libraries required by some imaging libs (opencv, pillow)
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
libgl1 \
|
||||
libglib2.0-0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /work
|
||||
VOLUME ["/work"]
|
||||
|
||||
# Copy the built wheel from the builder and install it
|
||||
COPY --from=builder /app/dist/*.whl /tmp/
|
||||
RUN pip install /tmp/*.whl \
|
||||
&& rm -f /tmp/*.whl
|
||||
|
||||
# Default entrypoint to the primary CLI; override with --entrypoint for other commands
|
||||
ENTRYPOINT ["translate"]
|
||||
CMD ["--help"]
|
||||
|
||||
# Example runs (documentation only):
|
||||
# docker run --rm -it --env-file .env -v ${PWD}:/work IMAGE_TAG translate -l "fr es" -md
|
||||
# docker run --rm -it --env-file .env -v ${PWD}:/work --entrypoint migrate-links IMAGE_TAG -l "all" -y
|
||||
|
||||
|
||||
@@ -202,6 +202,38 @@ For a fast start using the command line:
|
||||
|
||||
_(Replace `"ko ja fr"` with your desired space-separated language codes)_
|
||||
|
||||
### Quick Start: Docker
|
||||
|
||||
Build the image locally:
|
||||
|
||||
```bash
|
||||
# From repository root
|
||||
docker build -t co-op-translator:local .
|
||||
```
|
||||
|
||||
Run with your current folder mounted and `.env` provided:
|
||||
|
||||
```bash
|
||||
# Bash / Zsh
|
||||
docker run --rm -it --env-file .env -v "${PWD}:/work" co-op-translator:local -l "fr es" -md
|
||||
```
|
||||
|
||||
```powershell
|
||||
# PowerShell
|
||||
docker run --rm -it --env-file .env -v "${PWD}.Path:/work" co-op-translator:local -l "fr es" -md
|
||||
```
|
||||
|
||||
Notes:
|
||||
- The container’s default entrypoint is `translate`. To run other CLIs, override entrypoint, e.g.:
|
||||
|
||||
```bash
|
||||
# migrate-links
|
||||
docker run --rm -it --env-file .env -v "${PWD}:/work" --entrypoint migrate-links co-op-translator:local -l "all" -y
|
||||
```
|
||||
|
||||
- Image translation (`-img`) requires `AZURE_AI_SERVICE_API_KEY` and `AZURE_AI_SERVICE_ENDPOINT` in `.env`.
|
||||
- You may map a different working folder with `-v /path/to/repo:/work`.
|
||||
|
||||
### Detailed Usage Guides
|
||||
|
||||
Choose the approach that best fits your workflow:
|
||||
|
||||
Reference in New Issue
Block a user