-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerize the mkdocs dev server (#695)
* refine Dockerfile to modularize targets * add Makefile to simplify container build & run process * update readme to explain makefile use * `markdownlint --fix .` * address common error where `ssvc` module is not found due to PYTHONPATH * add `venv` note * explain that ports in docker containers are local to the container * add basic `make` explainer * `markdownlint --fix .` * use long options
- Loading branch information
1 parent
9b53f52
commit 73286d7
Showing
3 changed files
with
145 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
FROM python:3.12-slim-bookworm | ||
|
||
FROM python:3.12-slim-bookworm AS base | ||
RUN pip install --upgrade pip | ||
WORKDIR /app | ||
|
||
FROM base AS dependencies | ||
|
||
# install requirements | ||
COPY requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy the files we need | ||
COPY src/ . | ||
COPY data ./data | ||
COPY . /app | ||
# Set the environment variable | ||
ENV PYTHONPATH=/app/src | ||
|
||
|
||
FROM dependencies AS test | ||
# install pytest | ||
RUN pip install pytest | ||
|
||
# run the unit tests \ | ||
ENTRYPOINT ["pytest"] | ||
CMD ["test"] | ||
CMD ["pytest","src/test"] | ||
|
||
FROM dependencies AS docs | ||
CMD ["mkdocs", "serve", "--dev-addr", "0.0.0.0:8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Project-specific vars | ||
PFX=ssvc | ||
DOCKER=docker | ||
DOCKER_BUILD=$(DOCKER) build | ||
DOCKER_RUN=$(DOCKER) run --tty --rm | ||
PROJECT_VOLUME=--volume $(shell pwd):/app | ||
MKDOCS_PORT=8765 | ||
|
||
# docker names | ||
TEST_DOCKER_TARGET=test | ||
TEST_IMAGE = $(PFX)_test | ||
DOCS_DOCKER_TARGET=docs | ||
DOCS_IMAGE = $(PFX)_docs | ||
|
||
# Targets | ||
.PHONY: all dockerbuild_test dockerrun_test dockerbuild_docs dockerrun_docs docs docker_test clean help | ||
|
||
all: help | ||
|
||
dockerbuild_test: | ||
@echo "Building the test Docker image..." | ||
$(DOCKER_BUILD) --target $(TEST_DOCKER_TARGET) --tag $(TEST_IMAGE) . | ||
|
||
dockerrun_test: | ||
@echo "Running the test Docker image..." | ||
$(DOCKER_RUN) $(PROJECT_VOLUME) $(TEST_IMAGE) | ||
|
||
dockerbuild_docs: | ||
@echo "Building the docs Docker image..." | ||
$(DOCKER_BUILD) --target $(DOCS_DOCKER_TARGET) --tag $(DOCS_IMAGE) . | ||
|
||
dockerrun_docs: | ||
@echo "Running the docs Docker image..." | ||
$(DOCKER_RUN) --publish $(MKDOCS_PORT):8000 $(PROJECT_VOLUME) $(DOCS_IMAGE) | ||
|
||
|
||
docs: dockerbuild_docs dockerrun_docs | ||
docker_test: dockerbuild_test dockerrun_test | ||
|
||
clean: | ||
@echo "Cleaning up..." | ||
$(DOCKER) rmi $(TEST_IMAGE) $(DOCS_IMAGE) || true | ||
|
||
help: | ||
@echo "Usage: make [target]" | ||
@echo "" | ||
@echo "Targets:" | ||
@echo " all - Display this help message" | ||
@echo " docs - Build and run the docs Docker image" | ||
@echo " docker_test - Build and run the test Docker image" | ||
@echo "" | ||
@echo " dockerbuild_test - Build the test Docker image" | ||
@echo " dockerrun_test - Run the test Docker image" | ||
@echo " dockerbuild_docs - Build the docs Docker image" | ||
@echo " dockerrun_docs - Run the docs Docker image" | ||
@echo "" | ||
@echo " clean - Remove the Docker images" | ||
@echo " help - Display this help message" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters