From 98439623c52696e0d69c55b74638b984ad41993b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 21 Jan 2021 17:32:58 +0200 Subject: [PATCH] Add experimental Dockerfile and docker-compose.yml --- CHANGELOG.md | 1 + docker/Dockerfile | 22 ++++++++++++++ docker/docker-compose.yml | 34 ++++++++++++++++++++++ docker/uwsgi.ini | 18 ++++++++++++ templates/docs/configuring_prometheus.html | 2 +- templates/docs/configuring_prometheus.md | 2 +- templates/docs/self_hosted_docker.html | 34 ++++++++++++++++++++++ templates/docs/self_hosted_docker.md | 31 ++++++++++++++++++++ templates/front/base_docs.html | 1 + 9 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.yml create mode 100644 docker/uwsgi.ini create mode 100644 templates/docs/self_hosted_docker.html create mode 100644 templates/docs/self_hosted_docker.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 35098918..1b2cd92b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - Add Signal integration (#428) - Change Zulip onboarding, ask for the zuliprc file (#202) - Add a section in Docs about running self-hosted instances +- Add experimental Dockerfile and docker-compose.yml ## Bug Fixes - Fix unwanted HTML escaping in SMS and WhatsApp notifications diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..bbc41856 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.8 + +RUN useradd --system hc +ENV PYTHONUNBUFFERED=1 +WORKDIR /opt/healthchecks + +COPY requirements.txt /tmp +RUN \ + pip install --no-cache-dir -r /tmp/requirements.txt && \ + pip install uwsgi + +COPY . /opt/healthchecks/ + +RUN \ + rm -f /opt/healthchecks/hc/local_settings.py && \ + DEBUG=False SECRET_KEY=build-key ./manage.py collectstatic --noinput && \ + DEBUG=False SECRET_KEY=build-key ./manage.py compress + +USER hc + +CMD [ "uwsgi", "/opt/healthchecks/docker/uwsgi.ini"] + diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..1a5751cd --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,34 @@ +version: "3" +volumes: + db-data: + +services: + db: + image: postgres:12 + volumes: + - db-data:/var/lib/postgresql + environment: + - POSTGRES_DB=hc + - POSTGRES_PASSWORD=fixme-postgres-password + web: + build: + context: .. + dockerfile: docker/Dockerfile + environment: + - DEBUG=False + - DB=postgres + - DB_HOST=db + - DB_PORT=5432 + - DB_PASSWORD=fixme-postgres-password + - DEFAULT_FROM_EMAIL=healthchecks.io@healthchecks.io + - EMAIL_HOST=fixme-smtp-server.example.org + - EMAIL_HOST_USER=fixme-smtp-username + - EMAIL_HOST_PASSWORD=fixme-smtp-password + - SECRET_KEY=fixme-secret-key + - SITE_ROOT=http://localhost:8000 + ports: + - 8000:8000 + depends_on: + - db + command: bash -c 'while !Configuring Prometheus -

Healthchecks.io supports exporting metrics and check statuses to +

SITE_NAME supports exporting metrics and check statuses to Prometheus, for use with Grafana.

You can generate the metrics export endpoint by going to your project settings and clicking "Create API Keys." You will then see the link to diff --git a/templates/docs/configuring_prometheus.md b/templates/docs/configuring_prometheus.md index cecfa518..b4d3c7ab 100644 --- a/templates/docs/configuring_prometheus.md +++ b/templates/docs/configuring_prometheus.md @@ -1,6 +1,6 @@ # Configuring Prometheus -Healthchecks.io supports exporting metrics and check statuses to +SITE_NAME supports exporting metrics and check statuses to [Prometheus](https://prometheus.io/), for use with [Grafana](https://grafana.com/). You can generate the metrics export endpoint by going to your project settings diff --git a/templates/docs/self_hosted_docker.html b/templates/docs/self_hosted_docker.html new file mode 100644 index 00000000..8d23e12a --- /dev/null +++ b/templates/docs/self_hosted_docker.html @@ -0,0 +1,34 @@ +

Running with Docker

+

In the Healthchecks source code, /docker/ directory, +you can find a sample configuration for running the project with +Docker and Docker Compose.

+

Note: The Docker configuration is a recent addition, and, for the time being, +should be considered highly experimental.

+

Note: For the sake of simplicity, the sample configuration starts a single database +node and a single web server node, both on the same host. It also does not handle SSL +termination. If you plan to expose it to the public internet, make sure you put a +SSL-terminating load balancer or reverse proxy in front of it.

+

Getting Started

+ \ No newline at end of file diff --git a/templates/docs/self_hosted_docker.md b/templates/docs/self_hosted_docker.md new file mode 100644 index 00000000..ce82e637 --- /dev/null +++ b/templates/docs/self_hosted_docker.md @@ -0,0 +1,31 @@ +# Running with Docker + +In the Healthchecks source code, [/docker/ directory](https://github.com/healthchecks/healthchecks/tree/master/docker), +you can find a sample configuration for running the project with +[Docker](https://www.docker.com) and [Docker Compose](https://docs.docker.com/compose/). + +**Note: The Docker configuration is a recent addition, and, for the time being, +should be considered highly experimental**. + +Note: For the sake of simplicity, the sample configuration starts a single database +node and a single web server node, both on the same host. It also does not handle SSL +termination. If you plan to expose it to the public internet, make sure you put a +SSL-terminating load balancer or reverse proxy in front of it. + +## Getting Started + +* Grab the Healthchecks source code + [from the Github repository](https://github.com/healthchecks/healthchecks). +* Edit the `/docker/docker-compose.yml` file; add your SMTP credentials + and any other needed [environment variables](../self_hosted_configuration/). +* Create and start containers: + + $ cd docker + $ docker-compose up + +* Create a superuser: + + $ docker-compose run web /opt/healthchecks/manage.py createsuperuser + +* Open [http://localhost:8000](http://localhost:8000) in your browser and log in with + the credentials from the previous step. diff --git a/templates/front/base_docs.html b/templates/front/base_docs.html index bc25d35e..ffdffebe 100644 --- a/templates/front/base_docs.html +++ b/templates/front/base_docs.html @@ -45,6 +45,7 @@ {% include "front/docs_nav_item.html" with slug="self_hosted" title="Overview" %} {% include "front/docs_nav_item.html" with slug="self_hosted_configuration" title="Configuration" %} + {% include "front/docs_nav_item.html" with slug="self_hosted_docker" title="Running with Docker" %}
  • Cron syntax cheatsheet