mirror of
https://github.com/containers/podman-compose.git
synced 2025-05-11 09:44:52 +02:00
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:
parent
5c3ec5f49a
commit
56b88639ad
@ -148,7 +148,7 @@ def fix_mount_dict(compose, mount_dict, proj_name, srv_name):
|
|||||||
vols = compose.vols
|
vols = compose.vols
|
||||||
source = mount_dict.get("source", None)
|
source = mount_dict.get("source", None)
|
||||||
vol = (vols.get(source, None) or {}) if source else {}
|
vol = (vols.get(source, None) or {}) if source else {}
|
||||||
name = vol.get('name', None)
|
name = vol.get('name', None)
|
||||||
mount_dict["_vol"] = vol
|
mount_dict["_vol"] = vol
|
||||||
# handle anonymouse or implied volume
|
# handle anonymouse or implied volume
|
||||||
if not source:
|
if not source:
|
||||||
@ -934,7 +934,15 @@ class Podman:
|
|||||||
volumes = output.splitlines()
|
volumes = output.splitlines()
|
||||||
return volumes
|
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"):
|
for key in ("env_file", "security_opt", "volumes"):
|
||||||
if key not in service: continue
|
if key not in service: continue
|
||||||
if is_str(service[key]): service[key]=[service[key]]
|
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 {}
|
content = yaml.safe_load(f) or {}
|
||||||
if "services" in content:
|
if "services" in content:
|
||||||
content = content["services"]
|
content = content["services"]
|
||||||
|
subdirectory = filename.rsplit(os.sep, 1)[0]
|
||||||
|
if filename == subdirectory:
|
||||||
|
subdirectory = ''
|
||||||
content = rec_subs(content, environ)
|
content = rec_subs(content, environ)
|
||||||
from_service = content.get(from_service_name, {})
|
from_service = content.get(from_service_name, {})
|
||||||
normalize_service(from_service)
|
normalize_service(from_service, subdirectory)
|
||||||
else:
|
else:
|
||||||
from_service = services.get(from_service_name, {}).copy()
|
from_service = services.get(from_service_name, {}).copy()
|
||||||
del from_service["_deps"]
|
del from_service["_deps"]
|
||||||
@ -1368,7 +1379,7 @@ class cmd_parse:
|
|||||||
|
|
||||||
@cmd_run(podman_compose, 'version', 'show version')
|
@cmd_run(podman_compose, 'version', 'show version')
|
||||||
def compose_version(compose, args):
|
def compose_version(compose, args):
|
||||||
if getattr(args, 'short', False):
|
if getattr(args, 'short', False):
|
||||||
print(__version__)
|
print(__version__)
|
||||||
return
|
return
|
||||||
if getattr(args, 'format', 'pretty') == 'json':
|
if getattr(args, 'format', 'pretty') == 'json':
|
||||||
@ -1554,7 +1565,7 @@ def compose_up(compose, args):
|
|||||||
thread.start()
|
thread.start()
|
||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
while threads:
|
while threads:
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
thread.join(timeout=1.0)
|
thread.join(timeout=1.0)
|
||||||
@ -1655,7 +1666,7 @@ def compose_run(compose, args):
|
|||||||
cnt['tty']=False if args.T else True
|
cnt['tty']=False if args.T else True
|
||||||
if args.cnt_command is not None and len(args.cnt_command) > 0:
|
if args.cnt_command is not None and len(args.cnt_command) > 0:
|
||||||
cnt['command']=args.cnt_command
|
cnt['command']=args.cnt_command
|
||||||
# can't restart and --rm
|
# can't restart and --rm
|
||||||
if args.rm and 'restart' in cnt:
|
if args.rm and 'restart' in cnt:
|
||||||
del cnt['restart']
|
del cnt['restart']
|
||||||
# run podman
|
# run podman
|
||||||
@ -1764,7 +1775,7 @@ def compose_config(compose, args):
|
|||||||
def compose_version_parse(parser):
|
def compose_version_parse(parser):
|
||||||
parser.add_argument("-f", "--format", choices=['pretty', 'json'], default='pretty',
|
parser.add_argument("-f", "--format", choices=['pretty', 'json'], default='pretty',
|
||||||
help="Format the output")
|
help="Format the output")
|
||||||
parser.add_argument("--short", action='store_true',
|
parser.add_argument("--short", action='store_true',
|
||||||
help="Shows only Podman Compose's version number")
|
help="Shows only Podman Compose's version number")
|
||||||
|
|
||||||
@cmd_parse(podman_compose, 'up')
|
@cmd_parse(podman_compose, 'up')
|
||||||
|
Loading…
Reference in New Issue
Block a user