Skip to content

Commit

Permalink
PLA-509 add --no-build option to docker-compose up (#23164)
Browse files Browse the repository at this point in the history
## Summary & Motivation

This hooks into docker-compose's functionality to optionally disable
building images, even if specified by the policy

## How I Tested These Changes

Existing integration tests heavily depend on this functionality, so if
those pass then we can be confident that the new args are correct

Co-authored-by: Neil Fulwiler <[email protected]>
  • Loading branch information
neilfulwiler and Neil Fulwiler authored Jul 23, 2024
1 parent f00450d commit ed8896a
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@

@contextmanager
def docker_compose_cm(
docker_compose_yml, network_name=None, docker_context=None, service=None, env_file=None
docker_compose_yml,
network_name=None,
docker_context=None,
service=None,
env_file=None,
no_build: bool = False,
):
if not network_name:
network_name = network_name_from_yml(docker_compose_yml)
try:
docker_compose_up(docker_compose_yml, docker_context, service, env_file)
docker_compose_up(docker_compose_yml, docker_context, service, env_file, no_build=no_build)
if BUILDKITE:
# When running in a container on Buildkite, we need to first connect our container
# and our network and then yield a dict of container name to the container's
Expand All @@ -40,11 +45,12 @@ def _docker_compose(
docker_context=None,
service=None,
env_file=None,
no_build: bool = False,
):
if not docker_compose_yml:
docker_compose_yml = default_docker_compose_yml(test_directory)
with docker_compose_cm(
docker_compose_yml, network_name, docker_context, service, env_file
docker_compose_yml, network_name, docker_context, service, env_file, no_build
) as hostnames:
yield hostnames

Expand All @@ -57,7 +63,7 @@ def docker_compose(docker_compose_cm):
yield docker_compose


def docker_compose_up(docker_compose_yml, context, service, env_file):
def docker_compose_up(docker_compose_yml, context, service, env_file, no_build: bool = False):
if context:
compose_command = ["docker", "--context", context, "compose"]
else:
Expand All @@ -66,6 +72,9 @@ def docker_compose_up(docker_compose_yml, context, service, env_file):
if env_file:
compose_command += ["--env-file", env_file]

if no_build:
compose_command += ["--no-build"]

compose_command += [
"--file",
str(docker_compose_yml),
Expand Down

0 comments on commit ed8896a

Please sign in to comment.