Skip to content

Commit

Permalink
Added docs, fixed ARM build
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Mar 30, 2019
1 parent b9a8be4 commit ef2307a
Show file tree
Hide file tree
Showing 23 changed files with 858 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Dockerfile
/armhf.Dockerfile
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGES
=======

* Added coverage submission
* Added MySQL replication check
* Added MySQL and PostgreSQL clients to the container
* Better tests coverage for controller and checkers
* Travis: Clean up, not supporting Python 3.4 anymore
* Fixed: Paths with non-project structure were also marked as valid
* Properly marking now the global status, so it would be possible to check it by the monitoring
* Improved "http" check, so it is now following redirections and extra failing on non 200 pages
* Playing with travis build
* Fixed travis build
* Fixed travis build
* Adjusting travis build
Expand Down
20 changes: 13 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
FROM alpine:3.8

RUN apk --update add python3 py3-tornado py3-argparse bash perl curl wget grep sed docker sudo mysql-client postgresql-client
ADD ./app/ /app
ADD ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client make git
ADD . /infracheck
ADD .git /infracheck/

# tests
RUN set -x && cd /app && ./test.sh
RUN cd /infracheck \
&& git remote remove origin || true \
&& git remote add origin https://github.com/riotkit-org/infracheck.git \
&& make install \
&& make unit_test \
&& set -x && cd /infracheck/app && ./functional-test.sh \
&& rm -rf /infracheck/.git /infracheck/example /infracheck/tests \
&& rm -rf /var/cache/apk/* \
&& chmod +x /infracheck/entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/infracheck/entrypoint.sh"]
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ help:

all: build build_arm install unit_test run

build:
## Build docker image
build_image:
sudo docker build . -t wolnosciowiec/infracheck

build_arm:
## Build image for ARM/ARMHF
build_image_arm:
sudo docker build -f ./armhf.Dockerfile . -t wolnosciowiec/infracheck:armhf

## Run (for testing)
run:
sudo docker kill infracheck || true
sudo docker run --name infracheck -p 8000:8000 -t --rm wolnosciowiec/infracheck
Expand All @@ -40,6 +43,10 @@ run:
build_package:
${PY_BIN} ./setup.py build

## Build documentation
build_docs:
cd ./docs && make html

## Install
install: build_package
${PIP} install -r ./requirements.txt
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
InfraCheck
==========

[![Build Status](https://travis-ci.org/riotkit-org/infracheck.svg?branch=master)](https://travis-ci.org/riotkit-org/infracheck)
[![codecov](https://codecov.io/gh/riotkit-org/infracheck/branch/master/graph/badge.svg)](https://codecov.io/gh/riotkit-org/infracheck)

Health check system designed to be easy to extend by not enforcing the programming language.
A single health check unit (let we call it later just 'check') can be written even in BASH.


Dictionary
----------

- `check` - a script that is checking something
- `configuration` - your definition how to use a `check` eg. "type": http + params what is the URL, you can define multiple configurations for single check
- `template` - working example of `configuration`
- `script` - a script that is checking something
- `check` - your definition (input arguments) how to use a `check` eg. "type": http + params what is the URL, you can define multiple configurations for single check


How it works?
-------------
1. Write a `check` in any programming language, take environment variables as input.
2. Create a json `template` that will contain a working configuration example for your `check`.
3. You can skip 1 and 2 if you want to use already created checks
4. Create a `configuration` to use a `check` in *specified context
Guide to "check" creation
-------------------------
1. Write a `script` in any programming language, take environment variables as input (skip this step if you want to use existing pre-defined scripts)
2. Create a json `check` that will contain a working configuration example for your `script`.

Running
-------
Expand All @@ -30,7 +30,7 @@ See a working example in the `./example` directory.
python ./infracheck/bin.py --help
```

Docker-compose:
docker or docker-compose:

```yaml
version: '2'
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions app/infracheck/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _combine_project_dirs(project_dir: str) -> list:

# official docker container
'/app',
'/data',

# current directory
os.getcwd(),
Expand Down
2 changes: 1 addition & 1 deletion app/infracheck/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MainHandler(tornado.web.RequestHandler): # pragma: no cover

def get(self):
result = self.app.perform_checks()
self.set_status(500 if not result['status'] else 200)
self.set_status(500 if not result['global_status'] else 200)
self.add_header('Content-Type', 'application/json')
self.write(
json.dumps(result, sort_keys=True, indent=4, separators=(',', ': '))
Expand Down
31 changes: 18 additions & 13 deletions armhf.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
FROM balenalib/armv7hf-debian:buster

ADD ./app/ /app
ADD ./requirements.txt /app/
ADD ./entrypoint.sh /entrypoint.sh

RUN [ "cross-build-start" ]

RUN apt-get update \
&& apt-get install python3 python3-pip bash perl curl wget grep sed docker.io sudo mariadb-client netcat ca-certificates openssl \
&& apt-get clean \
&& pip3 install setuptools wheel --upgrade \
&& pip3 install -r /app/requirements.txt \
&& chmod +x /entrypoint.sh
&& apt-get -y install python3 python3-pip bash perl curl wget grep sed docker.io \
sudo mariadb-client postgresql-client netcat ca-certificates \
git openssl make python3-setuptools \
&& apt-get clean
RUN [ "cross-build-end" ]

# tests
RUN set -x && cd /app && ./test.sh
ADD . /infracheck
ADD .git /infracheck/

RUN [ "cross-build-start" ]
RUN cd /infracheck \
&& git remote remove origin || true \
&& git remote add origin https://github.com/riotkit-org/infracheck.git \
&& make install \
&& make unit_test \
&& set -x && cd /infracheck/app && ./functional-test.sh \
&& rm -rf /infracheck/.git /infracheck/example /infracheck/tests \
&& rm -rf /var/cache/apk/* \
&& chmod +x /infracheck/entrypoint.sh
RUN [ "cross-build-end" ]

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/infracheck/entrypoint.sh"]
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sphinx-glpi-theme
Empty file added docs/source/_static/.gitkeep
Empty file.
Binary file added docs/source/_static/quick-start.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added docs/source/_templates/.gitkeep
Empty file.
101 changes: 101 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
project = 'Infra Check'
copyright = '2019, RiotKit Team'
author = 'Wesolowski'

version = ''
release = '2'

extensions = [
'sphinx.ext.todo',
'sphinx.ext.imgmath',
'sphinx.ext.githubpages',
]

templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
language = None
exclude_patterns = []
pygments_style = None

import sphinx_glpi_theme
html_theme = 'glpi'
html_theme_path = sphinx_glpi_theme.get_html_themes_path()

html_static_path = ['_static']
htmlhelp_basename = 'InfraCheckdoc'


latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'InfraCheck.tex', 'Infra Check Documentation',
'Wolnosciowiec Team', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'infracheck', 'Infra Check Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'InfraCheck', 'Infra Check Documentation',
author, 'InfraCheck', 'One line description of project.',
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------

# -- Options for todo extension ----------------------------------------------

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
25 changes: 25 additions & 0 deletions docs/source/custom-scripts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Writing custom checks
=====================

Infracheck provides very basic scripts for health checking, you may probably want to write your own.
It's really simple.

1. "check" scripts are in **"checks" directory** of your project structure, here you can add a **new check script**
2. Your script needs to take **uppercase environment variables as input**
3. It is considered a good practice to validate environment variables presence in scripts
4. Your script needs to return a valid exit code when:
- Any of environment variables is missing or has invalid value
- The check fails
- The check success

That's all!

A few examples:

.. literalinclude:: ../../app/checks/dir-present
:language: bash
:linenos:

.. literalinclude:: ../../app/checks/replication-running
:language: bash
:linenos:

0 comments on commit ef2307a

Please sign in to comment.