Skip to content

Commit

Permalink
Persist container '/var/log'
Browse files Browse the repository at this point in the history
Mount '/var/log' as a shared directory so logs can be accessed in the
host, even if the container is removed.

Use per container setting 'nolog: true', to disable the behavior.

Signed-off-by: Rafael Guterres Jeffman <[email protected]>
  • Loading branch information
rjeffman committed Feb 8, 2025
1 parent 47101c6 commit 39f1321
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ Deploy the cluster with:
ansible-playbook -i inventory.yml playbooks/install-cluster.yml
```

The contents of each container `/var/log` can be found in the `logs/<name>` directory, soexecution can be evaluated even if the containers are offline.

To dispose the environment use:

```
podman-compose down
```


The configuration file
----------------------
Expand Down
4 changes: 4 additions & 0 deletions features/custom_container.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Scenario: Deploy server with custom containerfile
build:
context: containerfiles
dockerfile: my-container
volumes:
- ${PWD}/logs/server:/var/log:rw
"""
And the file "my-container" is copied to directory "custom_container/containerfiles"

Expand Down Expand Up @@ -98,5 +100,7 @@ Scenario: Pass container file through the command line
build:
context: containerfiles
dockerfile: my-container
volumes:
- ${PWD}/logs/server:/var/log:rw
"""
And the file "my-container" is copied to directory "custom_container/containerfiles"
7 changes: 7 additions & 0 deletions features/external_host.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Scenario: External DNS
dockerfile: fedora-latest
dns: 192.168.53.254
dns_search: ipa.test
volumes:
- ${PWD}/logs/server:/var/log:rw
nameserver:
container_name: nameserver
systemd: true
Expand All @@ -80,6 +82,7 @@ Scenario: External DNS
dns: 192.168.53.254
dns_search: ipa.test
volumes:
- ${PWD}/logs/nameserver:/var/log:rw
- ${PWD}/unbound:/etc/unbound:rw
"""
And the ipa-lab/inventory.yml file is
Expand Down Expand Up @@ -195,6 +198,8 @@ Scenario: Samba AD DC
args:
packages: systemd
command: /usr/sbin/init
volumes:
- ${PWD}/logs/addc:/var/log:rw
server:
container_name: server
systemd: true
Expand All @@ -213,6 +218,8 @@ Scenario: Samba AD DC
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/server:/var/log:rw
networks:
ipanet:
name: ipanet-ipa-ad-trust
Expand Down
2 changes: 2 additions & 0 deletions features/external_network.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Scenario: Use an external network
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/server:/var/log:rw
"""

Scenario: Fail to provide 'subnet' with external network
Expand Down
14 changes: 14 additions & 0 deletions features/minimal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Scenario: Minimal single server
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/server:/var/log:rw
"""
And the ipa-lab/inventory.yml file is
"""
Expand Down Expand Up @@ -122,6 +124,8 @@ Scenario: Minimum IPA cluster
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/server:/var/log:rw
replica:
container_name: replica
systemd: true
Expand All @@ -140,6 +144,8 @@ Scenario: Minimum IPA cluster
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/replica:/var/log:rw
client:
container_name: client
systemd: true
Expand All @@ -158,6 +164,8 @@ Scenario: Minimum IPA cluster
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/client:/var/log:rw
"""
And the ipa-lab/inventory.yml file is
"""
Expand Down Expand Up @@ -269,6 +277,8 @@ Scenario: FQDN containers and replica capapabilities
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/server.ipa.test:/var/log:rw
replica.ipa.test:
container_name: replica.ipa.test
systemd: true
Expand All @@ -287,6 +297,8 @@ Scenario: FQDN containers and replica capapabilities
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/replica.ipa.test:/var/log:rw
client.ipa.test:
container_name: client.ipa.test
systemd: true
Expand All @@ -305,6 +317,8 @@ Scenario: FQDN containers and replica capapabilities
build:
context: containerfiles
dockerfile: fedora-latest
volumes:
- ${PWD}/logs/client.ipa.test:/var/log:rw
"""
And the ipa-lab/inventory.yml file is
"""
Expand Down
4 changes: 4 additions & 0 deletions ipalab_config/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def generate_ipalab_configuration():
gen_external_node_configuration(data, base_dir, compose_config)

save_data(yaml, base_dir, "compose.yml", compose_config)
# create log directories
for node in compose_config["services"]:
os.makedirs(os.path.join(base_dir, "logs", node), exist_ok=True)

save_data(yaml, base_dir, "inventory.yml", inventory_config)

save_containers_data(data, base_dir, args)
Expand Down
14 changes: 12 additions & 2 deletions ipalab_config/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ def node_dns_key(hostname):
)
config["dns_search"] = network.domain

if "volumes" in container:
config.update({"volumes": container["volumes"]})
if not container.get("nolog", False):
volumes = container.get("volumes", [])
if not isinstance(volumes, (list, tuple)):
volumes = [volumes]
volumes.extend([f"${{PWD}}/logs/{name}:/var/log:rw"])
config.update({"volumes": volumes})

result[name] = config
return nodes, result
Expand Down Expand Up @@ -236,7 +240,13 @@ def get_external_hosts_configuration(lab_config, networkname, ip_generator):
for node in ext_nodes:
role = node.get("role")
if role and role in config:
volumes = config[role].pop("volumes", None)
services[node["name"]].update(config[role])
# Merge volumes with user configuration
if volumes:
uservol = services[node["name"]].get("volumes", [])
uservol.extend(volumes)
services[node["name"]]["volumes"] = uservol
services[node["name"]]["external_node"] = node
if dns:
service["dns"] = dns
Expand Down

0 comments on commit 39f1321

Please sign in to comment.