This commit is contained in:
wh
2026-04-16 10:18:07 +08:00
3 changed files with 48 additions and 5 deletions

View File

@@ -1,18 +1,22 @@
FROM python:3.12-slim
FROM registry.bjzgzp.com:4433/library/python3.12:base
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
ARG APT_MIRROR=mirrors.tuna.tsinghua.edu.cn
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
RUN sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}|g" /etc/apt/sources.list.d/debian.sources \
&& apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
curl \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -i "${PIP_INDEX_URL}" -r requirements.txt
COPY . .
EXPOSE 8000
EXPOSE 18000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "18000"]

12
docker-compose.python.yml Normal file
View File

@@ -0,0 +1,12 @@
version: "3.9"
services:
python-service:
image: label-ai-service:latest
build:
context: .
dockerfile: Dockerfile
container_name: label-ai-service
ports:
- "18000:18000"
restart: unless-stopped

27
start.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
COMPOSE_CMD="docker compose"
if ! docker compose version >/dev/null 2>&1; then
if command -v docker-compose >/dev/null 2>&1; then
COMPOSE_CMD="docker-compose"
else
echo "Error: docker compose and docker-compose are both unavailable." >&2
exit 1
fi
fi
echo "==> Pulling latest code..."
git pull
echo "==> Building image..."
docker build -t label-ai-service:latest -f Dockerfile .
echo "==> Starting service..."
$COMPOSE_CMD -f docker-compose.python.yml up -d
echo "==> Service started. Check logs with:"
echo " $COMPOSE_CMD -f docker-compose.python.yml logs -f python-service"