diff --git a/docker/.env b/docker/.env index 2548439c7..b6885ae56 100644 --- a/docker/.env +++ b/docker/.env @@ -11,6 +11,7 @@ SHINKEN_UI_GRAPHITE_GIT_REPO=mohierf/mod-ui-graphite ALIGNAK_DATADIR=./data/alignak # In the container +ALIGNAK_SHARE_DIR=/alignak ALIGNAK_LOG_DIR=/alignak/log ALIGNAK_RUN_DIR=/alignak/run ALIGNAK_ETC_DIR=/alignak/etc diff --git a/docker/.env.dist b/docker/.env.dist new file mode 100644 index 000000000..76c4b87c7 --- /dev/null +++ b/docker/.env.dist @@ -0,0 +1,83 @@ +PYTHON_BASE_VERSION=3.6 +ALIGNAK_IMAGE_TAG=0.0.1 + +DOCKER_REPOSITORY=alignak +DOCKER_SERVICE=alignak +DOCKER_SERVICE_UI=alignak-ui + +ALIGNAK_GIT_REPO=Alignak-monitoring/alignak +SHINKEN_WEBUI_GIT_REPO=mohierf/mod-webui +SHINKEN_UI_GRAPHITE_GIT_REPO=mohierf/mod-ui-graphite + +# Shared with the host +ALIGNAK_DATADIR=./data/alignak + +# In the container +ALIGNAK_SHARE_DIR=/alignak +ALIGNAK_LOG_DIR=/alignak/log +ALIGNAK_RUN_DIR=/alignak/run +ALIGNAK_ETC_DIR=/alignak/etc +ALIGNAK_CONFIGURATION_FILE=/alignak/etc/alignak.ini + +#################### +# Alignak configuration +#################### +# Use Shinken Web UI as the Alignak UI +ALIGNAK_SHINKEN_UI=yes +SHINKEN_UI_DEBUG=yes + +# Alignak retention module configuration +# Override module configuration file! +ALIGNAK_RETENTION_DIR=/alignak/retention + +# Alignak logging more information +#ALIGNAK_LOG_ACTIONS=WARNING +#ALIGNAK_LOG_ALERTS=WARNING +#ALIGNAK_LOG_CHECKS=1 +#ALIGNAK_LOG_ACTIVITY=3600 + +#################### +# Graphite configuration +#################### +GRAPHITE_DATADIR=./data/graphite + +# Tuning - much more is available, see: https://github.com/graphite-project/docker-graphite-statsd +GRAPHITE_WSGI_PROCESSES=4 +GRAPHITE_WSGI_THREADS=2 +GRAPHITE_WSGI_REQUEST_TIMEOUT=65 +GRAPHITE_WSGI_MAX_REQUESTS=1000 +GRAPHITE_WSGI_REQUEST_LINE=0 + +# Log +GRAPHITE_LOG_ROTATION=true +GRAPHITE_LOG_ROTATION_COUNT=1 +GRAPHITE_LOG_RENDERING_PERFORMANCE=true +GRAPHITE_LOG_CACHE_PERFORMANCE=true + +GRAPHITE_DEBUG=false + +COLLECTD=1 + +#################### +# MongoDB variables +#################### +MONGO_DATADIR=./data/mongodb + +# Create a super-user on first database launch +# Disabled! +MONGO_INITDB_ROOT_USERNAME= +MONGO_INITDB_ROOT_PASSWORD= +# Database selected for startup scripts +MONGO_INITDB_DATABASE=alignak + +#################### +# Mongo express configuration +#################### +ME_CONFIG_MONGODB_SERVER=mongodb +ME_CONFIG_MONGODB_ENABLE_ADMIN=true +# Disabled! +ME_CONFIG_MONGODB_ADMINUSERNAME= +ME_CONFIG_MONGODB_ADMINPASSWORD= +ME_CONFIG_OPTIONS_EDITORTHEME=ambiance +ME_CONFIG_BASICAUTH_USERNAME=admin +ME_CONFIG_BASICAUTH_PASSWORD=admin \ No newline at end of file diff --git a/docker/Makefile b/docker/Makefile index 1101bd3d7..f038330ad 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,18 +1,19 @@ +#!make # Specify a shell SHELL := /bin/bash .PHONY: help # Get the environment variables +$(shell cp .env.dist .env) include .env -ifndef DOCKER_TAG -$(info The image TAG variable (DOCKER_TAG) is missing. Setting a default value!) +ifndef ALIGNAK_IMAGE_TAG +$(error The image TAG variable (ALIGNAK_IMAGE_TAG) is missing.) endif # Default values for the image -PYTHON_VERSION ?= 3.6 -DOCKER_TAG ?= 0.0.0 +PYTHON_BASE_VERSION ?= 3.6 DOCKER_REPOSITORY ?= alignak DOCKER_ALIGNAK_DAEMON ?= alignak DOCKER_ALIGNAK_WEBUI ?= alignak-ui @@ -34,7 +35,7 @@ help: banner # -------------------- banner: ## This help message @echo -e "--------------------" - @echo -e "\x1b[36mImage\x1b[m:$(DOCKER_IMAGE):$(DOCKER_TAG)" | column -c2 -t -s : + @echo -e "\x1b[36mImage\x1b[m:$(DOCKER_IMAGE):$(ALIGNAK_IMAGE_TAG)" | column -c2 -t -s : @echo -e "--------------------" build: banner ## Build the image @@ -68,8 +69,8 @@ check: banner ## Check the Alignak configuration docker-compose run arbiter-master alignak-arbiter -V -e $(ALIGNAK_CONFIGURATION_FILE) push: banner login ## Push the image to the repository - $(info Pushing "$(DOCKER_IMAGE)":"$(DOCKER_TAG)" tagged image.) - @docker push $(DOCKER_IMAGE):$(DOCKER_TAG) + $(info Pushing "$(DOCKER_IMAGE)":"$(ALIGNAK_IMAGE_TAG)" tagged image.) + @docker push $(DOCKER_IMAGE):$(ALIGNAK_IMAGE_TAG) pull: banner ## Pull the image $(info Pulling "$(DOCKER_TAG)" tagged image.) diff --git a/docker/README b/docker/README index c662f5f72..1f04a6e84 100644 --- a/docker/README +++ b/docker/README @@ -1,8 +1,38 @@ # Docker Alignak To be completed... +A GNU makefile exists to help for the most common operations with Alignak Docker images. + +The Makefile includes the *.env* file existing in the current directory. + +Note: If the *.env* file does not exist, running make will copy the default *.env.dist* file to a new *.env* file. + +## Using the makefile + +```bash + + # View all the available targets + doc + make + + # Build the images + make build + # This will build the images according to the values defined in the .env file + + # Clean extra unused images + make clean + + # Push an image to your repository + # Direct + TAG=0.0.1 DOCKER_USER=username DOCKER_PASS=password make push + + export TAG=0.0.1 + export DOCKER_USER=username + export DOCKER_PASS=password + make push +``` ## Build and run +You can also use usual docker-compose to build the Alignak images: ```bash docker-compose build @@ -21,20 +51,6 @@ Check the Alignak configuration: make check ``` -## Using the makefile - -```bash - - # Push an image to your repository - # Direct - TAG=0.0.1 DOCKER_USER=username DOCKER_PASS=password make push - - export TAG=0.0.1 - export DOCKER_USER=username - export DOCKER_PASS=password - make push -``` - ## Metrics and Graphite View https://github.com/graphite-project/docker-graphite-statsd diff --git a/docker/data/alignak/etc/alignak.d/extra-alignak.ini b/docker/data/alignak/etc/alignak.d/extra-alignak.ini index 9654b6162..655272ed0 100755 --- a/docker/data/alignak/etc/alignak.d/extra-alignak.ini +++ b/docker/data/alignak/etc/alignak.d/extra-alignak.ini @@ -1,5 +1,5 @@ [DEFAULT] -_dist=/tmp/alignak +_dist=/alignak _dist_BIN=/usr/local/bin _dist_ETC=%(_dist)s/etc _dist_VAR=%(_dist)s/plugins diff --git a/docker/data/alignak/etc/alignak.ini b/docker/data/alignak/etc/alignak.ini index 385024941..87f1db30a 100755 --- a/docker/data/alignak/etc/alignak.ini +++ b/docker/data/alignak/etc/alignak.ini @@ -71,7 +71,7 @@ bindir=%(_dist_BIN)s ; ---------- ; This is the name used for this configuration ; The only purpose of this variable is to make it easier to search in the system log -config_name=Alignak global configuration +config_name=Alignak configuration ; Alignak instance name ; ---------- @@ -109,8 +109,10 @@ alignak_name=My Alignak ; ---------- ; Python logger configuration file ; Default is to get this file in the same directory as the alignak.ini +;logger_configuration=DEFAULT +; is the same as ;logger_configuration=./alignak-logger.json -; This will set the daemon log file +; This file will configure the daemon log and monitoring events loggers ; -------------------------------------------------------------------- ; -------------------------------------------------------------------- @@ -152,11 +154,20 @@ alignak_name=My Alignak ;idontcareaboutsecurity=0 ; Log file -; The daemon log file is configured according to the Python logger but it is +; The daemon log file is configured according to the Alignak Python logger but it is ; still possible to override this... ;log_filename=%(workdir)s/daemon.log -; Same for the log_level +; Same for the log_level. Default is to use the global log level ;log_level= +; and some other self-explanatory parameters. +; Those parameters and the log_level are not used except if the former log_filename is set. +; log_filename and log_level may be overriden on the daemon command line +;log_rotation_when=midnight +;log_rotation_interval=1 +;log_rotation_count=7 +;log_format[%%(asctime)s] %%(levelname)s: [%%(name)s] %%(message)s +;log_date=%%Y-%%m-%%d %%H:%%M:%%S +# !!! Note that the % sign must be written as %% ; Include the CherryPy daemon HTTP server log in the daemon log file ; This is interesting if you want many many details about the daemons inter-communication @@ -543,6 +554,22 @@ $NRPE_PLUGINS_DIR$=$NAGIOSPLUGINSDIR$ ; --- ; Monitoring events log default configuration ; -------------------------------------------------------------------- +; Log file +; The daemon log file is configured according to the Alignak Python logger but it is +; still possible to override this... +;log_filename=%(workdir)s/daemon.log +; Same for the log_level. Default is to use the global log level +;log_level= +; and some other self-explanatory parameters. +; Those parameters and the log_level are not used except if the former log_filename is set. +; log_filename and log_level may be overriden on the daemon command line +;log_rotation_when=midnight +;log_rotation_interval=1 +;log_rotation_count=365 +;log_format[%%(my_date)s] %%(levelname)s: %%(message)s +;log_date=%%Y-%%m-%%d %%H:%%M:%%S +# !!! Note that the % sign must be written as %% + ; Notifications ;log_notifications=1 @@ -701,3 +728,14 @@ retention_update_interval=60 ;tick_send_broks_to_modules=1 ;tick_get_objects_from_from_queues=1 ;tick_get_latency_average_percentile=10 + + +; -------------------------------------------------------------------- +; Some tuning parameters +; -------------------------------------------------------------------- +; When set, this parameter makes run the configuration clean once the data are +; ready to be prepared for dispatching to the daemons. +; This may be useful to make the running configuration a bit smaller +; Note that some configuration check information will get lost +; (imported from, configuration warnings, ...) +;clean_objects=0 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6b99fea38..67c577d7e 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -4,7 +4,7 @@ services: # Alignak daemons # - arbiter arbiter-master: - image: ${DOCKER_REPOSITORY}/${DOCKER_ALIGNAK_DAEMON}:${DOCKER_TAG} + image: ${DOCKER_REPOSITORY}/${DOCKER_SERVICE}:${ALIGNAK_IMAGE_TAG} build: context: ./image-alignak args: @@ -86,7 +86,7 @@ services: # - broker broker-master: - image: ${DOCKER_REPOSITORY}/${DOCKER_ALIGNAK_WEBUI}:${DOCKER_TAG} + image: ${DOCKER_REPOSITORY}/${DOCKER_SERVICE_UI}:${ALIGNAK_IMAGE_TAG} build: context: image-alignak-ui args: diff --git a/docker/image-alignak-ui/Dockerfile b/docker/image-alignak-ui/Dockerfile index c70b8b5d3..48bd8ec72 100644 --- a/docker/image-alignak-ui/Dockerfile +++ b/docker/image-alignak-ui/Dockerfile @@ -1,6 +1,15 @@ -FROM alignak/alignak:0.0.1 +ARG ALIGNAK_IMAGE_TAG -LABEL maintainer="Frédéric Mohier (frederic.mohier@alignak.net)" +FROM alignak/alignak:${ALIGNAK_IMAGE_TAG} + +ARG ALIGNAK_IMAGE_TAG + +ENV ALIGNAK_IMAGE_TAG $ALIGNAK_IMAGE_TAG + +LABEL maintainer="Frédéric Mohier (frederic.mohier@alignak.net)" \ + alignak.image_type="UI" \ + alignak.image.version=$ALIGNAK_IMAGE_TAG \ + alignak.python.version=$PYTHON_BASE_VERSION ENV DEBIAN_FRONTEND noninteractive diff --git a/docker/image-alignak-ui/supervisord.conf b/docker/image-alignak-ui/supervisord.conf index 6b1322d32..5c854c33a 100644 --- a/docker/image-alignak-ui/supervisord.conf +++ b/docker/image-alignak-ui/supervisord.conf @@ -1,7 +1,18 @@ [supervisord] -nodaemon=true +logfile=/alignak/log/supervisord.log ; supervisord log file +logfile_maxbytes=50MB ; maximum size of logfile before rotation +logfile_backups=10 ; number of backed up logfiles +loglevel=info ; info, debug, warn, trace +pidfile=/alignak/run/supervisord.pid ; pidfile location +nodaemon=true ; do not run supervisord as a daemon +minfds=1024 ; number of startup file descriptors +minprocs=200 ; number of process descriptors +###user=root ; default user +user=alignak + [program:alignak-broker] +user=alignak command=/usr/local/bin/alignak-broker -n broker-master -e %(ENV_ALIGNAK_CONFIGURATION_FILE)s stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 @@ -9,6 +20,7 @@ stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:nginx] +user=alignak command=/usr/sbin/nginx stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/docker/image-alignak/Dockerfile b/docker/image-alignak/Dockerfile index ae51fc667..906966f72 100644 --- a/docker/image-alignak/Dockerfile +++ b/docker/image-alignak/Dockerfile @@ -8,13 +8,11 @@ ARG ALIGNAK_IMAGE_TAG ENV ALIGNAK_IMAGE_TAG $ALIGNAK_IMAGE_TAG ENV PYTHON_BASE_VERSION $PYTHON_BASE_VERSION -LABEL alignak.image.version=$ALIGNAK_IMAGE_TAG \ +LABEL maintainer="Frédéric Mohier (frederic.mohier@alignak.net)" \ + alignak.image_type="Generic" \ + alignak.image.version=$ALIGNAK_IMAGE_TAG \ alignak.python.version=$PYTHON_BASE_VERSION -LABEL maintainer="Frédéric Mohier (frederic.mohier@alignak.net)" - -LABEL alignak.image_type="Generic" - ENV DEBIAN_FRONTEND noninteractive # Force container timezone @@ -64,4 +62,4 @@ RUN chmod 500 /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] # Run the arbiter in check mode for the configuration in the Alignak directory -CMD ["alignak-arbiter", "-V", "-e", "/repos/alignak/etc/alignak.ini" ] +CMD ["alignak-arbiter", "-V", "-e", "/alignak/etc/alignak.ini" ] diff --git a/docker/image-alignak/entrypoint.sh b/docker/image-alignak/entrypoint.sh index c6d996ce7..2056e8b97 100755 --- a/docker/image-alignak/entrypoint.sh +++ b/docker/image-alignak/entrypoint.sh @@ -1,6 +1,10 @@ -#!/usr/bin/env bash +#!/bin/bash -chown $ALIGNAK_USER:$ALIGNAK_GROUP $ALIGNAK_SHARE_DIR +ALIGNAK_SHARE_DIR=${ALIGNAK_SHARE_DIR:-/alignak} +ALIGNAK_USER=${ALIGNAK_USER:-alignak} +ALIGNAK_GROUP=${ALIGNAK_GROUP:-alignak} + +chown -R $ALIGNAK_USER:$ALIGNAK_GROUP $ALIGNAK_SHARE_DIR chmod -R 775 $ALIGNAK_SHARE_DIR echo $@ > /cmd