Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
toolmantim committed May 26, 2017
0 parents commit 22c90b6
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
steps:
- label: run bats tests
command: tests/
plugins:
${BUILDKITE_REPO}#${BUILDKITE_COMMIT}:
run: tests
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM lucor/bats

ENV LIBS_BATS_MOCK_VERSION "1.0.1"
RUN mkdir -p /usr/local/lib/bats/bats-mock \
&& curl -sSL https://github.com/lox/bats-mock/archive/master.tar.gz -o /tmp/bats-mock.tgz \
&& tar -zxf /tmp/bats-mock.tgz -C /usr/local/lib/bats/bats-mock --strip 1 \
&& printf 'source "%s"\n' "/usr/local/lib/bats/bats-mock/stub.bash" >> /usr/local/lib/bats/load.bash \
&& rm -rf /tmp/bats-mock.tgz

RUN apk --no-cache add ncurses

WORKDIR /app
ENTRYPOINT ["/usr/local/bin/bats"]
CMD ["tests/"]
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2017 Buildkite

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Docker Buildkite Plugin

A simple [Buildkite](https://buildkite.com/) Docker plugin allowing you to run a command in a Docker container. If you need more control, please see the [docker-compose Buildkite Plugin](https://github.com/buildkite-plugins/docker-compose-buildkite-plugin).

## Example

The following pipeline will run `yarn install && yarn run test` inside a Docker container:

```yml
steps:
- command: yarn install && yarn run test
plugins:
docker#v1.0.0:
image: "node:7"
workdir: /app
```
## Configuration
### `image`

The name of the Docker image to use. For example, `node:7`.

### `workdir`

The working directory where the pipeline’s code will be mounted to, and run from, inside the container. For example, `/app`.

## License

MIT (see [LICENSE](LICENSE))
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2'
services:
tests:
build: .
volumes:
- .:/app
10 changes: 10 additions & 0 deletions hooks/command
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail

docker run \
-it \
--rm \
-v "$(pwd):${BUILDKITE_PLUGIN_DOCKER_WORKDIR}" \
"${BUILDKITE_PLUGIN_DOCKER_IMAGE}" \
bash -c "${BUILDKITE_COMMAND}"
7 changes: 7 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "docker",
"description": "Run any CI step in an isolated Docker containers using Docker",
"author": "@buildkite",
"public": true,
"requirements": ["docker"]
}
20 changes: 20 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bats

load '/usr/local/lib/bats/load.bash'

export DOCKER_STUB_DEBUG=/dev/tty

@test "Runs the command using docker" {
export BUILDKITE_PLUGIN_DOCKER_WORKDIR=/app
export BUILDKITE_PLUGIN_DOCKER_IMAGE=image:tag
export BUILDKITE_COMMAND="command1 \"a string\" && command2"

stub docker \
"run -it --rm -v $PWD:/app image:tag bash -c 'command1 \"a string\" && command2' : echo ran command in docker"

run $PWD/hooks/command

unstub docker
assert_success
assert_output --partial "ran command in docker"
}

0 comments on commit 22c90b6

Please sign in to comment.