mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-05-18 10:40:33 +02:00
Added journalctl logging for docker up's and execute portfolio just once condition
This commit is contained in:
parent
ae48aebcd7
commit
39b312b997
@ -16,4 +16,20 @@ watch -n 2 "docker compose ps -a"
|
||||
|
||||
```bash
|
||||
docker inspect --format='{{json .State.Health}}' <container_id>
|
||||
```
|
||||
```
|
||||
|
||||
### 🔍 Logging with `journalctl`
|
||||
|
||||
All Docker Compose actions triggered by this role are logged to the system journal using `systemd-cat`. Output is simultaneously shown in the terminal and available via `journalctl`.
|
||||
|
||||
To view logs for a specific application:
|
||||
|
||||
```bash
|
||||
journalctl -t docker-compose-<application_id> -f
|
||||
```
|
||||
|
||||
Replace `<application_id>` with the actual project name (e.g. `discourse`, `nextcloud`, etc.).
|
||||
|
||||
This enables persistent and searchable logs for all container setups and rebuilds.
|
||||
|
||||
|
||||
|
@ -4,15 +4,18 @@
|
||||
# https://github.com/ansible/ansible/issues/10244
|
||||
#- name: shut down docker compose project
|
||||
# command:
|
||||
# cmd: docker-compose -p "{{application_id}}" down
|
||||
# cmd: docker-compose -p "{{ application_id }}" down
|
||||
# listen: docker compose project setup
|
||||
# when: mode_reset | bool
|
||||
|
||||
# default setup for docker compose files
|
||||
- name: docker compose project setup
|
||||
command:
|
||||
cmd: "docker-compose -p {{application_id}} up -d --force-recreate --remove-orphans"
|
||||
chdir: "{{docker_compose.directories.instance}}"
|
||||
shell: >
|
||||
docker-compose -p {{ application_id }} up -d --force-recreate --remove-orphans
|
||||
2>&1 | tee >(systemd-cat -t docker-compose-{{ application_id }})
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
COMPOSE_HTTP_TIMEOUT: 600
|
||||
DOCKER_CLIENT_TIMEOUT: 600
|
||||
@ -21,9 +24,12 @@
|
||||
# it's necessary to rebuild when a build in the docker compose files is defined
|
||||
# for performance reasons it's not recommended to use this if there is no build tag specified
|
||||
- name: docker compose project build and setup
|
||||
command:
|
||||
cmd: "docker-compose -p {{application_id}} up -d --force-recreate --build --remove-orphans"
|
||||
chdir: "{{docker_compose.directories.instance}}"
|
||||
shell: >
|
||||
docker-compose -p {{ application_id }} up -d --force-recreate --build --remove-orphans
|
||||
2>&1 | tee >(systemd-cat -t docker-compose-{{ application_id }})
|
||||
args:
|
||||
chdir: "{{ docker_compose.directories.instance }}"
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
COMPOSE_HTTP_TIMEOUT: 600
|
||||
DOCKER_CLIENT_TIMEOUT: 600
|
||||
|
@ -14,4 +14,14 @@ To reinitialize the container execute:
|
||||
|
||||
```bash
|
||||
docker network connect discourse_default central-postgres && /opt/docker/discourse/services/discourse_repository/launcher rebuild discourse_application
|
||||
```
|
||||
```
|
||||
|
||||
### 🔍 Logging with `journalctl`
|
||||
|
||||
All build actions triggered by this role are logged to the system journal using `systemd-cat`. Output is simultaneously shown in the terminal and available via `journalctl`.
|
||||
|
||||
To view logs for a specific application:
|
||||
|
||||
```bash
|
||||
journalctl -t rebuild-discourse -f
|
||||
```
|
||||
|
@ -17,7 +17,10 @@
|
||||
listen: recreate discourse
|
||||
|
||||
- name: rebuild discourse
|
||||
command:
|
||||
cmd: "./launcher rebuild {{applications[application_id].container}}"
|
||||
shell: >
|
||||
./launcher rebuild {{applications[application_id].container}}
|
||||
2>&1 | tee >(systemd-cat -t rebuild-{{ application_id }})
|
||||
args:
|
||||
executable: /bin/bash
|
||||
chdir: "{{docker_repository_directory }}"
|
||||
listen: recreate discourse
|
@ -2,6 +2,7 @@
|
||||
- name: "include docker-compose role"
|
||||
include_role:
|
||||
name: docker-compose
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: "include role nginx-domain-setup for {{application_id}}"
|
||||
include_role:
|
||||
@ -9,10 +10,12 @@
|
||||
vars:
|
||||
domain: "{{ domains[application_id] }}"
|
||||
http_port: "{{ ports.localhost.http[application_id] }}"
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: "include role docker-repository-setup for {{application_id}}"
|
||||
include_role:
|
||||
name: docker-repository-setup
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: "Check if host-specific config.yaml exists in {{ config_inventory_path }}"
|
||||
stat:
|
||||
@ -20,18 +23,22 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: config_file
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Load menu categories
|
||||
include_vars:
|
||||
file: "menu_categories.yml"
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Load docker cards
|
||||
set_fact:
|
||||
portfolio_cards: "{{ lookup('docker_cards', 'roles') }}"
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Group docker cards
|
||||
set_fact:
|
||||
portfolio_menu_data: "{{ lookup('docker_cards_grouped', portfolio_cards, portfolio_menu_categories) }}"
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Debug portfolio data
|
||||
debug:
|
||||
@ -39,24 +46,36 @@
|
||||
portfolio_cards: "{{ portfolio_cards }}"
|
||||
portfolio_menu_categories: "{{ portfolio_menu_categories}}"
|
||||
portfolio_menu_data: "{{ portfolio_menu_data }}"
|
||||
when: enable_debug | bool
|
||||
when:
|
||||
- enable_debug | bool
|
||||
- run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Copy host-specific config.yaml if it exists
|
||||
template:
|
||||
src: "{{ config_inventory_path }}"
|
||||
dest: "{{docker_repository_path}}/app/config.yaml"
|
||||
notify: docker compose project setup
|
||||
when: config_file.stat.exists
|
||||
when:
|
||||
- config_file.stat.exists
|
||||
- run_once_docker_portfolio is not defined
|
||||
|
||||
- name: Copy default config.yaml from the role template if host-specific file does not exist
|
||||
template:
|
||||
src: "config.yaml.j2"
|
||||
dest: "{{docker_repository_path}}/app/config.yaml"
|
||||
notify: docker compose project setup
|
||||
when: not config_file.stat.exists
|
||||
when:
|
||||
- not config_file.stat.exists
|
||||
- run_once_docker_portfolio is not defined
|
||||
|
||||
- name: add docker-compose.yml
|
||||
template:
|
||||
src: docker-compose.yml.j2
|
||||
dest: "{docker_compose.directories.instance}}docker-compose.yml"
|
||||
notify: docker compose project setup
|
||||
when: run_once_docker_portfolio is not defined
|
||||
|
||||
- name: run the portfolio tasks once
|
||||
set_fact:
|
||||
run_once_docker_portfolio: true
|
||||
when: run_once_docker_portfolio is not defined
|
Loading…
x
Reference in New Issue
Block a user