Skip to content

Commit

Permalink
Handle images with funky entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
orien committed Oct 3, 2018
1 parent eb7b258 commit e6f4fab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ steps:
- commands/**
- lib/**
- unwrappr/*.sh
- update/*.sh
agents:
queue: "${AGENT_QUEUE}"
4 changes: 3 additions & 1 deletion commands/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ args=(
"--tty"
"--rm"
"--volume" "$PWD:/bundle_update"
"--volume" "$PLUGIN_DIR/update:/update"
"--workdir" "/bundle_update"
"--env" "BUNDLE_APP_CONFIG=/bundle_app_config"
)

while IFS='=' read -r name _ ; do
Expand All @@ -27,7 +29,7 @@ while IFS='=' read -r name _ ; do
fi
done < <(env | sort)

docker run "${args[@]}" "${image}" bundle update "--jobs=$(nproc)"
docker run "${args[@]}" "${image}" /update/update.sh

if git diff-index --quiet HEAD -- Gemfile.lock; then
echo
Expand Down
21 changes: 5 additions & 16 deletions tests/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
load '/usr/local/lib/bats/load.bash'

# Uncomment the following to get more detail on failures of stubs
# export NPROC_STUB_DEBUG=/dev/tty
# export DOCKER_STUB_DEBUG=/dev/tty
# export GIT_STUB_DEBUG=/dev/tty
# export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty

@test "Runs the bundle update via Docker" {
export BUILDKITE_PLUGIN_BUNDLE_UPDATE_UPDATE=true

stub nproc ": echo 17"
stub docker \
"pull ruby:slim : echo pulled image" \
"run --interactive --tty --rm --volume /plugin:/bundle_update --workdir /bundle_update ruby:slim bundle update --jobs=17 : echo bundle updated"
"run --interactive --tty --rm --volume /plugin:/bundle_update --volume /plugin/hooks/../update:/update --workdir /bundle_update --env BUNDLE_APP_CONFIG=/bundle_app_config ruby:slim /update/update.sh : echo bundle updated"
stub git "diff-index --quiet HEAD -- Gemfile.lock : exit 1"
stub buildkite-agent "meta-data set bundle-update-plugin-changes true : echo meta-data set"

Expand All @@ -23,7 +21,6 @@ load '/usr/local/lib/bats/load.bash'
assert_success
assert_output --partial "pulled image"
assert_output --partial "bundle updated"
unstub nproc
unstub docker
unstub git
unstub buildkite-agent
Expand All @@ -32,18 +29,16 @@ load '/usr/local/lib/bats/load.bash'
@test "Sets buildkite metadata when changes are found" {
export BUILDKITE_PLUGIN_BUNDLE_UPDATE_UPDATE=true

stub nproc ": echo 17"
stub docker \
"pull ruby:slim : echo pulled image" \
"run --interactive --tty --rm --volume /plugin:/bundle_update --workdir /bundle_update ruby:slim bundle update --jobs=17 : echo bundle updated"
"run --interactive --tty --rm --volume /plugin:/bundle_update --volume /plugin/hooks/../update:/update --workdir /bundle_update --env BUNDLE_APP_CONFIG=/bundle_app_config ruby:slim /update/update.sh : echo bundle updated"
stub git "diff-index --quiet HEAD -- Gemfile.lock : exit 1"
stub buildkite-agent "meta-data set bundle-update-plugin-changes true : echo meta-data set"

run $PWD/hooks/command

assert_success
assert_output --partial "meta-data set"
unstub nproc
unstub docker
unstub git
unstub buildkite-agent
Expand All @@ -52,18 +47,16 @@ load '/usr/local/lib/bats/load.bash'
@test "Does not buildkite metadata when no changes are found" {
export BUILDKITE_PLUGIN_BUNDLE_UPDATE_UPDATE=true

stub nproc ": echo 17"
stub docker \
"pull ruby:slim : echo pulled image" \
"run --interactive --tty --rm --volume /plugin:/bundle_update --workdir /bundle_update ruby:slim bundle update --jobs=17 : echo bundle updated"
"run --interactive --tty --rm --volume /plugin:/bundle_update --volume /plugin/hooks/../update:/update --workdir /bundle_update --env BUNDLE_APP_CONFIG=/bundle_app_config ruby:slim /update/update.sh : echo bundle updated"
stub git "diff-index --quiet HEAD -- Gemfile.lock : exit 0"
stub buildkite-agent "meta-data set bundle-update-plugin-changes true : echo meta-data set"

run $PWD/hooks/command

assert_success
refute_output --partial "meta-data set"
unstub nproc
unstub docker
unstub git
}
Expand All @@ -72,10 +65,9 @@ load '/usr/local/lib/bats/load.bash'
export BUILDKITE_PLUGIN_BUNDLE_UPDATE_UPDATE=true
export BUILDKITE_PLUGIN_BUNDLE_UPDATE_IMAGE=my-image

stub nproc ": echo 17"
stub docker \
"pull my-image : echo pulled image" \
"run --interactive --tty --rm --volume /plugin:/bundle_update --workdir /bundle_update my-image bundle update --jobs=17 : echo bundle updated"
"run --interactive --tty --rm --volume /plugin:/bundle_update --volume /plugin/hooks/../update:/update --workdir /bundle_update --env BUNDLE_APP_CONFIG=/bundle_app_config my-image /update/update.sh : echo bundle updated"
stub git "diff-index --quiet HEAD -- Gemfile.lock : exit 1"
stub buildkite-agent "meta-data set bundle-update-plugin-changes true : echo meta-data set"

Expand All @@ -84,7 +76,6 @@ load '/usr/local/lib/bats/load.bash'
assert_success
assert_output --partial "pulled image"
assert_output --partial "bundle updated"
unstub nproc
unstub docker
unstub git
unstub buildkite-agent
Expand All @@ -96,10 +87,9 @@ load '/usr/local/lib/bats/load.bash'
export BUNDLE_RUBYGEMS__EXAMPLE__NET=secret2
export NOT_AS_BUNDLE_VAR=secret3

stub nproc ": echo 17"
stub docker \
"pull ruby:slim : echo pulled image" \
"run --interactive --tty --rm --volume /plugin:/bundle_update --workdir /bundle_update --env BUNDLE_RUBYGEMS__EXAMPLE__COM --env BUNDLE_RUBYGEMS__EXAMPLE__NET ruby:slim bundle update --jobs=17 : echo bundle updated"
"run --interactive --tty --rm --volume /plugin:/bundle_update --volume /plugin/hooks/../update:/update --workdir /bundle_update --env BUNDLE_APP_CONFIG=/bundle_app_config --env BUNDLE_RUBYGEMS__EXAMPLE__COM --env BUNDLE_RUBYGEMS__EXAMPLE__NET ruby:slim /update/update.sh : echo bundle updated"
stub git "diff-index --quiet HEAD -- Gemfile.lock : exit 1"
stub buildkite-agent "meta-data set bundle-update-plugin-changes true : echo meta-data set"

Expand All @@ -108,7 +98,6 @@ load '/usr/local/lib/bats/load.bash'
assert_success
assert_output --partial "pulled image"
assert_output --partial "bundle updated"
unstub nproc
unstub docker
unstub git
unstub buildkite-agent
Expand Down
5 changes: 5 additions & 0 deletions update/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cd /bundle_update
bundle update --jobs="$(nproc)"

0 comments on commit e6f4fab

Please sign in to comment.