Avoid crash when no services are defined

If no services are defined, podman-compose
crashes as services variable is None,
while the expected behavior might be
an error or the same as docker-compose, which will continue the
execution of the compose file (eg. creating networks, etc).

This commit fixes the crash and allows the program to continue, mimicking
docker-compose behavior.
This commit is contained in:
Enrico204 2020-04-04 23:09:37 +02:00 committed by Muayyad Alsadi
parent efcbc75f63
commit 796e6a4473
2 changed files with 11 additions and 0 deletions

View File

@ -828,6 +828,10 @@ class PodmanCompose:
print(" ** merged:\n", json.dumps(compose, indent = 2)) print(" ** merged:\n", json.dumps(compose, indent = 2))
ver = compose.get('version') ver = compose.get('version')
services = compose.get('services') services = compose.get('services')
if services is None:
services = {}
print("WARNING: No services defined")
# NOTE: maybe add "extends.service" to _deps at this stage # NOTE: maybe add "extends.service" to _deps at this stage
flat_deps(services, with_extends=True) flat_deps(services, with_extends=True)
service_names = sorted([ (len(srv["_deps"]), name) for name, srv in services.items() ]) service_names = sorted([ (len(srv["_deps"]), name) for name, srv in services.items() ])

View File

@ -0,0 +1,7 @@
version: '3'
networks:
shared-network:
driver: bridge
ipam:
config:
- subnet: 172.19.0.0/24