|
| 1 | +# Buildkite Golang Docker Example |
| 2 | + |
| 3 | +This repository is an example on how to test a Golang project through Docker |
| 4 | +using Buildkite. |
| 5 | + |
| 6 | +[Add this example to your Buildkite organization](https://buildkite.com/new) |
| 7 | + |
| 8 | +## Using in your own build pipelines |
| 9 | + |
| 10 | +We've wrapped up the `$GOPATH` wrangling required to get Golang projects to run |
| 11 | +into a `pre-command` hook which you can see here: |
| 12 | +https://github.com/buildkite/golang-example/blob/master/.buildkite/hooks/pre-command |
| 13 | + |
| 14 | +To use in your own build pipelines: |
| 15 | + |
| 16 | +1. Ensure `docker-compose` is installed on your build system. For details on how to do this, see: https://docs.docker.com/compose/install/ |
| 17 | + |
| 18 | +2. Use our `Dockerfile` and `docker-compose.yml` files as defaults: |
| 19 | + |
| 20 | + ```sh |
| 21 | + cd /your/golang/repo |
| 22 | + curl -o Dockerfile https://raw.githubusercontent.com/buildkite/golang-golang-example/master/Dockerfile |
| 23 | + curl -o docker-compose.yml https://raw.githubusercontent.com/buildkite/golang-golang-example/master/docker-compose.yml |
| 24 | + ``` |
| 25 | + |
| 26 | +3. Replace `/go/src/github.com/buildkite/golang-docker-example` in the `Dockerfile` and |
| 27 | + `docker-compose.yml` files with your own Golang import path. For example, |
| 28 | + if your import path in Golang looks like this: |
| 29 | + |
| 30 | + ```go |
| 31 | + import ( |
| 32 | + "github.com/keithpitt/project/sub-package" |
| 33 | + ) |
| 34 | + ``` |
| 35 | + |
| 36 | + Then you would replace `/go/src/github.com/buildkite/golang-docker-example` |
| 37 | + with `/go/src/github.com/keithpitt/project` (note the `sub-package` part of |
| 38 | + the import is not included). This path should also match the directory |
| 39 | + structure within the `$GOPATH` on your own development machine. |
| 40 | + |
| 41 | +4. Add to your build pipeline and add the `BUILDKITE_DOCKER_COMPOSE_CONTAINER` env: |
| 42 | + |
| 43 | + ```yml |
| 44 | + steps: |
| 45 | + - command: "./scripts/test.sh" |
| 46 | + env: |
| 47 | + BUILDKITE_DOCKER_COMPOSE_CONTAINER: "app" |
| 48 | + ``` |
| 49 | +
|
| 50 | +## License |
| 51 | +
|
| 52 | +See [Licence.md](Licence.md) (MIT) |
0 commit comments