Skip to content

Commit

Permalink
Merge pull request #346 from buildkite-plugins/toote_target_issue-231
Browse files Browse the repository at this point in the history
Add `target` option
  • Loading branch information
pzeballos authored Oct 15, 2022
2 parents 0cbd316 + dfc2402 commit 3d4a5a0
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 68 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Whether to skip the repository checkout phase. This is useful for steps that use

### `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.
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 Expand Up @@ -508,6 +508,12 @@ This option can also be configured on the agent machine using the environment va

A list of images to pull caches from in the format `service:index.docker.io/myorg/myrepo/myapp:tag` before building, ignoring any failures. If multiple images are listed for a service, the first one to successfully pull will be used. Requires docker-compose file version `3.2+`.

### `target` (optional, build only)

Allow for intermediate builds with `--target VALUE` options.

Note that there is a single build command run for all services so the target value will apply to all of them.

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

A list of volumes to mount into the container. If a matching volume exists in the Docker Compose config file, this option will override that definition.
Expand Down
5 changes: 5 additions & 0 deletions commands/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ if [[ "$(plugin_read_config BUILD_PARALLEL "false")" == "true" ]] ; then
build_params+=(--parallel)
fi

target="$(plugin_read_config TARGET "")"
if [[ -n "$target" ]] ; then
build_params+=(--target "$target")
fi

while read -r arg ; do
[[ -n "${arg:-}" ]] && build_params+=("--build-arg" "${arg}")
done <<< "$(plugin_read_list ARGS)"
Expand Down
87 changes: 45 additions & 42 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,83 @@ configuration:
push:
type: [ string, array ]
minimum: 1
pull:
ansi:
type: boolean
args:
type: [ string, array ]
minimum: 1
config:
build-alias:
type: [ string, array ]
minimum: 1
env:
cache-from:
type: [ string, array ]
minimum: 1
environment:
cli-version:
type: string
enum:
- 1
- 2
command:
type: array
config:
type: [ string, array ]
minimum: 1
args:
dependencies:
type: boolean
entrypoint:
type: string
env:
type: [ string, array ]
minimum: 1
build-alias:
environment:
type: [ string, array ]
minimum: 1
expand-volume-vars:
type: boolean
image-repository:
type: string
image-name:
type: [ string, array ]
pull-retries:
type: integer
push-retries:
type: integer
cache-from:
type: [ string, array ]
minimum: 1
volumes:
type: [ string, array ]
minimum: 1
expand-volume-vars:
leave-volumes:
type: boolean
command:
type: array
skip-checkout:
mount-buildkite-agent:
type: boolean
leave-volumes:
mount-ssh-agent:
type: boolean
no-cache:
type: boolean
use-aliases:
propagate-environment:
type: boolean
tty:
propagate-uid-gid:
type: boolean
dependencies:
pull:
type: [ string, array ]
minimum: 1
pull-retries:
type: integer
push-retries:
type: integer
rm:
type: boolean
ansi:
skip-checkout:
type: boolean
verbose:
skip-pull:
type: boolean
workdir:
target:
type: string
rm:
type: boolean
skip-pull:
tty:
type: boolean
upload-container-logs:
type: string
propagate-uid-gid:
type: boolean
propagate-environment:
type: boolean
mount-ssh-agent:
use-aliases:
type: boolean
mount-buildkite-agent:
verbose:
type: boolean
entrypoint:
type: string
cli-version:
volumes:
type: [ string, array ]
minimum: 1
workdir:
type: string
enum:
- 1
- 2
anyOf:
- required:
- run
Expand All @@ -112,6 +114,7 @@ configuration:
pull: [ run ]
push-retries: [ push ]
skip-pull: [ run ]
target: [ build ]
tty: [ run ]
use-aliases: [ run ]
user: [ run ]
Expand Down
24 changes: 22 additions & 2 deletions tests/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,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 \* : echo built \$9"

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

assert_success
assert_output --partial "pulled cache image"
Expand Down Expand Up @@ -649,7 +649,7 @@ load '../lib/shared'
@test "Build with an invalid image-name (too long) " {
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
# numbers from 1 to 69 result in 129 characters
# shellcheck disable=SC2155 # numbers from 1 to 69 result in 129 characters
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_NAME="$(seq 69 | tr -d "\n")"
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_REPOSITORY=my.repository/llamas
export BUILDKITE_BUILD_NUMBER=1
Expand Down Expand Up @@ -714,3 +714,23 @@ load '../lib/shared'
unstub docker-compose
unstub buildkite-agent
}

@test "Build with target" {
export BUILDKITE_BUILD_NUMBER=1
export BUILDKITE_JOB_ID=1111
export BUILDKITE_PIPELINE_SLUG=test

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TARGET=intermediate

stub docker-compose \
"-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull --target \* \* : echo built \${11} with target \${10}"

run "$PWD"/hooks/command

assert_success
assert_output --partial "built myservice"
assert_output --partial "with target intermediate"

unstub docker-compose
}
Loading

0 comments on commit 3d4a5a0

Please sign in to comment.