From 252ef468c96208f8ab691a73fd48330c57125536 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Sun, 10 Aug 2025 19:49:24 +0700 Subject: [PATCH] feat: update Dockerfile and requirements for ML dependencies; add base image build workflow --- .gitea/workflows/build-base.yml | 37 +++++++++++++++++++++++++++++++++ Dockerfile | 16 ++++---------- Dockerfile.base | 15 +++++++++++++ requirements.base.txt | 7 +++++++ requirements.txt | 9 +------- 5 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 .gitea/workflows/build-base.yml create mode 100644 Dockerfile.base create mode 100644 requirements.base.txt diff --git a/.gitea/workflows/build-base.yml b/.gitea/workflows/build-base.yml new file mode 100644 index 0000000..f870f3a --- /dev/null +++ b/.gitea/workflows/build-base.yml @@ -0,0 +1,37 @@ +name: Build Worker Base Image + +on: + workflow_dispatch: + push: + paths: + - 'Dockerfile.base' + - 'requirements.base.txt' + branches: + - main + +jobs: + build-base: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: git.siwatsystem.com + username: ${{ github.actor }} + password: ${{ secrets.RUNNER_TOKEN }} + + - name: Build and push base Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile.base + push: true + tags: git.siwatsystem.com/adsist-cms/worker-base:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fd55f68..2b3fcc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,11 @@ -# Use the official Python image from the Docker Hub -FROM python:3.13-bookworm +# Use our pre-built base image with ML dependencies +FROM git.siwatsystem.com/adsist-cms/worker-base:latest -# Set the working directory in the container -WORKDIR /app - -# Copy the requirements file into the container at /app +# Copy and install application requirements (frequently changing dependencies) COPY requirements.txt . - -# Update apt, install libgl1, and clear apt cache -RUN apt update && apt install -y libgl1 && rm -rf /var/lib/apt/lists/* - -# Install any dependencies specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt -# Copy the rest of the application code into the container at /app +# Copy the application code COPY . . # Run the application diff --git a/Dockerfile.base b/Dockerfile.base new file mode 100644 index 0000000..3700920 --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,15 @@ +# Base image with all ML dependencies +FROM python:3.13-bookworm + +# Install system dependencies +RUN apt update && apt install -y libgl1 && rm -rf /var/lib/apt/lists/* + +# Copy and install base requirements (ML dependencies that rarely change) +COPY requirements.base.txt . +RUN pip install --no-cache-dir -r requirements.base.txt + +# Set working directory +WORKDIR /app + +# This base image will be reused for all worker builds +CMD ["python3", "-m", "fastapi", "run", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/requirements.base.txt b/requirements.base.txt new file mode 100644 index 0000000..af22160 --- /dev/null +++ b/requirements.base.txt @@ -0,0 +1,7 @@ +torch +torchvision +ultralytics +opencv-python +scipy +filterpy +psycopg2-binary \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c0691b8..6eaf131 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,6 @@ fastapi uvicorn -torch -torchvision -ultralytics -opencv-python websockets fastapi[standard] redis -urllib3<2.0.0 -psycopg2-binary -scipy -filterpy \ No newline at end of file +urllib3<2.0.0 \ No newline at end of file