Skip to content

Commit

Permalink
Merge branch 'release_2.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 28, 2020
2 parents afa8c99 + df43404 commit d7948a1
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 64 deletions.
9 changes: 4 additions & 5 deletions .infrastructure/arm.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM balenalib/armv7hf-alpine:3.12

RUN [ "cross-build-start" ]
RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client make git supervisor tzdata \
RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client make git tzdata \
sshpass openssh-client
RUN [ "cross-build-end" ]

ADD . /infracheck
ADD .git /infracheck/

ENV CHECK_INTERVAL="*/1 * * * *" \
WAIT_TIME=0\
LAZY=false
ENV REFRESH_TIME="120" \
WAIT_TIME="0" \
CHECK_TIMEOUT="10"

RUN [ "cross-build-start" ]
RUN cd /infracheck \
Expand All @@ -34,7 +34,6 @@ RUN cd /infracheck \
RUN [ "cross-build-end" ]

ADD /.infrastructure/entrypoint.sh /entrypoint.sh
ADD /.infrastructure/supervisord.conf /etc/supervisord.conf

RUN [ "cross-build-start" ]
RUN chmod +x /entrypoint.sh
Expand Down
12 changes: 3 additions & 9 deletions .infrastructure/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@ prepare_entrypoint () {
fi

if [[ ${WAIT_TIME} ]]; then
ARGS="${ARGS} --wait${WAIT_TIME} "
ARGS="${ARGS} --wait=${WAIT_TIME} "
fi

# allow to pass custom arguments from docker run command
echo "#!/bin/bash" > /entrypoint.cmd.sh
echo "infracheck --server-port 8000 ${ARGS} --directory=/data --db-path=/database/db.sqlite3 $@" >> /entrypoint.cmd.sh

cat /entrypoint.cmd.sh
chmod +x /entrypoint.cmd.sh
echo "infracheck --server-port 8000 ${ARGS} --directory=/data --db-path=/database/db.sqlite3 $@"
}

prepare_data_directory
prepare_entrypoint "$@"

exec supervisord -c /etc/supervisord.conf
exec $(prepare_entrypoint "$@")
19 changes: 0 additions & 19 deletions .infrastructure/supervisord.conf

This file was deleted.

9 changes: 4 additions & 5 deletions .infrastructure/x86_64.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM alpine:3.12

RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client git supervisor tzdata \
RUN apk --update add python3 bash perl curl wget grep sed docker sudo mysql-client postgresql-client git tzdata \
sshpass openssh-client
ADD . /infracheck
ADD .git /infracheck/
ADD .infrastructure /infracheck/

ENV CHECK_INTERVAL="*/1 * * * *" \
WAIT_TIME=0\
LAZY=false
ENV REFRESH_TIME="120" \
WAIT_TIME="0" \
CHECK_TIMEOUT="10"

RUN cd /infracheck \
# install as a package
Expand All @@ -30,7 +30,6 @@ RUN cd /infracheck \
&& apk del BUILD_DEPS

ADD /.infrastructure/entrypoint.sh /entrypoint.sh
ADD /.infrastructure/supervisord.conf /etc/supervisord.conf
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
32 changes: 11 additions & 21 deletions docs/source/cache.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
Cache and freshness
===================

It can be harmful to the server to run all checks on each HTTP endpoint call, so a cronjob in background is writing results, and HTTP endpoint is reading.
It can be harmful to the server to run all checks on each HTTP endpoint call, so the application is running them periodically every X seconds specified by **--refresh-time** switch or **REFRESH_TIME** environment variable (in docker)

How often really the checks are performing depends on your configuration, how often you execute **infracheck --force**
Refresh time
------------

--force
-------
If you use an official docker image, then you can set an environment variable.

The *--force* parameter means that the application will write checks results to a cache.
Example: check once a day (good for domains whois check).

When this flag is not specified, then application will read the data from the cache.
.. code:: bash
Docker
------
REFRESH_TIME=86400
If you use an official docker image, then you can set CHECK_INTERVAL to a crontab-like syntax interval eg. **CHECK_INTERVAL=00 23 * * *** to check once a day (good for domains whois check).
From CLI you can set **--refresh-time=86400**

Limits
------
Wait time
---------

Some checks could call external APIs, those can have limits. A good example is a *domain-expiration* check which is using whois.
It is recommended to run a separate infracheck instance with less frequent checking, eg. once a day - see CHECK_INTERVAL in docker, and crontab in standalone installation.

You can also use `--wait` switch to set waiting in seconds between single checks (in docker it is `WAIT_TIME` variable)

--lazy
------

When running a ex. HTTP endpoint without `--force`, then application is only reading results of previously executed checks that are usually executed in background using cron.
**Without lazy** the checks that were not executed yet will be showing "Not ready yet" and a **status equals to false**.
If you really need to avoid such case, **then you can allow running a check on-demand by enabling** `--lazy` **flag** (LAZY=true in docker).
Set **--wait=60** to for example wait 60 seconds before each check - where check is a single entry on the list of checks.
8 changes: 4 additions & 4 deletions docs/source/first-steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ The image will by default expose a HTTP endpoint.
# create directory structure that will be present in "/data" inside container (see one of previous steps about the structure)
mkdir checks configured
sudo docker run --name infracheck -p 8000:8000 -v $(pwd):/data -d --rm quay.io/riotkit/infracheck:v1.9.1-x86_64 \
sudo docker run --name infracheck -p 8000:8000 -v $(pwd):/data -d --rm quay.io/riotkit/infracheck:v2.0-x86_64 \
--directory=/data --server-path-prefix=/your-secret-code-there
# now test it
curl http://localhost:8000/your-secret-code-there/
List of supported environment variables:
**List of supported environment variables:**

- REFRESH_TIME=120
- CHECK_TIMEOUT=120
Expand All @@ -123,7 +123,7 @@ List of supported environment variables:
infracheck --directory=/your-project-directory-path-there --no-server
# run the application with webserver and background worker
infracheck --directory=/your-project-directory-path-there --server-port=7422 --refresh-time=120 --log-level=info
infracheck --directory=/your-project-directory-path-there --server-port=8000 --refresh-time=120 --log-level=info
**Using PIP**
Expand All @@ -136,7 +136,7 @@ List of supported environment variables:
infracheck --directory=/your-project-directory-path-there --no-server
# run the application with webserver and background worker
infracheck --directory=/your-project-directory-path-there --server-port=7422 --refresh-time=120 --log-level=info
infracheck --directory=/your-project-directory-path-there --server-port=8000 --refresh-time=120 --log-level=info
Advanced
Expand Down
37 changes: 37 additions & 0 deletions docs/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ Parameters:
- expect_keyword
- not_expect_keyword

rkd://
------

Infracheck can execute RiotKit-Do tasks. RKD is a task executor, similar to Makefile or Gradle.
It's essential feature is a possibility to load tasks from PyPI (Python packages).


Using RKD you can write a Python class, version and release it to PyPI with a list of dependencies, and install in any place
with PIP. A packaged task can require extra dependencies you do not want always to install eg. MySQL, PostgreSQL, Redis or other clients
you want to selectively install on your Infracheck instances.

More information on how to write RKD tasks: `in RiotKit-Do's documentation <https://riotkit-do.readthedocs.io/en/latest/usage/developing-tasks.html#option-2-for-python-developers-task-as-a-class>`_


.. code:: json
{
"type": "rkd://rkd.standardlib.shell:sh",
"input": {
"-c": "ps aux |grep X11"
}
}
.. code:: json
{
"type": "rkd://my_rkd_check:mysql:temporary-table-size-check",
"input": {
"--max": "100000",
"--host: "localhost",
"--port": 3306,
"--user": "infracheck",
"--password": "${TEMP_TABLE_SIZE_CHECK_PASSWORD}"
}
}
dir-present
-----------

Expand Down
2 changes: 1 addition & 1 deletion infracheck/checks/domain-expiration
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Check if the domain is close to expiration date or if it is already expired.
**Notice: Multiple usage of this check can cause a "request limit exceeded" error to happen**
*Suggestion: If you check multiple domains, then separate domains checking from regular health checks and set CHECK_INTERVAL (docker) to once a day, and WAIT_TIME=300 for non-docker installations - in crontab set a check with --force once a day*
*Suggestion: If you check multiple domains, then separate domains checking from regular health checks and set REFRESH_TIME (docker) to once a day, and WAIT_TIME=300 for non-docker installations - in crontab set a check with --force once a day*
Parameters:
Expand Down

0 comments on commit d7948a1

Please sign in to comment.