Skip to content

Commit

Permalink
Merge pull request #6 from gdgib/G2-1619-Requirements
Browse files Browse the repository at this point in the history
G2-1619 Install python modules from requirements.txt
  • Loading branch information
gdgib authored Aug 13, 2024
2 parents 8807878 + 3073d44 commit f6168da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RUN apk add --no-cache \
bash \
git \
mkdocs \
py3-pip \
py3-pathspec py3-markupsafe py3-platformdirs
## The last line is only needed because nginx:alpine uses an older version, which doesn't have this dependency
## See https://pkgs.alpinelinux.org/package/edge/community/x86_64/mkdocs vs https://pkgs.alpinelinux.org/package/v3.19/community/x86_64/mkdocs
Expand All @@ -12,6 +13,7 @@ ENV MKDOCKER_REPOSITORY_URL github.com/g2forge/mkdocker
ENV MKDOCKER_REPOSITORY_BRANCH main

Check warning on line 13 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 14 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 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_VENV_DIRECTORY /mkdocker/venv

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/

EXPOSE 80

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ docker run -d --mount type=bind,source=${pwd},target=/mkdocker/docs --publish 12
* `MKDOCKER_REPOSITORY_URL` - The git repository to clone, without the protocol (default: `github.com/g2forge/mkdocker`)
* `MKDOCKER_REPOSITORY_BRANCH` - The branch in the git repository to build (default: `main`)
* `MKDOCKER_REPOSITORY_DIRECTORY` - The subdirectory in the git repository to run the build in (default: `example`)
* `MKDOCKER_LOCAL_DIRECTORY` - The directory inside the docker container to clone the repository in to, or to just use if already mounted (default `/mkdocker/docs`)
* `MKDOCKER_LOCAL_DIRECTORY` - The directory inside the docker container to clone the repository in to, or to just use if already mounted (default: `/mkdocker/docs`)
* `MKDOCKER_VENV_DIRECTORY` - The directory inside the docker container to use for the python virtual environment (default: `/mkdocker/venv`). This is only necessary if a `requirements.txt` is present, and can optionally be mounted to a docker volume for persistence.


## Scripts

Expand Down
18 changes: 16 additions & 2 deletions mkdocker/scripts/mkdocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ fi
cd "${MKDOCKER_REPOSITORY_DIRECTORY}"
echo "----------"
echo "Current directory: $(pwd)"
echo "Directory listing:"
ls -alR ./
echo "----------"

if [ -f requirements.txt ]; then
if [ ! -d "${MKDOCKER_VENV_DIRECTORY}" ] || [ -z "$(ls -A "${MKDOCKER_VENV_DIRECTORY}")" ]; then
echo "Creating virtual environment"
python3 -m venv "${MKDOCKER_VENV_DIRECTORY}"
fi
echo "Activating virtual environment"
. "${MKDOCKER_VENV_DIRECTORY}/bin/activate"
echo "Installing python requirements"
pip install -r requirements.txt
fi

echo "Running build"
if [ -x scripts/pre ]; then
echo Running pre script
Expand All @@ -33,4 +42,9 @@ if [ -x scripts/post ]; then
./scripts/post
fi

if [ -d "${MKDOCKER_VENV_DIRECTORY}" ]; then
echo "Deactivating virtual environment"
deactivate
fi

nginx -g "daemon off;"

0 comments on commit f6168da

Please sign in to comment.