diff --git a/README.md b/README.md index cf90131..a32ea35 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,14 @@ For deploying with heroku only. For auto-building the documentation when a change is detected thanks to https://pypi.org/project/sphinx-autobuild/ +**10. `$ make build_docker_image`** + +To build the production docker image for the docs site, for example: + +``` +$ make build_docker_image DOCKER_IMG_TAG=company/project-docs:develop +``` + Installation ------------ @@ -105,6 +113,27 @@ c.. To build with `travis-ci`, you need to copy these following files to your ro - `.travis/setup.sh` +Auto-build with docker-compose +------------------------------ + +Make sure `docker` and `docker-compose` are installed and running. + +```bash +$ docker-compose up -d +$ echo open http://localhost:`docker port docs_docs_1 80 | grep -o [0-9]*$` to view the docs +open http://localhost:32770 to view the docs +``` + +Check the output from the command above to open the docs site. The docs site will auto reload when +changes are made to the docs files. + +To see the docs site logs, execute the following command: + +```bash +$ docker-compose logs -f docs +``` + + Configuration ------------- @@ -186,6 +215,12 @@ ifndef REPO_URL_HEROKU # REPO_URL_HEROKU = git@heroku.com:spxd.git endif +## -- Docker Config -- ## + +ifndef DOCKER_IMG_TAG +# Configure your default docker image tag +DOCKER_IMG_TAG = sphinx-deployment/docs:develop +endif ## end deployment configuration, don't edit anything below this line ## ####################################################################### diff --git a/docs/Dockerfile b/docs/Dockerfile new file mode 100644 index 0000000..a964f45 --- /dev/null +++ b/docs/Dockerfile @@ -0,0 +1,41 @@ +ARG PYTHON_VERSION=3.6 +ARG NGINX_VERSION=1.13 + +#building +FROM python:$PYTHON_VERSION as builder + +RUN mkdir -p /opt/app + +ENV TERM=xterm-256color APP=/opt/app + +WORKDIR $APP + +ADD requirements.txt $APP/ + +RUN pip install -r requirements.txt + +ADD . $APP + +RUN make html + +# packaging +FROM nginx:$NGINX_VERSION + +LABEL authors="hoatle " + +RUN mkdir -p /opt/app + +ENV TERM=xterm APP=/opt/app + +WORKDIR $APP + +# add more arguments from CI to the image so that `$ env` should reveal more info +ARG CI_BUILD_ID +ARG CI_BUILD_REF +ARG CI_REGISTRY_IMAGE +ARG CI_BUILD_TIME + +ENV CI_BUILD_ID=$CI_BUILD_ID CI_BUILD_REF=$CI_BUILD_REF CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE \ + CI_BUILD_TIME=$CI_BUILD_TIME + +COPY --from=builder /opt/app/_build/html /usr/share/nginx/html diff --git a/docs/docker-compose.yml b/docs/docker-compose.yml new file mode 100644 index 0000000..f306572 --- /dev/null +++ b/docs/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3' + +services: + + # how to use: + # $ docker-compose up -d + # $ echo open http://localhost:`docker port docs_docs_1 80 | grep -o [0-9]*$` to view the docs + # open http://localhost:32770 to view the docs + docs: + image: python:3.6 + working_dir: /opt/app + command: sh run-dev.sh + restart: unless-stopped + ports: + - "80" + volumes: + - .:/opt/app diff --git a/docs/run-dev.sh b/docs/run-dev.sh new file mode 100755 index 0000000..5cafac5 --- /dev/null +++ b/docs/run-dev.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +pip install -r requirements.txt + +make livehtml diff --git a/docs/sphinx_deployment.mk b/docs/sphinx_deployment.mk index 0287ed9..1d67ee4 100644 --- a/docs/sphinx_deployment.mk +++ b/docs/sphinx_deployment.mk @@ -101,6 +101,14 @@ ifndef REPO_URL_HEROKU endif +## -- Docker Config -- ## + +ifndef DOCKER_IMG_TAG +# Configure your default docker image tag +DOCKER_IMG_TAG = sphinx-deployment/docs:develop +endif + + ## end deployment configuration, don't edit anything below this line ## ####################################################################### @@ -204,3 +212,8 @@ gen_deploy: generate deploy # `$ make livehtml` to auto-build the documentation when a change is detected livehtml: sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html -H 0.0.0.0 --port 80 + +# for example: `$ make build_docker_image DOCKER_IMG_TAG=company/project-docs:develop` +build_docker_image: + @echo "docker build -t $(DOCKER_IMG_TAG) -f Dockerfile ." + docker build -t $(DOCKER_IMG_TAG) -f Dockerfile .