diff --git a/Dockerfile b/Dockerfile index c6fdd28..5a237f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.python.yml b/docker-compose.python.yml new file mode 100644 index 0000000..d852fb6 --- /dev/null +++ b/docker-compose.python.yml @@ -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 diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..93204af --- /dev/null +++ b/start.sh @@ -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"