Spaces:
Runtime error
Runtime error
feat: update Docker setup with new base image, enhance build workflow, and improve error logging in main application
Browse files- .dockerignore +1 -0
- .github/workflows/build.yaml +18 -55
- Dockerfile +28 -35
- main.py +1 -1
- setup.py +1 -0
.dockerignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.venv
|
.github/workflows/build.yaml
CHANGED
|
@@ -1,64 +1,27 @@
|
|
| 1 |
-
name: Docker
|
| 2 |
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
-
branches:
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
jobs:
|
| 16 |
-
|
| 17 |
runs-on: ubuntu-latest
|
| 18 |
-
permissions:
|
| 19 |
-
contents: read
|
| 20 |
-
packages: write
|
| 21 |
-
|
| 22 |
steps:
|
| 23 |
-
-
|
| 24 |
-
uses: actions/checkout@v3
|
| 25 |
-
|
| 26 |
-
# Install the cosign tool except on PR
|
| 27 |
-
|
| 28 |
-
# Set up BuildKit Docker container builder to be able to build
|
| 29 |
-
# multi-platform images and export cache
|
| 30 |
-
# https://github.com/docker/setup-buildx-action
|
| 31 |
-
- name: Set up Docker Buildx
|
| 32 |
-
uses: docker/setup-buildx-action@v3 # v3.0.0
|
| 33 |
-
|
| 34 |
-
# Login against a Docker registry except on PR
|
| 35 |
-
# https://github.com/docker/login-action
|
| 36 |
-
- name: Log into registry ${{ env.REGISTRY }}
|
| 37 |
-
if: github.event_name != 'pull_request'
|
| 38 |
-
uses: docker/login-action@v3 # v3.0.0
|
| 39 |
with:
|
| 40 |
-
registry: ${{ env.REGISTRY }}
|
| 41 |
-
username: ${{ github.actor }}
|
| 42 |
-
password: ${{ secrets.GITHUB_TOKEN }}
|
| 43 |
-
|
| 44 |
-
# Extract metadata (tags, labels) for Docker
|
| 45 |
-
# https://github.com/docker/metadata-action
|
| 46 |
-
- name: Extract Docker metadata
|
| 47 |
-
id: meta
|
| 48 |
-
uses: docker/metadata-action@v5 # v5.0.0
|
| 49 |
-
with:
|
| 50 |
-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
| 51 |
-
|
| 52 |
-
# Build and push Docker image with Buildx (don't push on PR)
|
| 53 |
-
# https://github.com/docker/build-push-action
|
| 54 |
-
- name: Build and push Docker image
|
| 55 |
-
id: build-and-push
|
| 56 |
-
uses: docker/build-push-action@v5 # v5.0.0
|
| 57 |
-
with:
|
| 58 |
-
context: .
|
| 59 |
platforms: linux/amd64,linux/arm64
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
cache-to: type=gha,mode=max
|
|
|
|
| 1 |
+
name: Docker Build
|
| 2 |
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
- develop
|
| 8 |
+
- "feature/**"
|
| 9 |
+
- "hotfix/**"
|
| 10 |
+
tags:
|
| 11 |
+
- "v*.*.*"
|
| 12 |
+
pull_request:
|
| 13 |
+
branches:
|
| 14 |
+
- main
|
| 15 |
+
- develop
|
| 16 |
|
| 17 |
jobs:
|
| 18 |
+
docker:
|
| 19 |
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
steps:
|
| 21 |
+
- uses: pnstack/actions/docker-publish@main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
with:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
platforms: linux/amd64,linux/arm64
|
| 24 |
+
dockerfile: Dockerfile
|
| 25 |
+
context: .
|
| 26 |
+
push_enabled: true
|
| 27 |
+
registry: ghcr.io
|
|
|
Dockerfile
CHANGED
|
@@ -1,45 +1,38 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
PYTHONUNBUFFERED=1 \
|
| 6 |
-
PYTHONFAULTHANDLER=1 \
|
| 7 |
-
LANG=C.UTF-8 \
|
| 8 |
-
LC_ALL=C.UTF-8
|
| 9 |
-
|
| 10 |
-
# Install basic dependencies
|
| 11 |
-
RUN apt-get update && \
|
| 12 |
-
apt-get install -y --no-install-recommends \
|
| 13 |
-
gcc \
|
| 14 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
-
|
| 16 |
-
# Upgrade pip
|
| 17 |
-
RUN pip install --no-cache-dir --upgrade pip
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
ENV PATH="/.venv/bin:$PATH"
|
| 24 |
|
| 25 |
-
# Install dependencies
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
ENV PATH="/.venv/bin:$PATH"
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
COPY . .
|
| 40 |
|
| 41 |
-
|
| 42 |
-
EXPOSE 8000
|
| 43 |
|
| 44 |
-
# Run the application
|
| 45 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a Python image with uv pre-installed
|
| 2 |
+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm
|
| 3 |
|
| 4 |
+
# Install the project into `/app`
|
| 5 |
+
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Enable bytecode compilation
|
| 8 |
+
ENV UV_COMPILE_BYTECODE=1
|
| 9 |
|
| 10 |
+
# Copy from the cache instead of linking since it's a mounted volume
|
| 11 |
+
ENV UV_LINK_MODE=copy
|
|
|
|
| 12 |
|
| 13 |
+
# Install the project's dependencies using the lockfile and settings
|
| 14 |
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 15 |
+
--mount=type=bind,source=uv.lock,target=uv.lock \
|
| 16 |
+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
| 17 |
+
uv sync --frozen --no-install-project --no-dev
|
| 18 |
|
| 19 |
+
# Then, add the rest of the project source code and install it
|
| 20 |
+
# Installing separately from its dependencies allows optimal layer caching
|
| 21 |
+
ADD . /app
|
| 22 |
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
| 23 |
+
uv sync --frozen --no-dev
|
| 24 |
|
| 25 |
+
# Place executables in the environment at the front of the path
|
| 26 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
| 27 |
|
| 28 |
+
# Reset the entrypoint, don't invoke `uv`
|
| 29 |
+
ENTRYPOINT []
|
|
|
|
| 30 |
|
| 31 |
+
# Run setup.py
|
|
|
|
| 32 |
|
| 33 |
+
RUN python setup.py
|
|
|
|
| 34 |
|
| 35 |
+
# Run the FastAPI application by default
|
| 36 |
+
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
|
| 37 |
+
# Uses `--host 0.0.0.0` to allow access from outside the container
|
| 38 |
+
CMD ["python", "main.py"]
|
main.py
CHANGED
|
@@ -13,7 +13,7 @@ def main() -> None:
|
|
| 13 |
import src.modules.api
|
| 14 |
|
| 15 |
except Exception as e:
|
| 16 |
-
|
| 17 |
raise
|
| 18 |
|
| 19 |
|
|
|
|
| 13 |
import src.modules.api
|
| 14 |
|
| 15 |
except Exception as e:
|
| 16 |
+
logging.error(f"Application failed to start: {e}", exc_info=True)
|
| 17 |
raise
|
| 18 |
|
| 19 |
|
setup.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
print("Setup.py")
|