2025-12-05 14:22:39 +01:00
|
|
|
FROM python:3.13-slim
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Install system dependencies
|
|
|
|
|
RUN apt-get update && apt-get install -y \
|
|
|
|
|
curl \
|
|
|
|
|
git \
|
2025-12-05 14:42:18 +01:00
|
|
|
libpq-dev \
|
|
|
|
|
gcc \
|
2025-12-17 17:21:03 +01:00
|
|
|
g++ \
|
|
|
|
|
python3-dev \
|
2026-01-06 15:11:28 +01:00
|
|
|
postgresql-client \
|
2025-12-05 14:22:39 +01:00
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
# Build arguments for GitHub release deployment
|
|
|
|
|
ARG RELEASE_VERSION=latest
|
|
|
|
|
ARG GITHUB_TOKEN
|
|
|
|
|
ARG GITHUB_REPO=ct/bmc_hub
|
2025-12-17 21:10:31 +01:00
|
|
|
ARG GITEA_URL=https://g.bmcnetworks.dk
|
2025-12-05 14:22:39 +01:00
|
|
|
|
2026-01-06 08:39:23 +01:00
|
|
|
# Copy requirements first for better caching
|
|
|
|
|
COPY requirements.txt /tmp/requirements.txt
|
|
|
|
|
|
2025-12-05 14:22:39 +01:00
|
|
|
# If RELEASE_VERSION is set and not "latest", pull from GitHub release
|
2026-01-06 08:39:23 +01:00
|
|
|
# Otherwise, use local requirements
|
2025-12-05 14:22:39 +01:00
|
|
|
RUN if [ "$RELEASE_VERSION" != "latest" ] && [ -n "$GITHUB_TOKEN" ]; then \
|
2025-12-17 21:10:31 +01:00
|
|
|
echo "Downloading release ${RELEASE_VERSION} from Gitea..." && \
|
2025-12-05 14:22:39 +01:00
|
|
|
curl -H "Authorization: token ${GITHUB_TOKEN}" \
|
2025-12-17 21:10:31 +01:00
|
|
|
-L "${GITEA_URL}/api/v1/repos/${GITHUB_REPO}/archive/${RELEASE_VERSION}.tar.gz" \
|
2025-12-05 14:22:39 +01:00
|
|
|
-o /tmp/release.tar.gz && \
|
|
|
|
|
tar -xzf /tmp/release.tar.gz --strip-components=1 -C /app && \
|
2025-12-17 21:10:31 +01:00
|
|
|
rm /tmp/release.tar.gz && \
|
|
|
|
|
echo "Installing dependencies from release..." && \
|
|
|
|
|
pip install --no-cache-dir -r requirements.txt; \
|
|
|
|
|
else \
|
|
|
|
|
echo "Using local files..." && \
|
|
|
|
|
pip install --no-cache-dir -r /tmp/requirements.txt; \
|
2025-12-05 14:22:39 +01:00
|
|
|
fi
|
|
|
|
|
|
2026-03-03 22:19:26 +01:00
|
|
|
# Copy local source to temp location.
|
|
|
|
|
# In release builds we keep downloaded source in /app.
|
|
|
|
|
# In latest/local builds we copy from /app_local to /app.
|
|
|
|
|
COPY . /app_local
|
|
|
|
|
|
|
|
|
|
RUN if [ "$RELEASE_VERSION" = "latest" ] || [ -z "$GITHUB_TOKEN" ]; then \
|
|
|
|
|
echo "Using local source files..." && \
|
|
|
|
|
cp -a /app_local/. /app/; \
|
|
|
|
|
else \
|
|
|
|
|
echo "Keeping downloaded release source in /app (no local override)"; \
|
|
|
|
|
fi && \
|
|
|
|
|
rm -rf /app_local
|
2025-12-05 14:22:39 +01:00
|
|
|
|
|
|
|
|
# Create necessary directories
|
|
|
|
|
RUN mkdir -p /app/logs /app/uploads /app/static /app/data
|
|
|
|
|
|
|
|
|
|
# Expose port
|
|
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
|
|
|
# Health check
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=40s \
|
|
|
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
|
|
|
|
|
|
|
|
|
# Run application
|
|
|
|
|
CMD ["python", "main.py"]
|