Skip to content
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

Add a tty option to run #97

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -221,30 +221,26 @@ 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.

The default is `""` which only builds images on the local Docker host doing the build.

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.

The default is `${BUILDKITE_PIPELINE_SLUG}-${BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD}-build-${BUILDKITE_BUILD_NUMBER}`, for example `my-project-web-build-42`.

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.
Expand All @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions hooks/commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

# append command tokens if there are any. We do this to avoid word splitting
Expand Down
25 changes: 25 additions & 0 deletions tests/run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,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
}