Skip to content

Commit 4c9c81b

Browse files
committed
Allow running the annotate script outside of Docker
**Why** This might be a weird request, but I'm curious if it's reasonable to provide a non Docker in Docker (dind) option to run this junit-annotate-buildkite-plugin? We have a usecase where we don't have sysbox in the container's runtime environment and there isn't a secure way to run dind (We used to mount docker socket but we've removed it due to the the nature of the sensitive workload). However, we still want to use the plugin. Perhaps it makes sense to add an additional option, assuming that Ruby is in the runtime, to run the junit xml analysis and annotation in the runtime environment w/o dind.
1 parent a7a0cb5 commit 4c9c81b

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ The docker image to use for running the analysis code. Must be a valid image ref
108108

109109
Default: `ruby:3.1-alpine@sha256:a39e26d0598837f08c75a42c8b0886d9ed5cc862c4b535662922ee1d05272fca`
110110

111+
### `run-in-docker` (optional, boolean)
112+
113+
Default: `true`
114+
115+
Controls whether the JUnit processing should run inside a Docker container. When set to `false`, the processing will run directly on the host using the system's Ruby installation.
116+
111117
## Developing
112118

113119
To run testing, shellchecks and plugin linting use use `bk run` with the [Buildkite CLI](https://github.com/buildkite/cli).

hooks/command

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,22 @@ fi
4242
echo "--- :junit: Processing the junits"
4343

4444
set +e
45-
docker \
46-
--log-level "error" \
47-
run \
48-
--rm \
49-
--volume "$artifacts_dir:/junits" \
50-
--volume "$PLUGIN_DIR/ruby:/src" \
51-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
52-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
53-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
54-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED:-}" \
55-
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
56-
> "$annotation_path"
45+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER:-true}" =~ "true" ]]; then
46+
docker \
47+
--log-level "error" \
48+
run \
49+
--rm \
50+
--volume "$artifacts_dir:/junits" \
51+
--volume "$PLUGIN_DIR/ruby:/src" \
52+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
53+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
54+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
55+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SKIPPED:-}" \
56+
"${RUBY_IMAGE}" ruby /src/bin/annotate /junits \
57+
> "$annotation_path"
58+
else
59+
ruby "${PLUGIN_DIR}/ruby/bin/annotate" "${artifacts_dir}" > "$annotation_path"
60+
fi
5761

5862
exit_code=$?
5963
set -e

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ configuration:
3030
type: integer
3131
ruby-image:
3232
type: string
33+
run-in-docker:
34+
type: boolean
3335
required:
3436
- artifacts
3537
additionalProperties: false

tests/command.bats

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,61 @@ DOCKER_STUB_DEFAULT_OPTIONS='--log-level error run --rm --volume \* --volume \*
527527
unstub buildkite-agent
528528
unstub docker
529529
rm "${annotation_input}"
530+
}
531+
532+
@test "runs in docker by default" {
533+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
534+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
535+
536+
stub mktemp \
537+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
538+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
539+
540+
stub buildkite-agent \
541+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
542+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
543+
544+
stub docker \
545+
"${DOCKER_STUB_DEFAULT_OPTIONS} ruby /src/bin/annotate /junits : echo '<details>Failure</details>' && exit 64"
546+
547+
run "$PWD/hooks/command"
548+
549+
assert_success
550+
551+
assert_output --partial "Annotation added with context junit and style error"
552+
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'
553+
554+
unstub mktemp
555+
unstub buildkite-agent
556+
unstub docker
557+
rm "${annotation_input}"
558+
}
559+
560+
@test "does not run in docker when run-in-docker is false" {
561+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS="junits/*.xml"
562+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR=false
563+
export BUILDKITE_PLUGIN_JUNIT_ANNOTATE_RUN_IN_DOCKER=false
564+
565+
stub mktemp \
566+
"-d \* : mkdir -p '$artifacts_tmp'; echo '$artifacts_tmp'" \
567+
"-d \* : mkdir -p '$annotation_tmp'; echo '$annotation_tmp'"
568+
569+
stub buildkite-agent \
570+
"artifact download \* \* : echo Downloaded artifact \$3 to \$4" \
571+
"annotate --context \* --style \* : cat >'${annotation_input}'; echo Annotation added with context \$3 and style \$5, content saved"
572+
573+
stub ruby \
574+
"/plugin/hooks/../ruby/bin/annotate /plugin/${artifacts_tmp} : echo '<details>Failure</details>' && exit 64"
575+
576+
run "$PWD/hooks/command"
577+
578+
assert_success
579+
580+
assert_output --partial "Annotation added with context junit and style error"
581+
assert_equal "$(cat "${annotation_input}")" '<details>Failure</details>'
582+
583+
unstub mktemp
584+
unstub buildkite-agent
585+
unstub ruby
586+
rm "${annotation_input}"
530587
}

0 commit comments

Comments
 (0)