Skip to content

Commit

Permalink
Merge pull request #444 from buildkite-plugins/mount-job-socket
Browse files Browse the repository at this point in the history
Mount agent job socket/token
  • Loading branch information
jradtilbrook authored Jun 17, 2024
2 parents 4151607 + 52fd24d commit 1adacb1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ if [[ -n "${BUILDKITE_AGENT_BINARY_PATH:-}" ]] ; then
"-e" "BUILDKITE_AGENT_ACCESS_TOKEN"
"-v" "$BUILDKITE_AGENT_BINARY_PATH:/usr/bin/buildkite-agent"
)
if [[ -n "${BUILDKITE_AGENT_JOB_API_SOCKET:-}" ]] ; then
run_params+=(
"-e" "BUILDKITE_AGENT_JOB_API_SOCKET"
"-e" "BUILDKITE_AGENT_JOB_API_TOKEN"
"-v" "$BUILDKITE_AGENT_JOB_API_SOCKET:$BUILDKITE_AGENT_JOB_API_SOCKET"
)
fi
fi

# Optionally expose service ports
Expand Down
5 changes: 3 additions & 2 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,11 @@ cmd3"
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_BUILDKITE_AGENT=true
export BUILDKITE_AGENT_JOB_API_SOCKET=$BATS_MOCK_TMPDIR/agent.sock

stub docker \
"compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \
"compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e BUILDKITE_JOB_ID -e BUILDKITE_BUILD_ID -e BUILDKITE_AGENT_ACCESS_TOKEN -v $BATS_MOCK_TMPDIR/bin/buildkite-agent:/usr/bin/buildkite-agent myservice : echo ran myservice"
"compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e BUILDKITE_JOB_ID -e BUILDKITE_BUILD_ID -e BUILDKITE_AGENT_ACCESS_TOKEN -v $BATS_MOCK_TMPDIR/bin/buildkite-agent:/usr/bin/buildkite-agent -e BUILDKITE_AGENT_JOB_API_SOCKET -e BUILDKITE_AGENT_JOB_API_TOKEN -v $BUILDKITE_AGENT_JOB_API_SOCKET:$BATS_MOCK_TMPDIR/agent.sock myservice : echo ran myservice"

stub buildkite-agent \
"meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1"
Expand Down Expand Up @@ -1219,7 +1220,7 @@ cmd3"

@test "Run with --quiet-pull" {
export BUILDKITE_COMMAND="echo hello world"

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_QUIET_PULL=true
Expand Down
4 changes: 2 additions & 2 deletions tests/v1/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ cmd3"
assert_success
assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice"
assert_output --partial "ran myservice without pull"

unstub docker-compose
unstub buildkite-agent
}
Expand Down Expand Up @@ -1246,7 +1246,7 @@ cmd3"

@test "Run waiting for dependencies" {
export BUILDKITE_COMMAND="echo hello world"

export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false
export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WAIT=true
Expand Down

0 comments on commit 1adacb1

Please sign in to comment.