From b3d08c7150d08416db9d3e471a1bf10665c5db7f Mon Sep 17 00:00:00 2001 From: meilame-tayebjee Date: Wed, 2 Apr 2025 16:12:05 +0000 Subject: [PATCH 1/4] [wip] use of uv and adapt dockerfile --- Dockerfile | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5cb3122f..521c828e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,38 @@ -FROM python:3.12 +# Use Python 3.12 as the base image +FROM python:3.12-slim +# Set environment variables ARG API_USERNAME ARG API_PASSWORD -ENV API_USERNAME ${API_USERNAME} -ENV API_PASSWORD ${API_PASSWORD} +ENV API_USERNAME=${API_USERNAME} +ENV API_PASSWORD=${API_PASSWORD} ENV TIMEOUT=300 -# set api as the current work dir -WORKDIR /api -# copy the requirements list -COPY requirements.txt requirements.txt +# Set working directory inside src/ +WORKDIR /api/src -# install all the requirements and import corpus -RUN pip install --no-cache-dir --upgrade -r requirements.txt && \ - python -m nltk.downloader stopwords +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl build-essential && \ + rm -rf /var/lib/apt/lists/* -# copy the main code of fastapi -COPY ./app /api/app +# Install uv package manager +RUN pip install --no-cache-dir uv -# launch the unicorn server to run the api -# If you are running your container behind a TLS Termination Proxy (load balancer) like Nginx or Traefik, -# add the option --proxy-headers, this will tell Uvicorn to trust the headers sent by that proxy telling it -# that the application is running behind HTTPS, etc. -CMD ["uvicorn", "app.main:codification_ape_app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80", "--timeout-graceful-shutdown", "300"] +# Copy project files +COPY pyproject.toml uv.lock ../ + +# Install dependencies using uv +RUN uv sync + +# Copy the source code +COPY . . + +# Download required NLTK stopwords +RUN uv run -m nltk.downloader stopwords + +# Expose the API port +EXPOSE 80 + +# Command to run FastAPI with Uvicorn +CMD ["uvicorn", "api.main:codification_ape_app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80", "--timeout-graceful-shutdown", "300"] From 5c39e5cbf5007ae856169301591c9984a4f8a87c Mon Sep 17 00:00:00 2001 From: meilame-tayebjee Date: Wed, 2 Apr 2025 16:13:16 +0000 Subject: [PATCH 2/4] [wip] update actions to debug on branch --- .github/workflows/build-image.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 13bed9c1..67635192 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - dockerfile-debug tags: - "*" # Allows you to run this workflow manually from the Actions tab From 73336429242282ca72887854cc0e419fa1b51cf8 Mon Sep 17 00:00:00 2001 From: meilame-tayebjee Date: Wed, 2 Apr 2025 16:24:17 +0000 Subject: [PATCH 3/4] [wip] change build imaage yaml --- .github/workflows/build-image.yaml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 67635192..7e5acda6 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -7,7 +7,6 @@ on: - dockerfile-debug tags: - "*" - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: jobs: @@ -25,10 +24,9 @@ jobs: with: images: thomasfaria/codification-ape-api tags: | - # set latest tag for main branch - type=raw,value=v1.0.1,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - # propagate valid semver tags - type=semver,pattern={{raw}} + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=ref,event=branch + type=ref,event=tag - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -51,8 +49,8 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - "API_USERNAME=${{ secrets.API_USERNAME }}" - "API_PASSWORD=${{ secrets.API_PASSWORD }}" + API_USERNAME=${{ secrets.API_USERNAME }} + API_PASSWORD=${{ secrets.API_PASSWORD }} - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} From a47dede35166e530cb6088fcfd68d2e21c8efd0a Mon Sep 17 00:00:00 2001 From: meilame-tayebjee Date: Wed, 2 Apr 2025 16:27:28 +0000 Subject: [PATCH 4/4] [wip] install git in dockerfile (temoporarily) --- Dockerfile | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 521c828e..1245bd24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,25 @@ -# Use Python 3.12 as the base image -FROM python:3.12-slim +FROM python:3.12 -# Set environment variables -ARG API_USERNAME -ARG API_PASSWORD -ENV API_USERNAME=${API_USERNAME} -ENV API_PASSWORD=${API_PASSWORD} -ENV TIMEOUT=300 +# Install system dependencies, including Git +RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* -# Set working directory inside src/ +# Set working directory inside `src/` WORKDIR /api/src -# Install system dependencies -RUN apt-get update && apt-get install -y --no-install-recommends \ - curl build-essential && \ - rm -rf /var/lib/apt/lists/* +# Copy pyproject.toml and lockfile for dependency resolution +COPY pyproject.toml uv.lock ./ # Install uv package manager -RUN pip install --no-cache-dir uv +RUN pip install uv -# Copy project files -COPY pyproject.toml uv.lock ../ - -# Install dependencies using uv +# Sync dependencies RUN uv sync -# Copy the source code -COPY . . - -# Download required NLTK stopwords -RUN uv run -m nltk.downloader stopwords +# Copy application code +COPY ./src /api/src -# Expose the API port -EXPOSE 80 +# Expose port 5000 +EXPOSE 5000 -# Command to run FastAPI with Uvicorn -CMD ["uvicorn", "api.main:codification_ape_app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80", "--timeout-graceful-shutdown", "300"] +# Start FastAPI application +CMD ["uv", "run", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "5000"]