refactor to use Docker Compose

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-03-25 14:03:52 +01:00
parent 5f3011243a
commit b187f16ad9
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
4 changed files with 62 additions and 42 deletions

View File

@ -1,25 +1,20 @@
---
geth_expo_service_name: 'geth'
geth_expo_service_path: '/docker/{{ geth_expo_service_name }}'
geth_expo_compose_path: '{{ geth_expo_service_path }}/docker-compose.exporter.yml'
# source container
geth_source_cont_name: ~
geth_source_cont_ipc_path: '/data/geth.ipc'
#geth_expo_source_data_path: ~
#geth_expo_source_cont_name: ~
# metrics container settings
geth_expo_cont_image: statusteam/geth_exporter:latest
geth_expo_cont_name: geth-exporter
geth_expo_cont_tag: 'latest'
geth_expo_cont_image: 'statusteam/geth_exporter:{{ geth_expo_cont_tag }}'
geth_expo_cont_name: '{{ geth_expo_service_name }}-exporter'
geth_expo_cont_addr: '0.0.0.0'
geth_expo_cont_port: 9200
# consul catalog data
geth_expo_consul_id: 'geth-exporter'
geth_expo_consul_name: 'geth-exporter'
geth_expo_consul_addr: '{{ ansible_local.tinc.vpn_ip }}'
geth_expo_consul_extra_tag: '{{ geth_expo_cont_name }}'
geth_expo_consul_tags:
- '{{ geth_expo_consul_extra_tag }}'
- metrics
- geth
# generic container settings
cont_state: started
cont_recreate: false
cont_restart: false
# general container management
compose_recreate: 'smart'
compose_state: 'present'
compose_restart: false

View File

@ -2,17 +2,18 @@
- name: Create Consul service definition
include_role: name=consul-service
vars:
consul_config_name: '{{ geth_expo_cont_name | replace("-", "_") }}'
consul_config_name: '{{ geth_expo_cont_name }}'
consul_services:
- id: '{{ geth_expo_consul_id }}'
name: '{{ geth_expo_consul_name }}'
# Prometheus config expects this service name
- name: 'geth-exporter'
id: '{{ geth_expo_cont_name }}'
port: '{{ geth_expo_cont_port }}'
address: '{{ geth_expo_consul_addr }}'
tags: '{{ geth_expo_consul_tags }}'
address: '{{ ansible_local.tinc.vpn_ip }}'
tags: ['{{ geth_expo_cont_name }}', 'metrics', 'geth']
meta:
container: '{{ geth_source_cont_name | mandatory }}'
container: '{{ geth_expo_source_cont_name | mandatory }}'
checks:
- id: '{{ geth_expo_consul_name }}-health'
- id: '{{ geth_expo_cont_name }}-health'
name: 'geth-exporter healthcheck'
type: http
http: 'http://localhost:{{ geth_expo_cont_port }}/health'

View File

@ -1,18 +1,24 @@
---
- name: 'Start container: {{ geth_expo_cont_name }}'
docker_container:
name: '{{ geth_expo_cont_name }}'
image: '{{ geth_expo_cont_image }}'
user: root
pull: true
restart_policy: always
state: '{{ cont_state }}'
recreate: '{{ cont_recreate }}'
restart: '{{ cont_restart }}'
entrypoint: geth_exporter
volumes_from: '{{ geth_source_cont_name | mandatory }}'
command: |
-ipc {{ geth_source_cont_ipc_path }}
-port 9200
ports:
- '{{ geth_expo_cont_port }}:9200/tcp'
- name: Create compose file
template:
src: 'docker-compose.yml.j2'
dest: '{{ geth_expo_compose_path }}'
owner: 'dockremap'
group: 'docker'
mode: 0640
# Take into account additional docker-compose.yml files.
- name: Find all Docker Compose files
find:
paths: '{{ geth_expo_service_path }}'
patterns: 'docker-compose*.yml'
recurse: false
register: geth_expo_all_compose
- name: Create containers
docker_compose:
project_src: '{{ geth_expo_service_path }}'
files: '{{ geth_expo_all_compose.files | map(attribute="path") | list }}'
state: '{{ compose_state }}'
restarted: '{{ compose_restart }}'
recreate: '{{ compose_recreate | default("smart") }}'

View File

@ -0,0 +1,18 @@
---
version: '3.7'
services:
metrics:
container_name: '{{ geth_expo_cont_name }}'
image: '{{ geth_expo_cont_image }}'
user: 'root'
restart: 'always'
entrypoint: 'geth_exporter'
ports:
- '{{ geth_expo_cont_port }}:{{ geth_expo_cont_port }}/tcp'
volumes:
- '{{ geth_expo_source_data_path | mandatory }}:/data'
command: |
-ipc /data/geth.ipc
-port {{ geth_expo_cont_port }}
depends_on:
- 'geth'