diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2f3fc77e..8b38080a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -81,9 +81,10 @@ { "label": "action dry run", "type": "shell", - "command": "docker run --rm -v ${workspaceFolder}:/docs -e INPUT_PUSH --user $(id -u):$(id -g) althack/mkdocs-simple-plugin:latest deploy.sh", + "command": "docker run --rm -v ${workspaceFolder}:/docs -e INPUT_PUSH -e INPUT_SITE_DIR --user $(id -u):$(id -g) althack/mkdocs-simple-plugin:latest deploy.sh", "options": { "env": { + "INPUT_SITE_DIR": "/docs/site", "INPUT_PUSH": "false" } } @@ -91,9 +92,10 @@ { "label": "action dry run (root)", "type": "shell", - "command": "docker run --rm -v ${workspaceFolder}:/docs -e INPUT_PUSH althack/mkdocs-simple-plugin:latest deploy.sh", + "command": "docker run --rm -v ${workspaceFolder}:/docs -e INPUT_PUSH -e INPUT_SITE_DIR althack/mkdocs-simple-plugin:latest deploy.sh", "options": { "env": { + "INPUT_SITE_DIR": "/docs/site", "INPUT_PUSH": "false" } } @@ -101,7 +103,7 @@ { "label": "action serve", "type": "shell", - "command": "docker run --rm -p 8000:8000 -v ${PWD}:/docs --user $(id -u):$(id -g) -it althack/mkdocs-simple-plugin:latest" + "command": "docker run --rm -p 8000:8000 -v ${PWD}:/docs -it althack/mkdocs-simple-plugin:latest" }, { "label": "test", diff --git a/Dockerfile b/Dockerfile index d6460d65..c80febc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,18 +14,13 @@ RUN apt-get update && apt-get -y install --no-install-recommends \ python3-pip \ vim -WORKDIR /tmp +WORKDIR /opt/mkdocs-simple-plugin COPY mkdocs_simple_plugin mkdocs_simple_plugin COPY README.md README.md COPY VERSION VERSION COPY setup.py setup.py COPY pyproject.toml pyproject.toml - -RUN pip install --upgrade pip \ - && pip install --no-cache-dir . \ - && pip install --no-cache-dir mkdocs-material mike pillow cairosvg - -WORKDIR /docs +COPY docker/requirements.txt requirements.txt EXPOSE 8000 @@ -35,6 +30,8 @@ ENV PATH=/home/mkdocs/.local/bin:${PATH} COPY docker/deploy.sh /usr/local/bin/ COPY docker/entrypoint.sh /usr/local/bin/ + +WORKDIR /docs ENTRYPOINT ["entrypoint.sh"] CMD ["mkdocs_simple_gen", "--serve", "--", "-a", "0.0.0.0:8000", "--dirtyreload"] diff --git a/docker/README.md b/docker/README.md index f839c8ed..50d04393 100644 --- a/docker/README.md +++ b/docker/README.md @@ -9,7 +9,7 @@ Using the docker image, you don't need to have the plugin or its dependencies in Install, build and serve your docs: ```bash -docker run --rm -it --network=host -v ${PWD}:/docs --user $(id -u):$(id -g) althack/mkdocs-simple-plugin +docker run --rm -it -p 8000:8000 -v ${PWD}:/docs althack/mkdocs-simple-plugin:latest ``` Explanation of docker command-line options @@ -19,7 +19,6 @@ Explanation of docker command-line options | :------------------------- | :-------------------------------------------------------------------------- | | `-p 8000:8000` | [required] Map the mkdocs server port to a port on your localhost. | | `-v ${PWD}:/docs` | [required] Mount the local directory into the docs directory to build site. | -| `--user $(id -u):$(id -g)` | [recommended] Run the docker container with the current user and group. | | `--rm` | [optional] remove the docker image after it finishes running. | | `-it` | [optional] run in an interactive terminal. | @@ -31,8 +30,8 @@ The docker image runs `mkdocs serve` by default. Add an alias for the docker command to serve docs from any workspace. ```bash -echo 'function mkdocs_simple() { +echo 'function mkdocs_simple_serve() { local port=${1:-"8000"} - docker run --rm -p ${port}:8000 -v ${PWD}:/docs --user $(id -u):$(id -g) althack/mkdocs-simple-plugin + docker run --rm -it -p ${port}:8000 -v ${PWD}:/docs althack/mkdocs-simple-plugin:latest }' >> ~/.bashrc ``` diff --git a/docker/deploy.sh b/docker/deploy.sh index 79dbb45c..f8c4c4b5 100755 --- a/docker/deploy.sh +++ b/docker/deploy.sh @@ -31,7 +31,7 @@ if [[ "${INPUT_PUSH}" == "1" || "${INPUT_PUSH,,}" == "true" ]]; then mike deploy --config-file ${INPUT_CONFIG} -p -u -b ${INPUT_PUBLISH_BRANCH} ${INPUT_VERSION} else echo -e "${CYAN}Deploying docs to ${INPUT_PUBLISH_BRANCH}${UNSET}" - mkdocs gh-deploy --config-file ${INPUT_CONFIG} -b ${INPUT_PUBLISH_BRANCH} + mkdocs gh-deploy --config-file ${INPUT_CONFIG} -b ${INPUT_PUBLISH_BRANCH} -d ${INPUT_SITE_DIR} fi if [ "${INPUT_DEFAULT_VERSION}" ]; then @@ -39,7 +39,7 @@ if [[ "${INPUT_PUSH}" == "1" || "${INPUT_PUSH,,}" == "true" ]]; then mike set-default -p -b ${INPUT_PUBLISH_BRANCH} ${INPUT_DEFAULT_VERSION} fi else - mkdocs build --config-file ${INPUT_CONFIG} + mkdocs build --config-file ${INPUT_CONFIG} -d ${INPUT_SITE_DIR} fi # Set permissions diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index ab7e9c98..c8ed5110 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -3,12 +3,18 @@ set -e git config --global --add safe.directory /docs +PIP_OPTS='' + +if [ "$UID" -ne 0 ]; then + PIP_OPTS="--user" +fi + +pip install ${PIP_OPTS} --upgrade pip +pip install ${PIP_OPTS} /opt/mkdocs-simple-plugin +pip install ${PIP_OPTS} -r /opt/mkdocs-simple-plugin/requirements.txt + if [ -f "requirements.txt" ]; then - if [ "$UID" -eq 0 ]; then - pip install -r requirements.txt - else - pip install --user -r requirements.txt - fi + pip install ${PIP_OPTS} -r requirements.txt fi exec "$@" diff --git a/docker/requirements.txt b/docker/requirements.txt new file mode 100644 index 00000000..446a1403 --- /dev/null +++ b/docker/requirements.txt @@ -0,0 +1,7 @@ +cairosvg==2.7.1 +mike==1.1.2 +mkdocs-awesome-pages-plugin==2.9.2 +mkdocs-material==9.2.3 +mkdocs==1.5.2 +pillow==10.0.0 +pymdown-extensions==10.1 diff --git a/mkdocs_simple_plugin/generator.py b/mkdocs_simple_plugin/generator.py index 80329ec8..746a3464 100644 --- a/mkdocs_simple_plugin/generator.py +++ b/mkdocs_simple_plugin/generator.py @@ -68,7 +68,6 @@ def maybe_set_dict(name, key): # Set the config variables via environment if exist maybe_set_string("site_name") maybe_set_string("site_url") - maybe_set_string("site_dir") maybe_set_string("repo_url") maybe_set_dict("theme", "name") return config diff --git a/mkdocs_simple_plugin/plugin.py b/mkdocs_simple_plugin/plugin.py index 41cfef92..b4af582b 100644 --- a/mkdocs_simple_plugin/plugin.py +++ b/mkdocs_simple_plugin/plugin.py @@ -390,7 +390,8 @@ def on_files(self, files: Files, *, config): use_directory_urls=config["use_directory_urls"] ) if file.abs_dest_path in dedupe_files: - files.remove(dedupe_files[file.abs_dest_path]) + if file.abs_dest_path in files: + files.remove(dedupe_files[file.abs_dest_path]) files.append(file) return files diff --git a/tests/test_generator.py b/tests/test_generator.py index bcfe9086..df06e56b 100755 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -19,7 +19,6 @@ class TestDefaultConfig(unittest.TestCase): env_variables = [ 'INPUT_SITE_NAME', 'INPUT_SITE_URL', - 'INPUT_SITE_DIR', 'INPUT_REPO_URL', 'INPUT_THEME'] @@ -87,14 +86,6 @@ def test_site_url(self): config_name="site_url", config_value="https://www.althack.dev/mkdocs-simple-plugin/") - def test_site_dir(self): - """Test setting the site url.""" - self._test_env_setting( - env_variable="SITE_DIR", - env_value="/test_dir", - config_name="site_dir", - config_value="/test_dir") - def test_repo_url(self): """Test setting the repo url.""" self._test_env_setting(