Skip to content

Commit

Permalink
Mergeback from master to resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
toote committed Dec 17, 2022
2 parents 43117b1 + 44894d4 commit cb92712
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 7 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,14 @@ The default is `true` on unix, `false` on windows

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

If set to false, doesn't start linked services.
If set to false, runs with `--no-deps` and doesn't start linked services.

The default is `true`.

### `pre-run-dependencies` (optional, run only)

If `dependencies` are activated (which is the default), you can skip starting them up before the main container by setting this option to `false`. This is useful if you want compose to take care of that on its own at the expense of messier output in the run step.

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

Whether to wait for dependencies to be up (and healthy if possible) when starting them up. It translates to using [`--wait` in the docker-compose up] command.
Expand Down Expand Up @@ -614,6 +618,18 @@ If set to true, docker compose will remove the primary container after run. Equi

The default is `true`.

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

If set to true, all docker compose commands will rum with compatibility mode. Equivalent to `--compatibility` in docker-compose.

The default is `false`.

Note that [the effect of this option changes depending on your docker compose CLI version](https://docs.docker.com/compose/cli-command-compatibility/#flags-that-will-not-be-implemented):
* in v1 it translates (composefile) v3 deploy keys to their non-swarm (composefile) v2 equivalents
* in v2 it will revert some behaviour to v1 as well, including (but not limited to):
- [Character separator for container names](https://github.com/docker/compose/blob/a0acc20d883ce22b8b0c65786e3bea1328809bbd/cmd/compose/compose.go#L181)
- [Not normalizing compose models (when running `config`)](https://github.com/docker/compose/blob/2e7644ff21f9ca0ea6fb5e8d41d4f6af32cd7e20/cmd/compose/convert.go#L69)

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

Sets the `--entrypoint` argument when running `docker-compose`.
Expand Down
6 changes: 5 additions & 1 deletion commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fi
tty_default='true'
workdir_default="/workdir"
pwd_default="$PWD"
run_dependencies="true"

# Set operating system specific defaults
if is_windows ; then
Expand All @@ -137,6 +138,9 @@ fi
# Optionally disable dependencies
if [[ "$(plugin_read_config DEPENDENCIES "true")" == "false" ]] ; then
run_params+=(--no-deps)
run_dependencies="false"
elif [[ "$(plugin_read_config PRE_RUN_DEPENDENCIES "true")" == "false" ]]; then
run_dependencies="false"
fi

if [[ -n "$(plugin_read_config WORKDIR)" ]] || [[ "${mount_checkout}" == "true" ]]; then
Expand Down Expand Up @@ -274,7 +278,7 @@ if [[ "$(plugin_read_config WAIT "false")" == "true" ]] ; then
fi

dependency_exitcode=0
if [[ "$(plugin_read_config DEPENDENCIES "true")" == "true" ]] ; then
if [[ "${run_dependencies}" == "true" ]] ; then
# Start up service dependencies in a different header to keep the main run with less noise
echo "~~~ :docker: Starting dependencies"
run_docker_compose "${up_params[@]}" -d --scale "${run_service}=0" "${run_service}" || dependency_exitcode=$?
Expand Down
2 changes: 1 addition & 1 deletion lib/push.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default_compose_image_for_service() {
local service="$1"

local separator="_"
if [[ "$(plugin_read_config CLI_VERSION "1")" == "2" ]] ; then
if [[ "$(plugin_read_config CLI_VERSION "1")" == "2" ]] && [[ "$(plugin_read_config COMPATIBILITY "false")" != "true" ]] ; then
separator="-"
fi

Expand Down
5 changes: 5 additions & 0 deletions lib/shared.bash
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ function run_docker_compose() {
command+=(--no-ansi)
fi

# Enable compatibility mode for v3 files
if [[ "$(plugin_read_config COMPATIBILITY "false")" == "true" ]]; then
command+=(--compatibility)
fi

for file in $(docker_compose_config_files) ; do
command+=(-f "$file")
done
Expand Down
13 changes: 9 additions & 4 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ configuration:
cache-from:
type: [ string, array ]
minimum: 1
separator-cache-from:
type: string
minLength: 1
maxLength: 1
compatibility:
type: boolean
cli-version:
type: string
enum:
Expand Down Expand Up @@ -67,6 +65,8 @@ configuration:
type: [ boolean, string ]
no-cache:
type: boolean
pre-run-dependencies:
type: boolean
propagate-environment:
type: boolean
propagate-uid-gid:
Expand All @@ -80,6 +80,10 @@ configuration:
type: integer
rm:
type: boolean
separator-cache-from:
type: string
minLength: 1
maxLength: 1
service-ports:
type: boolean
skip-checkout:
Expand Down Expand Up @@ -129,6 +133,7 @@ configuration:
leave-volumes: [ run ]
mount-buildkite-agent: [ run ]
mount-checkout: [ run ]
pre-run-dependencies: [ run ]
propagate-uid-gid: [ run ]
pull: [ run ]
push-retries: [ push ]
Expand Down
53 changes: 53 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,32 @@ export BUILDKITE_JOB_ID=1111
unstub buildkite-agent
}

@test "Run with dependencies but in a single step" {
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND=pwd
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PIPELINE_SLUG=test

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PRE_RUN_DEPENDENCIES=false

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with dependencies"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \
"meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran myservice with dependencies"
unstub docker-compose
unstub buildkite-agent
}

@test "Run without ansi output" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
Expand Down Expand Up @@ -612,6 +638,33 @@ export BUILDKITE_JOB_ID=1111
unstub buildkite-agent
}

@test "Run with compatibility mode" {
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND=pwd
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PIPELINE_SLUG=test

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true

stub docker-compose \
"--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
"--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \
"--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \
"meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran myservice with use aliases output"
unstub docker-compose
unstub buildkite-agent
}

@test "Run with a volumes option" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
Expand Down
30 changes: 30 additions & 0 deletions tests/v2/push.bats
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ setup_file() {
unstub buildkite-agent
}

@test "Push a prebuilt image with a repository and a tag in compatibility mode" {
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PIPELINE_SLUG=test

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice:my.repository/myservice:llamas
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true

stub docker \
"compose --compatibility -f docker-compose.yml -p buildkite1111 config : echo blah" \
"pull myimage : echo pulled prebuilt image" \
"tag myimage buildkite1111_myservice : echo " \
"tag buildkite1111_myservice my.repository/myservice:llamas : echo tagged image" \
"push my.repository/myservice:llamas : echo pushed myservice"


stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \
"meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage"

run $PWD/hooks/command

assert_success
assert_output --partial "pulled prebuilt image"
assert_output --partial "tagged image"
assert_output --partial "pushed myservice"
unstub docker
unstub buildkite-agent
}

@test "Push a prebuilt image with an invalid tag" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice:my.repository/myservice:-llamas
Expand Down
55 changes: 55 additions & 0 deletions tests/v2/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,33 @@ export BUILDKITE_JOB_ID=1111
unstub buildkite-agent
}

@test "Run with dependencies but in a single step" {
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND=pwd
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PIPELINE_SLUG=test

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PRE_RUN_DEPENDENCIES=false

stub docker \
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
"compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with dependencies"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \
"meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran myservice with dependencies"

unstub docker
unstub buildkite-agent
}

@test "Run without ansi output" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
Expand Down Expand Up @@ -586,6 +613,34 @@ export BUILDKITE_JOB_ID=1111
unstub buildkite-agent
}


@test "Run with compatibility mode" {
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_COMMAND=pwd
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PIPELINE_SLUG=test

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true

stub docker \
"compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \
"compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \
"compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \
"meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage"

run "$PWD"/hooks/command

assert_success
assert_output --partial "ran myservice with use aliases output"
unstub docker
unstub buildkite-agent
}

@test "Run with a volumes option" {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
Expand Down

0 comments on commit cb92712

Please sign in to comment.