├── .buildkite ├── pipeline.yml └── template.yml ├── .gitignore ├── Dockerfile ├── Licence.md ├── Readme.md ├── docker-compose.yml ├── go.mod ├── go.sum ├── logger └── logger.go ├── main.go ├── main_test.go └── renovate.json /.buildkite/pipeline.yml: -------------------------------------------------------------------------------- 1 | steps: 2 | # group up all the steps that are related to the quality assurance of the code 3 | - group: ':mag: QA' 4 | id: quality_assurance 5 | steps: 6 | - key: lint 7 | label: ':golang: vet' 8 | command: go vet ./... 9 | plugins: 10 | - docker-compose#v5.4.0: 11 | run: app 12 | - key: test 13 | label: ':golang: test' 14 | command: 15 | - go test -v -count=1 -cover ./... -coverprofile=coverage.txt -covermode=atomic 16 | artifact_paths: 17 | - 'coverage.txt' # upload the coverage report as an artifact 18 | plugins: 19 | - docker-compose#v5.4.0: 20 | run: app 21 | # build the application after the quality assurance steps are done 22 | - key: build 23 | label: ':golang: build' 24 | command: go build -o dist/app 25 | artifact_paths: 26 | - 'dist/app' # upload the built application as an artifact 27 | plugins: 28 | - docker-compose#v5.4.0: 29 | run: app 30 | depends_on: quality_assurance -------------------------------------------------------------------------------- /.buildkite/template.yml: -------------------------------------------------------------------------------- 1 | # Used by the 'Add to Buildkite' button in the readme 2 | name: "Golang Docker Example" 3 | steps: 4 | - label: ":pipeline:" 5 | command: "buildkite-agent pipeline upload" 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest -------------------------------------------------------------------------------- /Licence.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Buildkite Pty Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Buildkite Golang Docker Example 2 | 3 | [![Add to Buildkite](https://buildkite.com/button.svg)](https://buildkite.com/new) 4 | 5 | This repository is an example on how to test a [Golang](https://go.dev) project through [Docker](https://docker.com) using Buildkite. 6 | 7 | ## Using in your own build pipelines 8 | 9 | 1. Ensure `docker-compose` is installed on your build system. For details on how to do this, see: https://docs.docker.com/compose/install/ 10 | 11 | 2. Use our `Dockerfile` and `docker-compose.yml` files as defaults: 12 | 13 | ```sh 14 | cd /your/golang/repo 15 | curl -o Dockerfile https://raw.githubusercontent.com/buildkite/golang-docker-example/master/Dockerfile 16 | curl -o docker-compose.yml https://raw.githubusercontent.com/buildkite/golang-docker-example/master/docker-compose.yml 17 | ``` 18 | 19 | ## License 20 | 21 | See [Licence.md](Licence.md) (MIT) 22 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | app: 3 | build: . 4 | volumes: 5 | - ./:/work:cached 6 | - ~/gocache:/gocache 7 | - ~/gomodcache:/gomodcache 8 | working_dir: /work 9 | environment: 10 | - BUILDKITE_AGENT_ACCESS_TOKEN 11 | - BUILDKITE_JOB_ID 12 | - BUILDKITE_BUILD_ID 13 | - BUILDKITE_BUILD_NUMBER 14 | - GOCACHE=/gocache 15 | - GOMODCACHE=/gomodcache -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/buildkite/golang-docker-example 2 | 3 | go 1.21 4 | 5 | require github.com/stretchr/testify v1.9.0 6 | 7 | require ( 8 | github.com/davecgh/go-spew v1.1.1 // indirect 9 | github.com/pmezard/go-difflib v1.0.0 // indirect 10 | gopkg.in/yaml.v3 v3.0.1 // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 6 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 7 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 8 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 9 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 10 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 11 | -------------------------------------------------------------------------------- /logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func Print(a ...any) { 8 | fmt.Println(a...) 9 | } 10 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/buildkite/golang-docker-example/logger" 5 | ) 6 | 7 | func main() { 8 | logger.Print("This is the best Golang program, ever!") 9 | } 10 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | 8 | "bytes" 9 | "io" 10 | "os" 11 | ) 12 | 13 | func TestMain(t *testing.T) { 14 | mainStdout := captureStdout(main) 15 | 16 | assert.Equal(t, "This is the best Golang program, ever!\n", mainStdout) 17 | } 18 | 19 | // Source https://gist.github.com/mindscratch/0faa78bd3c0005d080bf 20 | func captureStdout(f func()) string { 21 | old := os.Stdout 22 | r, w, _ := os.Pipe() 23 | os.Stdout = w 24 | 25 | f() 26 | 27 | w.Close() 28 | os.Stdout = old 29 | 30 | var buf bytes.Buffer 31 | io.Copy(&buf, r) 32 | return buf.String() 33 | } 34 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | --------------------------------------------------------------------------------