diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 13bed9c1..7e5acda6 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -4,9 +4,9 @@ on: push: branches: - main + - dockerfile-debug tags: - "*" - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: jobs: @@ -24,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 @@ -50,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 }} diff --git a/Dockerfile b/Dockerfile index 5cb3122f..1245bd24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,25 @@ FROM python:3.12 -ARG API_USERNAME -ARG 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 - -# install all the requirements and import corpus -RUN pip install --no-cache-dir --upgrade -r requirements.txt && \ - python -m nltk.downloader stopwords - -# copy the main code of fastapi -COPY ./app /api/app - -# 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"] +# 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/` +WORKDIR /api/src + +# Copy pyproject.toml and lockfile for dependency resolution +COPY pyproject.toml uv.lock ./ + +# Install uv package manager +RUN pip install uv + +# Sync dependencies +RUN uv sync + +# Copy application code +COPY ./src /api/src + +# Expose port 5000 +EXPOSE 5000 + +# Start FastAPI application +CMD ["uv", "run", "uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "5000"]