5454# epilog="Config provided either in .env or settings.ini or env vars: BPI_REPO_BASE_DIR (defaults to ~/bpi)"
5555
5656
57- def make_container_build_env (dev_root_path : str , container_build_dir : str , debug : bool , force_rebuild : bool , extra_build_args : str ):
57+ def make_container_build_env (dev_root_path : str , default_container_base_dir : str , debug : bool , force_rebuild : bool , extra_build_args : str ):
5858 container_build_env = {
5959 "BPI_NPM_REGISTRY_URL" : get_npm_registry_url (),
6060 "BPI_GO_AUTH_TOKEN" : config ("BPI_GO_AUTH_TOKEN" , default = "" ),
6161 "BPI_NPM_AUTH_TOKEN" : config ("BPI_NPM_AUTH_TOKEN" , default = "" ),
6262 "BPI_REPO_BASE_DIR" : dev_root_path ,
63- "BPI_CONTAINER_BASE_DIR" : container_build_dir ,
63+ "BPI_CONTAINER_BASE_DIR" : default_container_base_dir ,
6464 "BPI_HOST_UID" : f"{ os .getuid ()} " ,
6565 "BPI_HOST_GID" : f"{ os .getgid ()} " ,
6666 "BPI_IMAGE_LOCAL_TAG" : "stack" ,
@@ -99,11 +99,11 @@ def process_container(build_context: BuildContext) -> bool:
9999 # Now check if the container exists in the external stack.
100100 if not temp_build_script_filename .exists ():
101101 # If not, revert to building an internal container
102- container_build_script_dir = build_context .container_build_dir
102+ container_build_script_dir = build_context .default_container_base_dir
103103 build_dir = container_build_script_dir .joinpath (build_context .container .name .replace ("/" , "-" ))
104104 build_script_filename = build_dir .joinpath ("build.sh" )
105105 if not build_dir :
106- build_dir = build_context .container_build_dir .joinpath (build_context .container .name .replace ("/" , "-" ))
106+ build_dir = build_context .default_container_base_dir .joinpath (build_context .container .name .replace ("/" , "-" ))
107107 build_script_filename = build_dir .joinpath ("build.sh" )
108108
109109 if opts .o .verbose :
@@ -117,9 +117,11 @@ def process_container(build_context: BuildContext) -> bool:
117117 # TODO: make this less of a hack -- should be specified in some metadata somewhere
118118 # Check if we have a repo for this container. If not, set the context dir to the container-build subdir
119119 repo_full_path = os .path .join (build_context .dev_root_path , repo_dir )
120+ if build_context .container .path :
121+ repo_full_path = os .path .join (repo_full_path , build_context .container .path )
120122 repo_dir_or_build_dir = repo_full_path if os .path .exists (repo_full_path ) else build_dir
121123 build_command = (
122- os .path .join (build_context .container_build_dir , "default-build.sh" )
124+ os .path .join (build_context .default_container_base_dir , "default-build.sh" )
123125 + f" { default_container_tag } { repo_dir_or_build_dir } "
124126 )
125127
@@ -162,7 +164,7 @@ def command(ctx, stack, include, exclude, git_ssh, build_policy, extra_build_arg
162164 error_exit (f"{ build_policy } is not one of { BUILD_POLICIES } " )
163165
164166 # See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
165- container_build_dir = Path (__file__ ).absolute ().parent .parent .joinpath ("data" , "container-build" )
167+ default_container_base_dir = Path (__file__ ).absolute ().parent .parent .joinpath ("data" , "container-build" )
166168
167169 dev_root_path = get_dev_root_path (ctx )
168170
@@ -180,7 +182,7 @@ def command(ctx, stack, include, exclude, git_ssh, build_policy, extra_build_arg
180182
181183
182184 container_build_env = make_container_build_env (
183- dev_root_path , container_build_dir , opts .o .debug , "build-force" == build_policy , extra_build_args
185+ dev_root_path , default_container_base_dir , opts .o .debug , "build-force" == build_policy , extra_build_args
184186 )
185187
186188 # check if we have any repos that specify the container targets / build info
@@ -207,6 +209,11 @@ def command(ctx, stack, include, exclude, git_ssh, build_policy, extra_build_arg
207209 print (f"Error: Missing container repo for { fs_path_for_container_specs } , run fetch repositories" )
208210 sys .exit (1 )
209211
212+ if stack_container .path :
213+ container_spec .path = Path (os .path .join (fs_path_for_container_specs , stack_container .path )).absolute ().as_posix ()
214+ else :
215+ container_spec .path = fs_path_for_container_specs .absolute ().as_posix ()
216+
210217 image_registries_to_check = [r for r in [image_registry , image_registry_for_repo (stack_container .ref )] if r ]
211218
212219 container_spec_yml_path = os .path .join (fs_path_for_container_specs , container_file_name )
@@ -310,7 +317,8 @@ def command(ctx, stack, include, exclude, git_ssh, build_policy, extra_build_arg
310317 elif container_needs_built :
311318 if build_policy in ["prebuilt" , "prebuilt-local" , "prebuilt-remote" ]:
312319 error_exit (f"No prebuilt image available for: { container_spec .name } " )
313- build_context = BuildContext (stack , container_spec , container_build_dir , container_build_env , dev_root_path )
320+
321+ build_context = BuildContext (stack , container_spec , default_container_base_dir , container_build_env , dev_root_path )
314322
315323 for tag in [stack_legacy_tag , stack_local_tag , container_tag ]:
316324 try :
0 commit comments