Skip to content

Commit

Permalink
Merge pull request #341 from buildkite-plugins/toote_skip_pull_issue_292
Browse files Browse the repository at this point in the history
Skip pull in run step
  • Loading branch information
pzeballos authored Oct 11, 2022
2 parents 9c707dc + 3698342 commit 9a55963
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 80 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Will cause the image to be pushed twice (once by the build step and another by t

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

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.
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. Note that pulling will be skipped if the `skip-pull` option is activated.

### `config` (optional)

Expand Down Expand Up @@ -458,7 +458,13 @@ Example: `[ "powershell", "-Command" ]`

### `skip-checkout` (optional, run only)

Whether to skip the repository checkout phase. This is useful for steps that use a pre-built image. This will fail if there is no pre-built image.
Whether to skip the repository checkout phase. This is useful for steps that use a pre-built image and will fail if there is no pre-built image.

**Important**: as the code repository will not be available in the step, you need to ensure that the docker compose file(s) are present in some way (like using artifacts)

### `skip-pull` (optional, run only)

Completely avoid running any `pull` command. Images being used will need to be present in the machine from before or have been built in the same step. Could be useful to avoid hitting rate limits when you can be sure the operation is unnecessary. Note that it is possible other commands run in the plugin's lifecycle will trigger a pull of necessary images.

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

Expand Down
2 changes: 1 addition & 1 deletion commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ elif [[ ${#pull_services[@]} -eq 1 ]] ; then
fi

# Pull down specified services
if [[ ${#pull_services[@]} -gt 0 ]] ; then
if [[ ${#pull_services[@]} -gt 0 ]] && [[ "$(plugin_read_config SKIP_PULL "false")" != "true" ]]; then
echo "~~~ :docker: Pulling services ${pull_services[0]}"
retry "$pull_retries" run_docker_compose "${pull_params[@]}"
fi
Expand Down
27 changes: 15 additions & 12 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ configuration:
type: string
rm:
type: boolean
skip-pull:
type: boolean
upload-container-logs:
type: string
propagate-uid-gid:
Expand All @@ -96,21 +98,22 @@ configuration:
- push
additionalProperties: false
dependencies:
pull: [ run ]
image-repository: [ build ]
image-name: [ build ]
ansi: [ run ]
cache-from: [ build ]
dependencies: [ run ]
env: [ run ]
environment: [ run ]
push-retries: [ push ]
cache-from: [ build ]
volumes: [ run ]
expand-volume-vars: [ volumes ]
image-repository: [ build ]
image-name: [ build ]
leave-volumes: [ run ]
use-aliases: [ run ]
dependencies: [ run ]
ansi: [ run ]
mount-buildkite-agent: [ run ]
propagate-uid-gid: [ run ]
pull: [ run ]
push-retries: [ push ]
skip-pull: [ run ]
tty: [ run ]
workdir: [ run ]
use-aliases: [ run ]
user: [ run ]
propagate-uid-gid: [ run ]
mount-buildkite-agent: [ run ]
volumes: [ run ]
workdir: [ run ]
50 changes: 25 additions & 25 deletions tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load '../lib/shared'
stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull myservice : echo built myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

unstub docker-compose
assert_success
Expand All @@ -33,7 +33,7 @@ load '../lib/shared'
stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull --no-cache myservice : echo built myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -50,7 +50,7 @@ load '../lib/shared'
stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull --parallel myservice : echo built myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -68,7 +68,7 @@ load '../lib/shared'
stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -85,7 +85,7 @@ load '../lib/shared'
stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull myservice : echo built myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -106,7 +106,7 @@ load '../lib/shared'
stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand Down Expand Up @@ -134,7 +134,7 @@ load '../lib/shared'
"meta-data set docker-compose-plugin-built-image-tag-myservice-1 my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice-1" \
"meta-data set docker-compose-plugin-built-image-tag-myservice-2 my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice-2"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand Down Expand Up @@ -163,7 +163,7 @@ load '../lib/shared'
stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -188,7 +188,7 @@ load '../lib/shared'
stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -214,7 +214,7 @@ load '../lib/shared'
stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml-tests/composefiles/docker-compose.v2.1.yml my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -240,7 +240,7 @@ load '../lib/shared'
"meta-data set docker-compose-plugin-built-image-tag-myservice1 my.repository/llamas:test-myservice1-build-1 : echo set image metadata for myservice1" \
"meta-data set docker-compose-plugin-built-image-tag-myservice2 my.repository/llamas:test-myservice2-build-1 : echo set image metadata for myservice2"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built all services"
Expand All @@ -258,7 +258,7 @@ load '../lib/shared'
export BUILDKITE_PIPELINE_SLUG=test
export BUILDKITE_BUILD_NUMBER=1

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_failure
assert_output --partial "Compose file versions 2.0 and above"
Expand All @@ -278,7 +278,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image"
Expand All @@ -300,7 +300,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull --no-cache helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
refute_output --partial "pulled cache image"
Expand All @@ -324,7 +324,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image"
Expand Down Expand Up @@ -355,7 +355,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image build-target"
Expand Down Expand Up @@ -392,7 +392,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image build-target-latest"
Expand Down Expand Up @@ -431,7 +431,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image build-target-latest"
Expand Down Expand Up @@ -463,7 +463,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image"
Expand All @@ -488,7 +488,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "my.repository/myservice_cache:latest will not be used as a cache for helloworld"
Expand All @@ -512,7 +512,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull hello-world : echo built hello-world"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image"
Expand Down Expand Up @@ -564,7 +564,7 @@ load '../lib/shared'
stub docker-compose \
"-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "pulled cache image"
Expand All @@ -589,7 +589,7 @@ load '../lib/shared'
stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice my.repository/llamas:my-llamas-image : echo set image metadata for myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand All @@ -615,7 +615,7 @@ load '../lib/shared'
stub buildkite-agent \
"meta-data set docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v3.2.yml my.repository/llamas:my-llamas-image : echo set image metadata for myservice"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
Expand Down Expand Up @@ -643,7 +643,7 @@ load '../lib/shared'
"meta-data set docker-compose-plugin-built-image-tag-myservice1 my.repository/llamas:my-llamas-image-1 : echo set image metadata for myservice1" \
"meta-data set docker-compose-plugin-built-image-tag-myservice2 my.repository/llamas:my-llamas-image-2 : echo set image metadata for myservice2"

run $PWD/hooks/command
run "$PWD"/hooks/command

assert_success
assert_output --partial "built all services"
Expand Down
Loading

0 comments on commit 9a55963

Please sign in to comment.