Skip to content

Commit 269d769

Browse files
authored
Merge pull request #48 from buildkite-plugins/toote_image_versioning
Pin image to actual version (and add option to change it)
2 parents b509b8d + a46aa12 commit 269d769

4 files changed

Lines changed: 50 additions & 10 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ For a full list of features see the [Buildkite Plugin Linter cli tool documentat
1010
steps:
1111
- label: ":sparkles: Lint"
1212
plugins:
13-
- plugin-linter#v3.0.0:
13+
- plugin-linter#v3.1.0:
1414
id: my-org/my-plugin
1515
```
1616
@@ -24,6 +24,10 @@ If you want to run it locally on a command line, see the [Buildkite Plugin Linte
2424

2525
The id of the plugin (e.g. `my-org/my-plugin`)
2626

27+
### `image-version`
28+
29+
The docker tag of the `buildkite/plugin-linter` image to use. Default is `2.0.1`
30+
2731
### `readme` (optional)
2832

2933
The filename of the plugin’s readme. Default is `README.md`

hooks/command

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -euo pipefail
44

5+
if [ -z "${BUILDKITE_PLUGIN_PLUGIN_LINTER_ID:-}" ]; then
6+
echo ':boom: Missing id parameter in plugin configuration'
7+
exit 1
8+
fi
9+
510
echo "--- :docker: Fetching the latest buildkite/plugin-linter"
611

712
docker pull buildkite/plugin-linter
@@ -15,8 +20,10 @@ args=(
1520
"--env" "PLUGIN_ID=$BUILDKITE_PLUGIN_PLUGIN_LINTER_ID"
1621
)
1722

23+
TAG=${BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION:-v2.0.1}
24+
1825
if [[ -n "${BUILDKITE_PLUGIN_PLUGIN_LINTER_README:-}" ]] ; then
1926
args+=("--env" "PLUGIN_README=$BUILDKITE_PLUGIN_PLUGIN_LINTER_README")
2027
fi
2128

22-
docker run "${args[@]}" buildkite/plugin-linter
29+
docker run "${args[@]}" buildkite/plugin-linter:"${TAG}"

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ configuration:
77
properties:
88
id:
99
type: string
10+
image-version:
11+
type: string
1012
readme:
1113
type: string
1214
required:

tests/command.bats

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
#!/usr/bin/env bats
22

3-
load '/usr/local/lib/bats/load.bash'
4-
53
# Uncomment the following to get more detail on failures of stubs
64
# export DOCKER_STUB_DEBUG=/dev/tty
75

8-
@test "Runs the linter via Docker" {
6+
setup() {
7+
load "${BATS_PLUGIN_PATH}/load.bash"
8+
99
export BUILDKITE_PLUGIN_PLUGIN_LINTER_ID=my-plugin
10+
# defining specific version to make all the tests not dependent on default
11+
export BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION='latest'
12+
}
13+
14+
@test "Missing id parameter is a failure" {
15+
unset BUILDKITE_PLUGIN_PLUGIN_LINTER_ID
16+
17+
run "$PWD"/hooks/command
1018

19+
assert_failure
20+
assert_output --partial 'Missing id parameter in plugin configuration'
21+
}
22+
23+
@test "Runs the linter via Docker" {
1124
stub docker \
1225
"pull buildkite/plugin-linter : echo pulled image" \
13-
"run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter : echo linted"
26+
"run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter:latest : echo linted"
1427

15-
run $PWD/hooks/command
28+
run "$PWD"/hooks/command
1629

1730
assert_success
1831
assert_output --partial "pulled image"
@@ -21,14 +34,28 @@ load '/usr/local/lib/bats/load.bash'
2134
}
2235

2336
@test "Supports the readme option" {
24-
export BUILDKITE_PLUGIN_PLUGIN_LINTER_ID=my-plugin
2537
export BUILDKITE_PLUGIN_PLUGIN_LINTER_README=some-readme.yml
2638

2739
stub docker \
2840
"pull buildkite/plugin-linter : echo pulled image" \
29-
"run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin --env PLUGIN_README=some-readme.yml buildkite/plugin-linter : echo linted"
41+
"run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin --env PLUGIN_README=some-readme.yml buildkite/plugin-linter:latest : echo linted"
42+
43+
run "$PWD"/hooks/command
44+
45+
assert_success
46+
assert_output --partial "pulled image"
47+
assert_output --partial "linted"
48+
unstub docker
49+
}
50+
51+
@test "Support not specifying a tag" {
52+
unset BUILDKITE_PLUGIN_PLUGIN_LINTER_IMAGE_VERSION
53+
54+
stub docker \
55+
"pull buildkite/plugin-linter : echo pulled image" \
56+
"run -it --rm --volume /plugin:/plugin:ro --env PLUGIN_ID=my-plugin buildkite/plugin-linter:v2.0.1 : echo linted"
3057

31-
run $PWD/hooks/command
58+
run "$PWD"/hooks/command
3259

3360
assert_success
3461
assert_output --partial "pulled image"

0 commit comments

Comments
 (0)