refactor to use Docker Compose

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-12-07 13:11:09 +01:00
parent 74f8605b28
commit 935860d435
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
8 changed files with 72 additions and 51 deletions

View File

@ -30,6 +30,8 @@ You can manage existing alerts by using the `amtool` on any of the hosts running
> amtool alert
Alertname Starts At Summary
Test_Alert 2018-07-06 18:30:18 UTC This is a testing alert!
```
```
> amtool silence
ID Matchers Starts At Ends At Updated At Created By Comment
9635b573-5177-4601-a3b0-ac6a25d0a4ef alertname=InstanceDown 2018-07-06 12:37:04 UTC 2018-07-06 14:36:05 UTC 2018-07-06 12:37:04 UTC jakubgs test

View File

@ -1,25 +1,30 @@
---
alertmanager_service_name: 'alertmanager'
alertmanager_service_path: '/docker/{{ alertmanager_service_name }}'
alertmanager_compose_file: '{{ alertmanager_service_path }}/docker-compose.yml'
# Public Domain
alertmanager_domain: ~
alertmanager_url: 'https://{{ alertmanager_domain | mandatory }}/'
alertmanager_admin_email: ~
# Container
alertmanager_cont_tag: 'v0.21.0'
alertmanager_cont_image: 'quay.io/prometheus/alertmanager:{{ alertmanager_cont_tag }}'
alertmanager_cont_name: 'alertmanager'
alertmanager_cont_vol: '/docker/{{ alertmanager_cont_name }}'
alertmanager_cont_log_lvl: info
alertmanager_cont_log_lvl: 'info'
# port used for the web ui
# Port used for the web ui
alertmanager_webui_port: 9093
# port used for clustering AlertManager peers
# Port used for clustering AlertManager peers
alertmanager_cluster_port: 9094
# SMTP
alertmanager_smtp_host: ~
alertmanager_smtp_port: ~
alertmanager_smtp_from: ~
alertmanager_smtp_user: ~
alertmanager_smtp_pass: ~
alertmanager_domain: ~
alertmanager_url: 'https://{{ alertmanager_domain | mandatory }}/'
alertmanager_admin_email: ~
# Route configuration
alertmanager_group_by: ['alertname', 'cluster']
alertmanager_group_wait: '30s'
@ -37,6 +42,6 @@ alertmanager_victorops_state_message: '{% raw %}Alert: {{ .CommonLabels.alertnam
consul_catalog_url: 'http://localhost:8500/v1/catalog'
# Generic container options
cont_state: started
cont_recreate: false
cont_restart: false
compose_recreate: 'smart'
compose_state: 'present'
compose_restart: false

View File

@ -1,22 +1,22 @@
---
- name: Create container directories
file:
path: '{{ alertmanager_cont_vol }}/{{ item }}'
path: '{{ alertmanager_service_path }}/{{ item }}'
state: 'directory'
owner: 'dockremap'
group: 'docker'
recurse: true
with_items:
- data
- conf
- 'data'
- 'conf'
- name: Create config files
template:
src: '{{ item }}.j2'
dest: '{{ alertmanager_cont_vol }}/conf/{{ item }}'
dest: '{{ alertmanager_service_path }}/conf/{{ item }}'
owner: 'dockremap'
group: 'docker'
register: alertmanager_cont_config
register: alertmanager_config
with_items:
- 'alertmanager.yml'
- 'amtool.yml'

View File

@ -2,9 +2,9 @@
- name: Create Consul service definition
include_role: name=consul-service
vars:
consul_config_name: '{{ alertmanager_cont_name }}'
consul_config_name: '{{ alertmanager_service_name }}'
consul_services:
- name: '{{ alertmanager_cont_name }}'
- name: '{{ alertmanager_service_name }}'
tags: ['metrics', 'alertmanager']
port: '{{ alertmanager_webui_port }}'
address: '{{ ansible_local.tinc.vpn_ip }}'

View File

@ -1,29 +1,17 @@
---
- name: Start container
docker_container:
name: '{{ alertmanager_cont_name }}'
image: '{{ alertmanager_cont_image }}'
user: root
- name: Create compose file
template:
src: 'docker-compose.yml.j2'
dest: '{{ alertmanager_compose_file }}'
owner: 'dockremap'
group: 'docker'
mode: 0644
- name: Create containers
docker_compose:
project_src: '{{ alertmanager_service_path }}'
pull: true
restart_policy: always
state: '{{ cont_state }}'
recreate: '{{ cont_recreate }}'
restart: '{{ alertmanager_cont_config.changed | default(cont_restart) }}'
ports:
- '0.0.0.0:{{ alertmanager_cluster_port }}:{{ alertmanager_cluster_port }}'
- '0.0.0.0:{{ alertmanager_webui_port }}:{{ alertmanager_webui_port }}'
volumes:
- '{{ alertmanager_cont_vol }}/conf/alertmanager.yml:/etc/alertmanager.yml:ro'
- '{{ alertmanager_cont_vol }}/conf/amtool.yml:/etc/amtool/config.yml:ro'
- '{{ alertmanager_cont_vol }}/data:/data'
- '/certs:/certs'
command: |
--storage.path=/data
--log.level={{ alertmanager_cont_log_lvl }}
--config.file=/etc/alertmanager.yml
--web.external-url={{ alertmanager_url }}
--cluster.advertise-address="{{ ansible_local.tinc.vpn_ip }}:{{ alertmanager_cluster_port }}"
--cluster.listen-address="0.0.0.0:{{ alertmanager_cluster_port }}"
{% for peer in cluster_peers %}
--cluster.peer={{ peer }}:{{ alertmanager_cluster_port }}
{% endfor %}
build: false
state: '{{ compose_state }}'
restarted: '{{ compose_restart }}'
recreate: '{{ alertmanager_config.changed | ternary("always", compose_recreate) }}'

View File

@ -6,7 +6,7 @@
- name: Get AlertManager node addresses
uri:
url: '{{ consul_catalog_url }}/service/{{ alertmanager_cont_name }}?dc={{ item }}'
url: '{{ consul_catalog_url }}/service/{{ alertmanager_service_name }}?dc={{ item }}'
method: GET
validate_certs: no
with_items: '{{ data_centers.json }}'
@ -14,8 +14,8 @@
- name: Extract IP addresses
set_fact:
cluster_peers: |
alertmanager_cluster_peers: |
{{ alertmanager_services.results
| sum(attribute="json", start=[])
| map(attribute="ServiceAddress")
| sort(attribute='Node')
| list }}

View File

@ -1,6 +1,6 @@
---
- include_tasks: consul.yml
#- include_tasks: consul.yml
- include_tasks: discover.yml
- include_tasks: config.yml
- include_tasks: container.yml
- include_tasks: wrapper.yml
#- include_tasks: wrapper.yml

View File

@ -0,0 +1,26 @@
---
version: '3.7'
services:
app:
container_name: '{{ alertmanager_service_name }}'
image: '{{ alertmanager_cont_image }}'
user: 'root'
restart: 'always'
ports:
- '0.0.0.0:{{ alertmanager_webui_port }}:{{ alertmanager_webui_port }}' # Web UI
- '0.0.0.0:{{ alertmanager_cluster_port }}:{{ alertmanager_cluster_port }}' # Cluster
volumes:
- '{{ alertmanager_service_path }}/conf/alertmanager.yml:/etc/alertmanager.yml:ro'
- '{{ alertmanager_service_path }}/conf/amtool.yml:/etc/amtool/config.yml:ro'
- '{{ alertmanager_service_path }}/data:/data'
- '/certs:/certs'
command:
- '--storage.path=/data'
- '--log.level={{ alertmanager_cont_log_lvl }}'
- '--config.file=/etc/alertmanager.yml'
- '--web.external-url={{ alertmanager_url }}'
- '--cluster.advertise-address={{ ansible_local.tinc.vpn_ip }}:{{ alertmanager_cluster_port }}'
- '--cluster.listen-address=0.0.0.0:{{ alertmanager_cluster_port }}'
{% for peer in alertmanager_cluster_peers %}
- '--cluster.peer={{ peer.ServiceAddress }}:{{ peer.ServicePort }}' # {{ peer.Node }}
{% endfor %}