Files
GateCounter-Dashboard/docker-compose.yaml
Brennen Raimer fa48b3357e PIRgate now logs immediately for better visualization in Grafana
Gatecounter service added
Gatecounter db now initialized by the gatecounter itself courtesy of SQLAlchemy
2019-11-03 13:49:46 -05:00

151 lines
8.1 KiB
YAML

version: '3.7' #specifies the version of the compose-file specification to use. Refer to the compose-file reference for more info https://docs.docker.com/compose/compose-file/
#this section specifies the various services that comprise the project
services:
gatecounter:
build:
context: . #build a custom python container to run the gatecounter script
container_name: gatecounter
privileged: true #enable access to GPIO from Docker Container
volumes:
#make the scripts acessible to the container, read-only
- ${PWD}/gatecounter-scripts:/usr/src/app:ro
labels:
- traefik.enable=false
networks:
- gatecounter
restart: unless-stopped
depends_on:
- gatecounter-db
command:
- "${GATECOUNTER_SCRIPT:?The name of a gatecounter script in the gatecounter-scripts directory is required. Please edit .env and add a value for GATECOUNTER_SCRIPT}"
- "-H"
- "gatecounter-db"
- "-d"
- "${MYSQL_DB_NAME}"
- "-u"
- "${MYSQL_USER}"
- "-p"
- "${MYSQL_USER_PW}"
#this service will be the mysql database that detections will be logged to
gatecounter-db: #how this service will be referenced in this file
image: yobasystems/alpine-mariadb:armhf
container_name: gatecounter-db #how docker itself will refer to this service and the hostname it will be accessible from other services, defaults to the service name
environment: #set environment variables for this service. These will initialize a database
#these environment variables will specify how the gate counter script will connect to the db to record data
MYSQL_DATABASE: ${MYSQL_DB_NAME:-gatecounter}
MYSQL_USER: ${MYSQL_USER:-gatecounter}
MYSQL_PASSWORD: ${MYSQL_USER_PW:?a non-admin database password is requred. Please edit .env with this value}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PW:?an admin database password is requred. Please edit .env with this value}
TZ: ${TZ:-America/New_York}
volumes: #specify where data to be peristed will be stored on host and where it resides within the service
- gatecounter-db:/var/lib/mysql #left of the : is the name of a docker volume to store data in, right of it is where it is located in the service
restart: unless-stopped #keep this service running unless told explicitly to stop
networks: #virtual network for services to connect to each other through. necessary to resolve their container_name to their virtual ip address
- gatecounter
labels: #can be used to communicate info about this service to other services
- traefik.enable=false #tells traefik reverse proxy to ignore this container, do not proxy requests to it
healthcheck: #this command is run periodically so docker can know whether or not this service is actually accessible. Completely optional.
test: ["CMD-SHELL", "mysqladmin -h $$HOSTNAME -u ${MYSQL_USER:-gatecounter} -h 127.0.0.1 --password=${MYSQL_USER_PW:?a non-admin database password is requred. Please edit .env with this value} ping || exit 1"]
interval: 30s
timeout: 10s
retries: 5
expose:
- "3306"
grafana:
image: grafana/grafana:6.4.3
container_name: grafana #redundant, would have defaulted to the service name anyway
restart: unless-stopped
volumes:
- ./configs/grafana.ini:/etc/grafana/grafana.ini #maps grafana.ini in this directory into the container
- grafana_data:/var/lib/grafana
- grafana_home:/usr/share/grafana
- grafana_logs:/var/log/grafana
- grafana_plugins:/var/lib/grafana/plugins
- grafana_provisioning:/etc/grafana/provisioning
labels:
- traefik.enable=true #enable forwarding of requests to this container
- traefik.http.routers.grafana-http.rule=Host(`${GRAFANA_DOMAIN_NAME}`) #when a request is received for this domain, forward the request to this container...
- traefik.http.routers.grafana-http.entrypoints=http
- traefik.http.routers.grafana-http.middlewares=https-only #redirect all http requests to https
- traefik.http.routers.grafana-https.entrypoints=https
- traefik.http.routers.grafana-https.tls=true
- traefik.http.services.grafana.loadbalancer.server.port=3000 #on this port...
expose:
- "3000" #makes this port accessible to other containers on the same network, but not availble directly on the host system
depends_on: #specifies which containers must be up and running before this one can be started
- reverse-proxy
- gatecounter-db
environment:
GF_SERVER_ROOT_URL: https://${GRAFANA_DOMAIN_NAME}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PW:?an admin password is requred for Grafana. Please edit .env with this value}
GF_INSTALL_PLUGINS: ${GRAFANA_PLUGINS}
networks:
- gatecounter
grafana-db: #how this service will be referenced in this file
image: yobasystems/alpine-mariadb:armhf
container_name: grafana-db #how docker itself will refer to this service and the hostname it will be accessible from other services, defaults to the service name
environment: #set environment variables for this service. These will initialize a database #these environment variables will specify how the gate counter script will connect to the db to record data
MYSQL_DATABASE: ${GRAFANA_DB_NAME:-grafana}
MYSQL_ROOT_PASSWORD: ${GRAFANA_DB_ROOT_PW:?an admin database password is requred for grafana database. Please edit .env with this value}
TZ: ${TZ:-America/New_York}
volumes: #specify where data to be peristed will be stored on host and where it resides within the service
- grafana-db:/var/lib/mysql #left of the : is the name of a docker volume to store data in, right of it is where it is located in the service
restart: unless-stopped #keep this service running unless told explicitly to stop
networks: #virtual network for services to connect to each other through. necessary to resolve their container_name to their virtual ip address
- gatecounter
labels: #can be used to communicate info about this service to other services
- traefik.enable=false #tells traefik reverse proxy to ignore this container, do not proxy requests to it
healthcheck: #this command is run periodically so docker can know whether or not this service is actually accessible. Completely optional.
test: ["CMD-SHELL", "mysqladmin -u $$MYSQL_USER --password=$$MYSQL_PASSWORD ping || exit 1"]
interval: 30s
timeout: 10s
retries: 5
expose:
- "3306" #this database only needs to be accessible internally to grafana
reverse-proxy:
image: traefik:latest
container_name: traefik
command:
- "--api=false"
- "--entryPoints.http.address=:80"
- "--entryPoints.https.address=:443"
- "--providers.docker=true"
- "--accesslog=true"
- "--log=true"
- "--log.level=INFO"
- "--providers.file.directory=/etc/traefik/custom/"
labels:
- "com.ouroboros.enable=true" #enables watchtower for auto updates
- "traefik.http.middlewares.https-only.redirectscheme.scheme=https"
- "traefik.http.middlewares.https-only.redirectscheme.permanent=true"
restart: unless-stopped #Docker will automatically restart this container unless you intentionally stopped it
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/var/run/docker.sock #allows traefik to monitor for changes and to read labels
- ./certs/:/certs/:ro
- ./configs/traefik:/etc/traefik/custom:ro
networks:
- gatecounter
#this section specifies where data will be persisted between starts/stops/recreates, etc. I will be using named docker volumes because that is the most portable
#way to do this (you don't have to know about the directory structure of where you're going to run it), but you can map host system directories into your containers
#if you so choose. You can also specify options for them here.
volumes:
gatecounter-db:
grafana-db:
grafana_data:
grafana_home:
grafana_logs:
grafana_plugins:
grafana_provisioning:
#this section specifies virtual networks that will be used and any options you want to set for them
networks:
gatecounter: