Fixing subdirectory from extends where extended service will build a Service from Dockerfile in an own subdirectory

Signed-off-by: kjunker <junker.kurt@googlemail.com>
This commit is contained in:
kjunker 2022-02-20 21:53:24 +01:00 committed by Muayyad Alsadi
parent 5c3ec5f49a
commit 56b88639ad

View File

@ -934,7 +934,15 @@ class Podman:
volumes = output.splitlines()
return volumes
def normalize_service(service):
def normalize_service(service, sub_dir=''):
if sub_dir and 'build' in service and 'context' in service['build']:
context = service['build']['context']
if re.match('^(((\./)?(\w+)+(/\w+)+?$)|(\.$))', context):
if context.startswith('.'):
context = context.replace('.', sub_dir)
else:
context = sub_dir + os.sep + context
service['build']['context'] = context
for key in ("env_file", "security_opt", "volumes"):
if key not in service: continue
if is_str(service[key]): service[key]=[service[key]]
@ -1014,9 +1022,12 @@ def resolve_extends(services, service_names, environ):
content = yaml.safe_load(f) or {}
if "services" in content:
content = content["services"]
subdirectory = filename.rsplit(os.sep, 1)[0]
if filename == subdirectory:
subdirectory = ''
content = rec_subs(content, environ)
from_service = content.get(from_service_name, {})
normalize_service(from_service)
normalize_service(from_service, subdirectory)
else:
from_service = services.get(from_service_name, {}).copy()
del from_service["_deps"]