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
Logout rework #73
Merged
Merged
Logout rework #73
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
787f427
Updated desired configuration
toote 5462fab
Updated documentation (and cleaned it up a bit)
toote 68795fd
Added new hooks for logout and job isolation
toote 4f70c43
Renamed test files for easier adding of more tests
toote 75a38e1
Refactored tests and added a few more
toote 5a5bef1
Refactored tests and added a few more
toote fe6427b
Corrected issues with pre-exit hooks
toote bba3ed6
enable shellchecks on tests as well
toote 1fde661
Added tests on pre-exit hook as well
toote c3d6729
Remove tests from shellcheck (see https://github.com/koalaman/shellch…
toote 6b04fab
Remove unnecessary option
toote bf630e2
Consider environment isolation and disable logout (with necessary war…
toote 5dcf07e
Update tests for the new behaviour
toote File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
# a clean docker config for each job, for improved isolation | ||
if [ "${BUILDKITE_PLUGIN_DOCKER_LOGIN_ISOLATE_CONFIG:-true}" = "true" ]; then | ||
BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG=$(mktemp -d) | ||
export BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG | ||
export DOCKER_CONFIG="$BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
logout_args=(logout) | ||
|
||
if [ -n "${BUILDKITE_PLUGIN_DOCKER_LOGIN_SERVER:-}" ]; then | ||
logout_args+=("${BUILDKITE_PLUGIN_DOCKER_LOGIN_SERVER}") | ||
fi | ||
|
||
if [ "${BUILDKITE_PLUGIN_DOCKER_LOGIN_DISABLE_LOGOUT:-false}" = "false" ]; then | ||
docker "${logout_args[@]}" | ||
fi | ||
|
||
if [ "${BUILDKITE_PLUGIN_DOCKER_LOGIN_ISOLATE_CONFIG:-true}" = "true" ] && | ||
[ -d "${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" ] ; then | ||
rm -rf "${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
name: Docker Login | ||
description: Login to Docker registries in your build steps | ||
author: https://github.com/lox | ||
author: https://github.com/buildkite | ||
requirements: | ||
- bash | ||
- docker | ||
configuration: | ||
properties: | ||
username: | ||
type: string | ||
server: | ||
type: string | ||
disable-logout: | ||
type: boolean | ||
isolate-config: | ||
type: boolean | ||
keep-config-file: | ||
type: boolean | ||
password-env: | ||
type: string | ||
retries: | ||
type: number | ||
default: 0 | ||
server: | ||
type: string | ||
username: | ||
type: string | ||
required: | ||
- username |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "${BATS_PLUGIN_PATH}/load.bash" | ||
|
||
# export DOCKER_STUB_DEBUG=/dev/tty | ||
|
||
setup() { | ||
export BUILDKITE_PLUGIN_DOCKER_LOGIN_USERNAME="blah" | ||
export DOCKER_LOGIN_PASSWORD="llamas" | ||
} | ||
|
||
@test "Missing required parameter fails" { | ||
unset BUILDKITE_PLUGIN_DOCKER_LOGIN_USERNAME | ||
|
||
run "$PWD/hooks/pre-command" | ||
|
||
assert_failure | ||
} | ||
|
||
@test "Login to single registry with default password" { | ||
stub docker \ | ||
"login --username blah --password-stdin : echo logging in to docker hub; cat" | ||
|
||
run "${PWD}/hooks/pre-command" | ||
|
||
assert_success | ||
assert_output --partial "logging in to docker hub" | ||
assert_output --partial "llamas" | ||
|
||
unstub docker | ||
} | ||
|
||
@test "Login to single registry with password-env" { | ||
export BUILDKITE_PLUGIN_DOCKER_LOGIN_PASSWORD_ENV="CUSTOM_DOCKER_LOGIN_PASSWORD" | ||
export CUSTOM_DOCKER_LOGIN_PASSWORD="llamas2" | ||
|
||
stub docker \ | ||
"login --username blah --password-stdin : echo logging in to docker hub; cat" | ||
|
||
run "${PWD}/hooks/pre-command" | ||
|
||
assert_success | ||
assert_output --partial "logging in to docker hub" | ||
assert_output --partial "llamas2" | ||
|
||
unstub docker | ||
} | ||
|
||
@test "Multiple retries not used if first command is successful" { | ||
export BUILDKITE_PLUGIN_DOCKER_LOGIN_RETRIES=5 | ||
|
||
stub docker \ | ||
"login --username blah --password-stdin : echo logging in to docker hub; cat" | ||
|
||
run "${PWD}/hooks/pre-command" | ||
|
||
assert_success | ||
assert_output --partial "logging in to docker hub" | ||
assert_output --partial "llamas" | ||
|
||
unstub docker | ||
} | ||
|
||
@test "Multiple retries used until command is successful" { | ||
export BUILDKITE_PLUGIN_DOCKER_LOGIN_RETRIES=5 | ||
|
||
stub docker \ | ||
"login --username blah --password-stdin : exit 1" \ | ||
"login --username blah --password-stdin : exit 1" \ | ||
"login --username blah --password-stdin : echo logging in to docker hub; cat" | ||
|
||
run "${PWD}/hooks/pre-command" | ||
|
||
assert_success | ||
assert_output --partial "logging in to docker hub" | ||
assert_output --partial "llamas" | ||
|
||
unstub docker | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "${BATS_PLUGIN_PATH}/load.bash" | ||
|
||
# export DOCKER_STUB_DEBUG=/dev/tty | ||
|
||
setup () { | ||
export BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG="${BATS_TEST_TMPDIR}/test-folder" | ||
} | ||
|
||
@test "Clean logout execution" { | ||
stub docker \ | ||
"echo got \$# args \$@" | ||
|
||
run "$PWD/hooks/pre-exit" | ||
|
||
assert_success | ||
assert_output --partial 'got 1 args logout' | ||
refute_output --partial "removing ${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" | ||
|
||
unstub docker | ||
} | ||
|
||
@test "Server can be set" { | ||
export BUILDKITE_PLUGIN_DOCKER_LOGIN_SERVER='my-server' | ||
|
||
stub docker \ | ||
"echo got \$# args \$@" | ||
|
||
run "$PWD/hooks/pre-exit" | ||
|
||
assert_success | ||
assert_output --partial 'got 2 args logout my-server' | ||
|
||
unstub docker | ||
} | ||
|
||
@test "Docker config is removed if it exists" { | ||
mkdir "${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" | ||
|
||
stub docker \ | ||
"echo got \$# args \$@" | ||
|
||
stub rm \ | ||
"echo removing \$2" | ||
|
||
run "$PWD/hooks/pre-exit" | ||
|
||
assert_success | ||
assert_output --partial 'got 1 args logout' | ||
assert_output --partial "removing ${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" | ||
|
||
unstub docker | ||
unstub rm | ||
} | ||
|
||
@test "Can prevent from file to be removed" { | ||
mkdir "${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" | ||
export BUILDKITE_PLUGIN_DOCKER_LOGIN_ISOLATE_CONFIG='false' | ||
|
||
stub docker \ | ||
"echo got \$# args \$@" | ||
|
||
run "$PWD/hooks/pre-exit" | ||
|
||
assert_success | ||
assert_output --partial 'got 1 args logout' | ||
refute_output --partial "removing ${BUILDKITE_DOCKER_LOGIN_TEMP_CONFIG}" | ||
|
||
unstub docker | ||
} |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter isn't being used