From 4e13df9738d46c88f4ab16d15c4d4f7b7a28ac1a Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Tue, 24 Sep 2019 07:50:06 +0530 Subject: [PATCH] Docker compose (#417) * feat(docker): add healthcheck to container Signed-off-by: Ameya Shenoy * feat(docker): add docker-compose files Signed-off-by: Ameya Shenoy --- Dockerfile | 9 ++++++-- bukuserver/README.md | 31 ++++++++++++++++++++++++++++ docker-compose/data/nginx/nginx.conf | 22 ++++++++++++++++++++ docker-compose/docker-compose.yml | 26 +++++++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 docker-compose/data/nginx/nginx.conf create mode 100644 docker-compose/docker-compose.yml diff --git a/Dockerfile b/Dockerfile index c49ef77..41ba650 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ FROM python:alpine MAINTAINER Ameya Shenoy "shenoy.ameya@gmail.com" +ENV BUKUSERVER_PORT=5001 + COPY . /Buku RUN set -ex \ @@ -17,6 +19,9 @@ RUN set -ex \ && apk del .build-deps \ && rm -rf /Buku -ENTRYPOINT gunicorn --bind 0.0.0.0:5001 "bukuserver.server:create_app()" -EXPOSE 5001 +HEALTHCHECK --interval=1m --timeout=10s \ + CMD nc -z localhost ${BUKUSERVER_PORT} || exit 1 + +ENTRYPOINT gunicorn --bind 0.0.0.0:${BUKUSERVER_PORT} "bukuserver.server:create_app()" +EXPOSE ${BUKUSERVER_PORT} diff --git a/bukuserver/README.md b/bukuserver/README.md index 5d290d7..9576114 100644 --- a/bukuserver/README.md +++ b/bukuserver/README.md @@ -7,6 +7,7 @@ - [From PyPi](#from-pypi) - [From source](#from-source) - [Using Docker](#using-docker) + - [Using Docker Compose](#using-docker-compose) - [Webserver options](#webserver-options) - [Configuration](#configuration) - [Screenshots](#screenshots) @@ -57,6 +58,36 @@ database. Visit `127.0.0.1:5001` in your browser to access your bookmarks. +#### Using Docker Compose + +There is a `docker-compose.yml` file present in the `docker-compose` directory +in the root of this project. You may modify the configurations in this file to +your liking, and then simply execute the below command. + +```sh +docker-compose up -d +``` + +You will have you bukuserver running on port port 80 of the host. + +To stop simply run + +```sh +docker-compose down +``` + +In case you want to add basic auth to your hosted instance you may do so by +creating a `.htpasswd` file in the `data/basic_auth` directory. Add a user to +the file using + +```sh +htpasswd -c data/basic_auth/.htpasswd your_username +``` + +And then comment out the basic auth lines from the `data/nginx/nginx.conf` file. + +For more information please refer the [nginx docs](https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/). + ### Webserver options To run the server on host 127.0.0.1, port 5001, run following command: diff --git a/docker-compose/data/nginx/nginx.conf b/docker-compose/data/nginx/nginx.conf new file mode 100644 index 0000000..2562128 --- /dev/null +++ b/docker-compose/data/nginx/nginx.conf @@ -0,0 +1,22 @@ +server { + listen 80; + server_name yoursitename.com; + server_tokens off; + + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + location / { + #auth_basic "Administrator's Area"; + #auth_basic_user_file /basic_auth/.htpasswd; + proxy_pass http://bukuserver:5001; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Remote-Port $remote_port; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_redirect off; + } +} + diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml new file mode 100644 index 0000000..c51cc49 --- /dev/null +++ b/docker-compose/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3.7' + +services: + bukuserver: + image: bukuserver/bukuserver + restart: unless-stopped + environment: + - BUKUSERVER_PER_PAGE=100 + - BUKUSERVER_OPEN_IN_NEW_TAB=true + # - BUKUSERVER_SECRET_KEY=123456789012345678901234 + # - BUKUSERVER_URL_RENDER_MODE=full + # - BUKUSERVER_DISABLE_FAVICON=false + ports: + - "5001:5001" + volumes: + - ./data:/root/.local/share/buku + + nginx: + image: nginx:alpine + restart: unless-stopped + ports: + - "80:80" + volumes: + - ./data/nginx:/etc/nginx/conf.d + - ./data/basic_auth:/basic_auth +