Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add optional dependent services to start #203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+56 −3
Diff settings

Always

Just for now

Add optional dependent services to start

Signed-off-by: Elliott Davis <elliott@excellent.io>
  • Loading branch information...
Elliott Davis
Elliott Davis committed Feb 28, 2019
commit 64f653f40d9a1baa2c2bec7864c8d3c141e6d519
Copy path View file
@@ -297,6 +297,10 @@ A list of services to push in the format `service:image:tag`. If an image has be

Pull down multiple pre-built images. By default only the service that is being run will be pulled down, but this allows multiple images to be specified to handle prebuilt dependent images.

### `deps` (optional, run only)

Start dependent services for your service. By default only your service is started (and any accompanying linked services). However, since links is officially deprecated this command is useful for starting what would normally be linked services.

### `config` (optional)

The file name of the Docker Compose configuration file to use. Can also be a list of filenames.
Copy path View file
@@ -21,6 +21,7 @@ pull_params=()
up_params=()
pull_services=()
prebuilt_candidates=("$run_service")
service_deps=()

# Build a list of services that need to be pulled down
while read -r name ; do
@@ -33,6 +34,17 @@ while read -r name ; do
fi
done <<< "$(plugin_read_list PULL)"

# Build a list of service dependencies that need to be pulled down
while read -r name ; do
if [[ -n "$name" ]] ; then
service_deps+=("$name")

if ! in_array "$name" "${prebuilt_candidates[@]}" ; then
pull_services+=("$name")
fi
fi
done <<< "$(plugin_read_list DEPS)"

# A list of tuples of [service image cache_from] for build_image_override_file
prebuilt_service_overrides=()
prebuilt_services=()
@@ -69,7 +81,7 @@ fi

# Pull down specified services
if [[ ${#pull_services[@]} -gt 0 ]] ; then
echo "~~~ :docker: Pulling services ${pull_services[0]}"
echo "~~~ :docker: Pulling services" "${pull_services[@]}"
retry "$pull_retries" run_docker_compose "${pull_params[@]}"
fi

@@ -151,10 +163,14 @@ fi
# Start up service dependencies in a different header to keep the main run with less noise
if [[ "$(plugin_read_config DEPENDENCIES "true")" == "true" ]] ; then
echo "~~~ :docker: Starting dependencies"
scaled_service_deps=()
for service in "${service_deps[@]}"; do
scaled_service_deps+=(--scale "${service}=1")
done
if [[ ${#up_params[@]} -gt 0 ]] ; then
run_docker_compose "${up_params[@]}" up -d --scale "${run_service}=0" "${run_service}"
run_docker_compose "${up_params[@]}" up -d --scale "${run_service}=0" "${scaled_service_deps[@]}" "${run_service}" "${service_deps[@]}"
else
run_docker_compose up -d --scale "${run_service}=0" "${run_service}"
run_docker_compose up -d "${scaled_service_deps[@]}" --scale "${run_service}=0" "${run_service}" "${service_deps[@]}"
fi

# Sometimes docker-compose leaves unfinished ansi codes
Copy path View file
@@ -17,6 +17,9 @@ configuration:
pull:
type: [ string, array ]
minimum: 1
deps:
type: [ string, array ]
minimum: 1
config:
type: [ string, array ]
minimum: 1
@@ -76,6 +79,7 @@ configuration:
additionalProperties: false
dependencies:
pull: [ run ]
deps: [ run ]
image-repository: [ build ]
image-name: [ build ]
env: [ run ]
Copy path View file
@@ -623,6 +623,35 @@ export BUILDKITE_JOB_ID=1111
unstub buildkite-agent
}

@test "Run with multiple prebuilt images and multiple deps" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice1
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_DEPS_0=myservice2
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_DEPS_1=myservice3
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND=pwd
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull --parallel myservice2 myservice3 myservice1 : echo pulled myservice1, myservice2 and myservice3" \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice2=1 myservice2 --scale myservice3=1 myservice3 --scale myservice1=0 myservice1 : echo started dependencies for myservice1" \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice1_build_1 myservice1 /bin/sh -e -c 'pwd' : echo ran myservice1"

stub buildkite-agent \
"meta-data get docker-compose-plugin-built-image-tag-myservice1 : echo myimage1"

run $PWD/hooks/command

assert_success
assert_output --partial "pulled myservice1, myservice2 and myservice3"
assert_output --partial "ran myservice1"
unstub docker-compose
unstub buildkite-agent
}


@test "Run without a prebuilt image and a custom user" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.