refactor to use Docker Compose

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-09-30 12:42:18 +02:00
parent 10f34e0c67
commit 46ab9d32bf
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
4 changed files with 51 additions and 28 deletions

View File

@ -1,8 +1,15 @@
---
matterbridge_service_name: 'matterbridge'
matterbridge_service_path: '/docker/{{ matterbridge_service_name }}'
matterbridge_compose_file: '{{ matterbridge_service_path }}/docker-compose.yml'
# container
matterbridge_version: 'latest'
matterbridge_cont_image: 'statusteam/matterbridge:{{ matterbridge_version }}'
matterbridge_cont_name: 'matterbridge'
matterbridge_cont_vol: '/docker/{{ matterbridge_cont_name }}'
matterbridge_cont_name: '{{ matterbridge_service_name }}'
matterbridge_cont_vol: '{{ matterbridge_service_path }}/app'
# general config
matterbridge_debug: false
matterbridge_nick: bridge
matterbridge_ens_name: bridge.stateofus.eth
@ -18,6 +25,6 @@ matterbridge_gateways: []
matterbridge_bridges: {}
# general container management
cont_state: started
cont_recreate: false
cont_restart: false
compose_recreate: 'smart'
compose_state: 'present'
compose_restart: false

View File

@ -2,12 +2,12 @@
- name: Create Consul service definition
include_role: name=consul-service
vars:
consul_config_name: '{{ matterbridge_cont_name }}'
consul_config_name: '{{ matterbridge_service_name }}'
consul_services:
- name: '{{ matterbridge_cont_name }}'
- name: '{{ matterbridge_service_name }}'
tags: ['matterbridge', 'bridge']
checks:
- id: '{{ matterbridge_cont_name }}-status'
- id: '{{ matterbridge_service_name }}-health'
name: 'MatterBridge health'
type: 'script'
script: '/usr/bin/pgrep -xl matterbridge'
@ -16,12 +16,12 @@
include_role: name=consul-service
when: '{{ matterbridge_api_enabled }}'
vars:
consul_config_name: '{{ matterbridge_cont_name }}-api'
consul_config_name: '{{ matterbridge_service_name }}-api'
consul_services:
- name: '{{ matterbridge_cont_name }}-api'
- name: '{{ matterbridge_service_name }}-api'
tags: ['matterbridge', 'bridge']
checks:
- id: '{{ matterbridge_cont_name }}-api-health'
- id: '{{ matterbridge_service_name }}-api-health'
name: 'MatterBridge API health'
type: 'script'
script: 'curl --fail http://localhost:{{ matterbridge_api_port }}/api/health'
type: 'http'
http: 'http://localhost:{{ matterbridge_api_port }}/api/health'

View File

@ -1,18 +1,16 @@
---
- name: MatterBridge | Create compose file
template:
src: 'docker-compose.yml.j2'
dest: '{{ matterbridge_compose_file }}'
owner: 'dockremap'
group: 'docker'
mode: 0644
- name: MatterBridge | Create container
docker_container:
name: '{{ matterbridge_cont_name }}'
image: '{{ matterbridge_cont_image }}'
docker_compose:
project_src: '{{ matterbridge_service_path }}'
pull: true
restart_policy: always
state: '{{ cont_state }}'
recreate: '{{ cont_recreate }}'
restart: '{{ config_file.changed or cont_restart }}'
volumes:
- '{{ matterbridge_cont_vol }}/matterbridge.yaml:/matterbridge.yaml'
ports: '{{ [lookup("vars", "docker_api_port")] if lookup("vars", "matterbridge_api_enabled") else [] }}'
command: |
-conf=/matterbridge.yaml
{% if matterbridge_debug %}-debug{% endif %}
vars:
docker_api_port: '{{ matterbridge_api_port }}:{{ matterbridge_api_port }}'
state: '{{ compose_state }}'
restarted: '{{ compose_restart }}'
recreate: '{{ compose_recreate }}'

View File

@ -0,0 +1,18 @@
---
version: '3.7'
services:
app:
container_name: '{{ matterbridge_cont_name }}'
image: '{{ matterbridge_cont_image }}'
restart: 'always'
volumes:
- '{{ matterbridge_cont_vol }}/matterbridge.yaml:/matterbridge.yaml'
command: |
-conf=/matterbridge.yaml
{% if matterbridge_debug %}
-debug
{% endif %}
{% if matterbridge_api_enabled %}
ports:
- '{{ matterbridge_api_port }}:{{ matterbridge_api_port }}'
{% endif %}