diff --git a/README.md b/README.md index fbad352e..49908d27 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,13 @@ volumes: ## Environment -By default, docker-compose makes whatever environment variables it gets available for -interpolation of docker-compose.yml, but it doesn't pass them in to your containers. +By default, docker-compose makes whatever environment variables it gets available for +interpolation of docker-compose.yml, but it doesn't pass them in to your containers. You can use the [environent key in docker-compose.yml](https://docs.docker.com/compose/environment-variables/) to either set specific environment vars or "pass through" environment variables from outside docker-compose. -If you want to add extra environment above what is declared in your `docker-compose.yml`, +If you want to add extra environment above what is declared in your `docker-compose.yml`, this plugin offers a `environment` block of it's own: ```yml @@ -221,7 +221,7 @@ The file name of the Docker Compose configuration file to use. Can also be a lis Default: `docker-compose.yml` -### `image-repository` (optional) +### `image-repository` (optional, build only) The repository for pushing and pulling pre-built images, same as the repository location you would use for a `docker push`, for example `"index.docker.io/org/repo"`. Each image is tagged to the specific build so you can safely share the same image repository for any number of projects and builds. @@ -229,9 +229,7 @@ The default is `""` which only builds images on the local Docker host doing the This option can also be configured on the agent machine using the environment variable `BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_REPOSITORY`. -Note: this option can only be specified on a `build` step. - -### `image-name` (optional) +### `image-name` (optional, build only) The name to use when tagging pre-built images. @@ -239,12 +237,10 @@ The default is `${BUILDKITE_PIPELINE_SLUG}-${BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUI Note: this option can only be specified on a `build` step. -### `env` or `environment` (optional) +### `env` or `environment` (optional, run only) A list of either KEY or KEY=VALUE that are passed through as environment variables to the container. -Note: this option can only be specified on a `run` step. - ### `pull-retries` (optional) A number of times to retry failed docker pull. Defaults to 0. @@ -263,21 +259,23 @@ A list of images to pull caches from in the format `service:index.docker.io/org/ Note: this option can only be specified on a `build` step. -### `leave-volumes` (optional) +### `leave-volumes` (optional, run only) Prevent the removal of volumes after the command has been run. The default is `false`. -Note: this option can only be specified on a `run` step. - -### `no-cache` (optional) +### `no-cache` (optional, build only) Sets the build step to run with `--no-cache`, causing Docker Compose to not use any caches when building the image. The default is `false`. -Note: this option can only be specified on a `build` step. +### `tty` (optional, run only) + +If set to false, doesn't allocate a TTY. This is useful in some situations where TTY's aren't supported, for instance windows. + +The default is `true`. ### `verbose` (optional) diff --git a/hooks/commands/run.sh b/hooks/commands/run.sh index 5101ca86..e8f77df2 100755 --- a/hooks/commands/run.sh +++ b/hooks/commands/run.sh @@ -50,6 +50,11 @@ done <<< "$(printf '%s\n%s' \ "$(plugin_read_list ENV)" \ "$(plugin_read_list ENVIRONMENT)")" +# Optionally disable allocating a TTY +if [[ "$(plugin_read_config TTY "true")" == "false" ]] ; then + run_params+=(-T) +fi + run_params+=("$service_name") ( diff --git a/tests/run.bats b/tests/run.bats index 6934ffdc..820c4f15 100644 --- a/tests/run.bats +++ b/tests/run.bats @@ -160,3 +160,28 @@ load '../lib/run' unstub docker-compose unstub buildkite-agent } + +@test "Run without a TTY" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND=pwd + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TTY=false + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T myservice pwd : echo ran myservice without tty" + + stub buildkite-agent \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" + + run $PWD/hooks/command + + assert_success + assert_output --partial "ran myservice without tty" + unstub docker-compose + unstub buildkite-agent +}