Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #73

Merged
merged 8 commits into from
Oct 28, 2024
Merged

Dev #73

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Default: 0.4.27
UV_IMG_VERSION=
## Default: 3.12-slim
PYTHON_IMG_VERSION=

## Default: 8000
MKDOCS_HTTP_PORT=8002
63 changes: 63 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## Add build args.
# You can pass different args for these values in a docker-compose.yml
# file's build: section
ARG UV_BASE=${UV_IMG_VER:-0.4.27}
ARG PYTHON_BASE=${PYTHON_IMG_VER:-3.12-slim}
ARG NGINX_BASE=${NGINX_IMG_VER:-alpine}

FROM ghcr.io/astral-sh/uv:$UV_BASE as uv
FROM python:$PYTHON_BASE AS base
## Add astral.sh/uv to container's /bin/ path
COPY --from=uv /uv /bin/

## Set environment variables. These will be passed
# to stages that inherit from this layer
ENV PYTHONDONTWRITEBYTECODE 1 \
PYTHONUNBUFFERED 1

## Set CWD in container
WORKDIR /project

## Copy project files & install with uv
COPY pyproject.toml uv.lock ./
RUN uv sync --all-extras --dev && \
uv pip install .

## Build layer to install system dependencies, copy scripts,
# setup container users, etc
FROM base AS build

RUN apt-get update -y && \
apt-get install -y --no-install-recommends git

WORKDIR /project

## Copy remaining project files, i.e. source code
COPY ./docs ./docs
COPY ./includes ./includes
COPY ./mkdocs.yml ./mkdocs.yml

## Build the mkdocs site
RUN uv run mkdocs build

## Runtime layer
FROM build AS run

COPY --from=build /project /project

WORKDIR /project

## Expose a port from a service inside the container
EXPOSE 8000

## Run a command/script inside the container
ENTRYPOINT ["uv", "run", "mkdocs", "serve", "--dev-addr", "0.0.0.0:8000"]

## Serve the static site with nginx
FROM nginx:${NGINX_BASE} AS serve

COPY --from=build /project/site /usr/share/nginx/html

EXPOSE 80

ENTRYPOINT ["nginx", "-g", "daemon off;"]
21 changes: 21 additions & 0 deletions dev.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
services:
mkdocs:
container_name: redkb-mkdocs
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
args:
UV_BASE: ${UV_IMG_VERSION:-0.4.27}
PYTHON_BASE: ${PYTHON_IMG_VERSION:-3.12-slim}
## Layer that runs mkdocs serve
target: run
volumes:
- ./docs:/project/docs
- ./includes:/project/includes
# expose:
# - 8000
ports:
- ${MKDOCS_HTTP_PORT:-8000}:8000

22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
services:
mkdocs:
container_name: redkb-mkdocs
restart: unless-stopped
build:
context: .
dockerfile: Dockerfile
args:
UV_BASE: ${UV_IMG_VERSION:-0.4.27}
PYTHON_BASE: ${PYTHON_IMG_VERSION:-3.12-slim}
## Layer that serves site/ with nginx
target: serve
volumes:
- ./docs:/project/docs
- ./includes:/project/includes
- ./.git:/project/.git
# expose:
# - 80
ports:
- ${NGINX_HTTP_PORT:-80}:80

Loading
Loading