feat: add gitea docker
This commit is contained in:
91
Dockerfile
91
Dockerfile
@@ -1,60 +1,57 @@
|
||||
# Use an official Python runtime based on Debian 12 "bookworm" as a parent image.
|
||||
FROM python:3.12-slim-bookworm
|
||||
FROM python:3.14-slim-bookworm AS builder
|
||||
|
||||
# Add user that will be used in the container.
|
||||
RUN useradd wagtail
|
||||
RUN useradd -m kursy
|
||||
|
||||
# Port used by this container to serve HTTP.
|
||||
EXPOSE 8000
|
||||
ENV NODE_VERSION=24.14.1
|
||||
|
||||
# Set environment variables.
|
||||
# 1. Force Python stdout and stderr streams to be unbuffered.
|
||||
# 2. Set PORT variable that is used by Gunicorn. This should match "EXPOSE"
|
||||
# command.
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PORT=8000
|
||||
# install uv
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
||||
|
||||
# Install system packages required by Wagtail and Django.
|
||||
RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
libmariadb-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
zlib1g-dev \
|
||||
libwebp-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# install nodejs
|
||||
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
||||
apt-get install -y nodejs
|
||||
|
||||
# Install the application server.
|
||||
RUN pip install "gunicorn==20.0.4"
|
||||
# copy project files
|
||||
WORKDIR /app
|
||||
COPY pyproject.toml uv.lock ./
|
||||
|
||||
# Install the project requirements.
|
||||
COPY requirements.txt /
|
||||
RUN pip install -r /requirements.txt
|
||||
RUN chown kursy:kursy /app -R
|
||||
|
||||
# Use /app folder as a directory where the source code is stored.
|
||||
USER kursy
|
||||
|
||||
# install project dependencies
|
||||
RUN uv sync
|
||||
|
||||
COPY --chown=kursy:kursy . .
|
||||
|
||||
# install tailwind
|
||||
WORKDIR /app/theme/static_src
|
||||
RUN npm install
|
||||
|
||||
# collect static files
|
||||
WORKDIR /app
|
||||
RUN uv run python manage.py collectstatic --noinput --clear
|
||||
|
||||
|
||||
# --- RUNTIME IMAGE ---
|
||||
FROM python:3.14-slim-bookworm
|
||||
|
||||
RUN useradd -m kursy
|
||||
WORKDIR /app
|
||||
|
||||
# Set this directory to be owned by the "wagtail" user. This Wagtail project
|
||||
# uses SQLite, the folder needs to be owned by the user that
|
||||
# will be writing to the database file.
|
||||
RUN chown wagtail:wagtail /app
|
||||
RUN mkdir -p /app/data && chown kursy:kursy /app/data
|
||||
|
||||
# Copy the source code of the project into the container.
|
||||
COPY --chown=wagtail:wagtail . .
|
||||
USER kursy
|
||||
|
||||
# Use user "wagtail" to run the build commands below and the server itself.
|
||||
USER wagtail
|
||||
COPY --from=builder --chown=kursy:kursy /app/.venv /app/.venv
|
||||
COPY --from=builder --chown=kursy:kursy /app /app
|
||||
|
||||
# Collect static files.
|
||||
RUN python manage.py collectstatic --noinput --clear
|
||||
ENV PATH="/app/.venv/bin:$PATH" \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PORT=8000
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD set -xe; python manage.py migrate --noinput; python manage.py runserver 0.0.0.0:8000
|
||||
|
||||
# Runtime command that executes when "docker run" is called, it does the
|
||||
# following:
|
||||
# 1. Migrate the database.
|
||||
# 2. Start the application server.
|
||||
# WARNING:
|
||||
# Migrating database at the same time as starting the server IS NOT THE BEST
|
||||
# PRACTICE. The database should be migrated manually or using the release
|
||||
# phase facilities of your hosting platform. This is used only so the
|
||||
# Wagtail instance can be started with a simple "docker run" command.
|
||||
CMD set -xe; python manage.py migrate --noinput; gunicorn kursy.wsgi:application
|
||||
|
||||
Reference in New Issue
Block a user