2bd778117f
Replace persistent Cloudflare tunnels (API-based) with temporary tunnels using 'cloudflared tunnel --url'. This removes the need for Cloudflare API tokens, DNS records, and persistent tunnel management. Changes: - Install cloudflared binary in API Dockerfile - Add start_cloudflared_tunnel() and stop_cloudflared_tunnel() to docker.py - Update instance start/stop/restart/delete to use temporary tunnels - Store tunnel PID in tunnel_id field, temporary URL in url/public_url - Remove Cloudflare API service (cloudflare_tunnel.py) - Remove cloudflared container from docker-compose - Remove Cloudflare env vars (CLOUDFLARE_API_TOKEN, ZONE_ID, etc.) - Remove Cloudflare configuration from config.py - Remove Cloudflare startup check from main.py - Remove /health/cloudflare endpoint
74 lines
2.6 KiB
Docker
74 lines
2.6 KiB
Docker
# Build stage
|
|
FROM python:3.11-slim as builder
|
|
|
|
WORKDIR /build
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc \
|
|
libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies
|
|
COPY pyproject.toml .
|
|
RUN pip install --no-cache-dir --user -e ".[dev]"
|
|
|
|
# Production stage
|
|
FROM python:3.11-slim
|
|
|
|
# Create non-root user and add to docker group
|
|
RUN groupadd -r appgroup && useradd -r -g appgroup appuser \
|
|
&& groupadd -r docker || true \
|
|
&& usermod -aG docker appuser
|
|
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies including Docker CLI
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libpq5 \
|
|
git \
|
|
netcat-openbsd \
|
|
ca-certificates \
|
|
curl \
|
|
gnupg \
|
|
&& install -m 0755 -d /etc/apt/keyrings \
|
|
&& curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
|
|
&& chmod a+r /etc/apt/keyrings/docker.gpg \
|
|
&& echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
|
|
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list \
|
|
&& apt-get update \
|
|
&& apt-get install -y --no-install-recommends docker-ce-cli docker-compose-plugin \
|
|
&& curl -L --output /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 \
|
|
&& chmod +x /usr/local/bin/cloudflared \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy dependencies from builder
|
|
COPY --from=builder /root/.local /root/.local
|
|
ENV PATH=/root/.local/bin:$PATH
|
|
|
|
# Copy application code
|
|
COPY --chown=appuser:appgroup . .
|
|
|
|
# Create directories for repo and instance storage
|
|
RUN mkdir -p /data/repos /data/instances && chown -R appuser:appgroup /data
|
|
|
|
# Copy wait-for-db script
|
|
COPY wait-for-db.sh /usr/local/bin/wait-for-db.sh
|
|
RUN chmod +x /usr/local/bin/wait-for-db.sh
|
|
|
|
# NOTE: Running as root to access Docker socket for managing tool instances
|
|
# This is required because Docker socket permissions require root or docker group membership
|
|
# which doesn't work well across container boundaries.
|
|
# Consider using Docker-in-Docker or rootless Docker for production hardening.
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
|
|
# Run the application (with database wait)
|
|
ENTRYPOINT ["/usr/local/bin/wait-for-db.sh"]
|
|
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|