Skip to content
Merged
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
8 changes: 5 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,29 @@
{
"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"
}
}
},
{
"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"
}
}
},
{
"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",
Expand Down
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
7 changes: 3 additions & 4 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. |
<!-- markdownlint-enable MD038 -->
Expand All @@ -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
```
4 changes: 2 additions & 2 deletions docker/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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
echo -e "${CYAN}Setting default version to ${INPUT_DEFAULT_VERSION}${UNSET}"
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
Expand Down
16 changes: 11 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
7 changes: 7 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion mkdocs_simple_plugin/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion mkdocs_simple_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class TestDefaultConfig(unittest.TestCase):
env_variables = [
'INPUT_SITE_NAME',
'INPUT_SITE_URL',
'INPUT_SITE_DIR',
'INPUT_REPO_URL',
'INPUT_THEME']

Expand Down Expand Up @@ -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(
Expand Down