Skip to content

Commit

Permalink
Merge pull request #9 from gdgib/G2-1629-MultiSiteBuilds
Browse files Browse the repository at this point in the history
G2-1629 Support for multiple site builds
  • Loading branch information
gdgib authored Aug 29, 2024
2 parents cdc4732 + 7d3c27a commit 7f2c979
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM nginx:alpine
RUN apk add --no-cache \
bash \
git \
rsync \
mkdocs \
py3-pip \
mkdocs-material \
Expand All @@ -14,6 +15,7 @@ ENV MKDOCKER_REPOSITORY_URL github.com/g2forge/mkdocker
ENV MKDOCKER_REPOSITORY_LOGIN ''

Check warning on line 15 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV MKDOCKER_REPOSITORY_BRANCH main

Check warning on line 16 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV MKDOCKER_REPOSITORY_DIRECTORY example

Check warning on line 17 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV MKDOCKER_TEMP_DIRECTORY /mkdocker/temp

Check warning on line 18 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV MKDOCKER_LOCAL_DIRECTORY /mkdocker/docs

Check warning on line 19 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV MKDOCKER_VENV_DIRECTORY /mkdocker/venv

Check warning on line 20 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV MKDOCKER_SERVE 0

Check warning on line 21 in Dockerfile

View workflow job for this annotation

GitHub Actions / build

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ mkdocker can run scripts both before and after the mkdocs build.
Simply create `scripts/pre` and `scripts/post` files in the `MKDOCKER_REPOSITORY_DIRECTORY` directory, and mark them executable.
One example of this is shown in this repository to created [protected pages](example/scripts/post) by modifying the nginx config.

## Control File

Each script takes two arguments: the path to a temp directory for use by the scripts, and the path to the control file.
The `pre` script should create this file, and both mkdocker and the `post` script will consume it.
If the `pre` script does not exist or does not create the file, mkdocker will.

Each line of the control file represents a separate mkdocs build, though only the last build will be served when `MKDOCKER_SERVE` is set all will be built.
Each line specifies a repository-relative or absolute path for the source, and a HTTP root relative path for the destination separated by a space (using bash quoting).
`mkdocs` will be run once per line.

The default control file is:

```
. .
```

# Development

* Build - `docker build ./ -t mkdocker:latest`
Expand Down
31 changes: 28 additions & 3 deletions mkdocker/scripts/mkdocker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash
set -eu -o pipefail

SCRIPT_TEMP="${MKDOCKER_TEMP_DIRECTORY}/script-temp"
mkdir -pv "${SCRIPT_TEMP}"

if [ ! -d "${MKDOCKER_LOCAL_DIRECTORY}" ]; then
mkdir -pv "${MKDOCKER_LOCAL_DIRECTORY}"
cd "${MKDOCKER_LOCAL_DIRECTORY}"
Expand Down Expand Up @@ -40,13 +43,32 @@ fi
echo "Running build"
if [ -x scripts/pre ]; then
echo Running pre script
./scripts/pre
./scripts/pre "${SCRIPT_TEMP}" "${MKDOCKER_TEMP_DIRECTORY}/control"
fi

if [ ! -f "${MKDOCKER_TEMP_DIRECTORY}/control" ]; then
cat << EOF > "${MKDOCKER_TEMP_DIRECTORY}/control"
. .
EOF
fi
# For all but the last site, build them
while read -r SOURCE TARGET; do
echo "Building ${SOURCE} to ${TARGET}"
pushd "${SOURCE}"
mkdocs build -d "/usr/share/nginx/html/${TARGET}"
popd
done < <(head -n -1 "${MKDOCKER_TEMP_DIRECTORY}/control")

# For the last site, build or serve it
read -r SOURCE TARGET < <(tail -n 1 "${MKDOCKER_TEMP_DIRECTORY}/control")
if [ "${MKDOCKER_SERVE}" = 0 ]; then
mkdocs build -d /usr/share/nginx/html
echo "Building ${SOURCE} to ${TARGET}"
pushd "${SOURCE}"
mkdocs build -d "/usr/share/nginx/html/${TARGET}"
popd
if [ -x scripts/post ]; then
echo Running post script
./scripts/post
./scripts/post "${SCRIPT_TEMP}" "${MKDOCKER_TEMP_DIRECTORY}/control"
fi

if [ -d "${MKDOCKER_VENV_DIRECTORY}" ]; then
Expand All @@ -56,5 +78,8 @@ if [ "${MKDOCKER_SERVE}" = 0 ]; then

nginx -g "daemon off;"
else
echo "Serving ${SOURCE}"
pushd "${SOURCE}"
mkdocs serve -a "0.0.0.0:80"
popd
fi

0 comments on commit 7f2c979

Please sign in to comment.