Skip to content

Commit

Permalink
Fixes pozgo#47: Added DEV_ADDR variable for custom mkdocs ip and port…
Browse files Browse the repository at this point in the history
… definition inside of container (pozgo#48)
  • Loading branch information
pozgo authored May 31, 2020
1 parent bda83ca commit 5e6e8b5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ name: Build & Test MKDocs

on:
push:
branches: [ issue/*, feature/* ]
branches: [issue/*, feature/*]
pull_request:
branches: [ master ]
branches: [master]

jobs:

build:

runs-on: ubuntu-latest

steps:
Expand All @@ -24,3 +22,7 @@ jobs:
docker run -d --cap-add NET_ADMIN -p 8000:8000 --name mkdocs polinux/mkdocs:${RELEASE}
sleep 10
curl -sSLi http://127.0.0.1:8000 | grep '200 OK'
# Test custom port
docker run -d --cap-add NET_ADMIN -p 8001:9000 --name custom -e "DEV_ADDR=0.0.0.0:9000" polinux/mkdocs:${RELEASE}
sleep 10
curl -sSLi http://127.0.0.1:8001 | grep '200 OK'
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ ADD container-files/ /

RUN \
apk add --update \
ca-certificates \
bash \
git \
openssh \
python3 \
python3-dev \
build-base && \
pip3 install --upgrade pip && \
ca-certificates \
bash \
git \
openssh \
python3 \
python3-dev \
py3-pip \
build-base && \
pip install --upgrade pip && \
pip install mkdocs==${MKDOCS_VERSION} && \
cd /bootstrap && pip install -e /bootstrap && \
rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/* && \
chmod 600 /root/.ssh/config

CMD ["/usr/bin/bootstrap", "start"]
CMD ["/usr/bin/bootstrap", "start"]
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### MkDocs in a docker.

![Docker Image MKDocs](https://github.com/pozgo/docker-mkdocs/workflows/Docker%20Image%20MKDocs/badge.svg?branch=master)
[![Docker Image MKDocs](https://github.com/pozgo/docker-mkdocs/workflows/Docker%20Image%20MKDocs/badge.svg?branch=master)](https://github.com/pozgo/docker-mkdocs/actions?query=workflow%3A%22Build+%26+Test+MKDocs%22)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpozgo%2Fdocker-mkdocs.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpozgo%2Fdocker-mkdocs?ref=badge_shield)

[![GitHub Open Issues](https://img.shields.io/github/issues/pozgo/docker-mkdocs.svg)](https://github.com/pozgo/docker-mkdocs/issues)
Expand All @@ -25,7 +25,7 @@ version: '3'
services:
mkdocs:
container_name: mkdocs
image: polinux/mkdocs:1.1.0
image: polinux/mkdocs:1.1.2
restart: always
ports:
- "8000:8000"
Expand Down Expand Up @@ -53,6 +53,7 @@ services:
|`GIT_BRANCH`|Self explanatory|`master`|
|`AUTO_UPDATE`|Auto update for git repository support|`false`|
|`UPDATE_INTERVAL`|Update interval in *minutes* - used only when `AUTO_UPDATE` set to `true`|every `15` minutes|
|`DEV_ADDR`|Custom IP address and port to serve documentation locall|`0.0.0.0:8000`|

### Usage

Expand All @@ -68,7 +69,7 @@ Custom config with `git` repository as source of documentation
docker run \
-ti \
--name mkdocs \
-p 80:8000 \
-p 80:9000 \
-e "ADD_MODULES=mkdocs-bootstrap mkdocs-gitbook mkdocs-bootstrap4" \
-e "LIVE_RELOAD_SUPPORT=true" \
-e "FAST_MODE=true" \
Expand All @@ -77,6 +78,7 @@ docker run \
-e "GIT_BRANCH=develop" \
-e "AUTO_UPDATE=true" \
-e "UPDATE_INTERVAL=1" \
-e "DEV_ADDR=0.0.0.0:9000" \
-v ${HOME}/.ssh/id_rsa:/root/.ssh/id_rsa \
polinux/mkdocs
```
Expand Down
15 changes: 11 additions & 4 deletions container-files/bootstrap/app/mkdocs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def start():
_check_previous_installation()
print('Starting MKDocs')
os.chdir(docks_dir)
os.system(f'mkdocs serve -a 0.0.0.0:8000 {_live_reload()} {_fast_mode()}')
if "DEV_ADDR" in os.environ:
_dev_addr = os.environ['DEV_ADDR']
else:
_dev_addr = '0.0.0.0:8000'
os.system(f'mkdocs serve -a {_dev_addr} {_live_reload()} {_fast_mode()}')


def _install_modules(modules):
Expand All @@ -45,13 +49,15 @@ def _check_previous_installation():
:return:
"""
if not os.path.exists(docks_dir + '/mkdocs.yml'):
print(colored(f'No documentation found in ({docks_dir}). Creating new one.', 'yellow'))
print(colored(
f'No documentation found in ({docks_dir}). Creating new one.', 'yellow'))
if not os.path.exists(docks_dir):
os.mkdir(docks_dir)
print(colored(f'Starting fresh installation', 'green'))
os.system(f'mkdocs new {docks_dir}/')
else:
print(colored(f'Detected previous installation in ({docks_dir}).', 'green'))
print(
colored(f'Detected previous installation in ({docks_dir}).', 'green'))


def _live_reload():
Expand Down Expand Up @@ -111,7 +117,8 @@ def _clone_repo(repo):

if auto_update == 'true':
print(colored(f'AUTO_UPDATE - [ ENABLED ]', 'green'))
print(colored(f'UPDATE_INTERVAL set to every {interval} minute/s', 'green'))
print(
colored(f'UPDATE_INTERVAL set to every {interval} minute/s', 'green'))
_set_auto_update(interval)


Expand Down
2 changes: 1 addition & 1 deletion container-files/bootstrap/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='bootstrap',
version='0.0.2',
version='1.0.0',
py_modules=['bootstrap'],
include_package_data=True,
install_requires=[
Expand Down

0 comments on commit 5e6e8b5

Please sign in to comment.