Skip to content

Commit

Permalink
#9, #10: Update docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 19, 2020
1 parent 57c5b8f commit 496361c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
28 changes: 11 additions & 17 deletions .infrastructure/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash

# shellcheck disable=SC2001
CHECK_INTERVAL=$(echo "${CHECK_INTERVAL}" | sed "s/\"//g")

get_common_args () {
echo " --directory=/data --db-path=/database/db.sqlite3 "
}
Expand All @@ -17,34 +15,30 @@ prepare_data_directory () {
touch /database/db.sqlite3
}

prepare_crontab () {
# depending on operating system, create an entrypoint for cron
echo "#!/bin/bash" > /entrypoint.cron.sh
echo "crond -d 2 -f" >> /entrypoint.cron.sh

# check interval can be configured using environment variables
echo "${CHECK_INTERVAL} infracheck --force --wait=${WAIT_TIME} $(get_common_args) " > /etc/crontabs/root

chmod +x /entrypoint.cron.sh
}

prepare_entrypoint () {
ARGS=""

if [[ ${LAZY} == "true" ]] || [[ ${LAZY} == "1" ]]; then
ARGS="${ARGS} --lazy "
if [[ ${REFRESH_TIME} ]]; then
ARGS="${ARGS} --refresh-time=${REFRESH_TIME} "
fi

if [[ ${CHECK_TIMEOUT} ]]; then
ARGS="${ARGS} --timeout=${CHECK_TIMEOUT} "
fi

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

# allow to pass custom arguments from docker run command
echo "#!/bin/bash" > /entrypoint.cmd.sh
echo "infracheck --server --server-port 8000 ${ARGS} $(get_common_args) $@" >> /entrypoint.cmd.sh
echo "infracheck --server-port 8000 ${ARGS} $(get_common_args) $@" >> /entrypoint.cmd.sh

cat /entrypoint.cmd.sh
chmod +x /entrypoint.cmd.sh
}

prepare_data_directory
prepare_crontab
prepare_entrypoint "$@"

exec supervisord -c /etc/supervisord.conf
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CHANGES
=======

* #9, #10: Logic extraction from controller into more layers, added model, using pickle instead of json in database cache, the application now is working in two threads - one is server, second is background worker (replaces crontab calls)
* #8: Fix issue with missing "msgpack"
* #8: Add missing package "msgpack"
* #8: Add hashbang
Expand Down
24 changes: 12 additions & 12 deletions docs/source/first-steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ The image will by default expose a HTTP endpoint.
List of supported environment variables:

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

**Without Docker**

Expand All @@ -120,13 +120,11 @@ List of supported environment variables:
rkd :install
# run checks in the shell
infracheck --directory=/your-project-directory-path-there
infracheck --directory=/your-project-directory-path-there --no-server
# run a webserver
infracheck --directory=/your-project-directory-path-there --server --server-port=7422 --lazy
# run the application with webserver and background worker
infracheck --directory=/your-project-directory-path-there --server-port=7422 --refresh-time=120 --log-level=info
# set up a scheduled checking
echo "*/1 * * * * infracheck --directory=/your-project-directory-path-there --force" >> /etc/crontabs/root
**Using PIP**

Expand All @@ -135,11 +133,13 @@ List of supported environment variables:
sudo pip install infracheck
# run checks in the shell
infracheck --directory=/your-project-directory-path-there
infracheck --directory=/your-project-directory-path-there --no-server
# run a webserver
infracheck --directory=/your-project-directory-path-there --server --server-port=7422
# run the application with webserver and background worker
infracheck --directory=/your-project-directory-path-there --server-port=7422 --refresh-time=120 --log-level=info
# set up a scheduled checking
echo "*/1 * * * * infracheck --directory=/your-project-directory-path-there --force" >> /etc/crontabs/root
Advanced
--------

**Setting timeout per check:** Set :code:`INFRACHECK_TIMEOUT` environment variable in json file to adjust timeout for given check.
3 changes: 2 additions & 1 deletion infracheck/infracheck/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def main():
'--log-level', '-l',
help='Logging level name - debug, info, warning, error, fatal. Defaults to "info"',
type=LogLevel,
choices=list(LogLevel)
choices=list(LogLevel),
default='info'
)

parsed = parser.parse_args()
Expand Down

0 comments on commit 496361c

Please sign in to comment.