Skip to content

Commit aac7193

Browse files
committed
feat: up --build support
1 parent 76e453d commit aac7193

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

compose/cli/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,6 @@ def build(self, options):
275275
"""
276276
service_names = options['SERVICE']
277277
build_args = options.get('--build-arg', None)
278-
environment_file = options.get('--env-file')
279-
environment = Environment.from_env_file(self.project_dir, environment_file)
280-
native_builder = environment.get_boolean('COMPOSE_NATIVE_BUILDER')
281278
if build_args:
282279
if not service_names and docker.utils.version_lt(self.project.client.api_version, '1.25'):
283280
raise UserError(
@@ -286,6 +283,8 @@ def build(self, options):
286283
)
287284
build_args = resolve_build_args(build_args, self.toplevel_environment)
288285

286+
native_builder = self.toplevel_environment.get_boolean('COMPOSE_NATIVE_BUILDER')
287+
289288
self.project.build(
290289
service_names=options['SERVICE'],
291290
no_cache=bool(options.get('--no-cache', False)),
@@ -1075,6 +1074,8 @@ def up(self, options):
10751074
for excluded in [x for x in opts if options.get(x) and no_start]:
10761075
raise UserError('--no-start and {} cannot be combined.'.format(excluded))
10771076

1077+
native_builder = self.toplevel_environment.get_boolean('COMPOSE_NATIVE_BUILDER')
1078+
10781079
with up_shutdown_context(self.project, service_names, timeout, detached):
10791080
warn_for_swarm_mode(self.project.client)
10801081

@@ -1094,6 +1095,7 @@ def up(rebuild):
10941095
reset_container_image=rebuild,
10951096
renew_anonymous_volumes=options.get('--renew-anon-volumes'),
10961097
silent=options.get('--quiet-pull'),
1098+
cli=native_builder,
10971099
)
10981100

10991101
try:

compose/project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ def up(self,
509509
reset_container_image=False,
510510
renew_anonymous_volumes=False,
511511
silent=False,
512+
cli=False,
512513
):
513514

514515
self.initialize()
@@ -523,7 +524,7 @@ def up(self,
523524
include_deps=start_deps)
524525

525526
for svc in services:
526-
svc.ensure_image_exists(do_build=do_build, silent=silent)
527+
svc.ensure_image_exists(do_build=do_build, silent=silent, cli=cli)
527528
plans = self._get_convergence_plans(
528529
services, strategy, always_recreate_deps=always_recreate_deps)
529530

compose/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ def create_container(self,
341341
raise OperationFailedError("Cannot create container for service %s: %s" %
342342
(self.name, ex.explanation))
343343

344-
def ensure_image_exists(self, do_build=BuildAction.none, silent=False):
344+
def ensure_image_exists(self, do_build=BuildAction.none, silent=False, cli=False):
345345
if self.can_be_built() and do_build == BuildAction.force:
346-
self.build()
346+
self.build(cli=cli)
347347
return
348348

349349
try:
@@ -359,7 +359,7 @@ def ensure_image_exists(self, do_build=BuildAction.none, silent=False):
359359
if do_build == BuildAction.skip:
360360
raise NeedsBuildError(self)
361361

362-
self.build()
362+
self.build(cli=cli)
363363
log.warning(
364364
"Image for service {} was built because it did not already exist. To "
365365
"rebuild this image you must use `docker-compose build` or "

0 commit comments

Comments
 (0)