Skip to content

Commit e14aa29

Browse files
authored
Merge pull request #21 from buildkite/chore_update_example
updated this example to use gomod and tidy
2 parents b5cc3e4 + ba1d353 commit e14aa29

File tree

10 files changed

+72
-57
lines changed

10 files changed

+72
-57
lines changed

.buildkite/pipeline.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
steps:
2-
- name: ":golang:"
3-
command: "./scripts/test.sh"
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.3.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.3.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
427
plugins:
5-
- docker-compose#v5.2.0:
28+
- docker-compose#v5.3.0:
629
run: app
30+
depends_on: quality_assurance

Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
FROM golang:cross
2-
3-
# The golang Docker sets the $GOPATH to be /go
4-
# https://github.com/docker-library/golang/blob/c1baf037d71331eb0b8d4c70cff4c29cf124c5e0/1.4/Dockerfile
5-
RUN mkdir -p /go/src/github.com/buildkite/golang-docker-example
6-
WORKDIR /go/src/github.com/buildkite/golang-docker-example
1+
FROM golang:latest

Readme.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
[![Add to Buildkite](https://buildkite.com/button.svg)](https://buildkite.com/new)
44

5-
This repository is an example on how to test a Golang project through Docker
6-
using Buildkite.
5+
This repository is an example on how to test a [Golang](https://go.dev) project through [Docker](https://docker.com) using Buildkite.
76

87
## Using in your own build pipelines
98

@@ -17,30 +16,6 @@ using Buildkite.
1716
curl -o docker-compose.yml https://raw.githubusercontent.com/buildkite/golang-docker-example/master/docker-compose.yml
1817
```
1918

20-
3. Replace `/go/src/github.com/buildkite/golang-docker-example` in the `Dockerfile` and
21-
`docker-compose.yml` files with your own Golang import path. For example,
22-
if your import path in Golang looks like this:
23-
24-
```go
25-
import (
26-
"github.com/keithpitt/project/sub-package"
27-
)
28-
```
29-
30-
Then you would replace `/go/src/github.com/buildkite/golang-docker-example`
31-
with `/go/src/github.com/keithpitt/project` (note the `sub-package` part of
32-
the import is not included). This path should also match the directory
33-
structure within the `$GOPATH` on your own development machine.
34-
35-
4. Add to your build pipeline and add the `BUILDKITE_DOCKER_COMPOSE_CONTAINER` env:
36-
37-
```yml
38-
steps:
39-
- command: "./scripts/test.sh"
40-
env:
41-
BUILDKITE_DOCKER_COMPOSE_CONTAINER: "app"
42-
```
43-
4419
## License
4520

4621
See [Licence.md](Licence.md) (MIT)

docker-compose.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
app:
2-
build: .
3-
volumes:
4-
- ./:/go/src/github.com/buildkite/golang-docker-example
5-
- /usr/bin/buildkite-agent:/usr/bin/buildkite-agent
6-
environment:
7-
- BUILDKITE_AGENT_ACCESS_TOKEN
8-
- BUILDKITE_JOB_ID
9-
- BUILDKITE_BUILD_ID
10-
- BUILDKITE_BUILD_NUMBER
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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=

logger/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import (
44
"fmt"
55
)
66

7-
func Print(text string) {
8-
fmt.Printf("%s", text)
7+
func Print(a ...any) {
8+
fmt.Println(a...)
99
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import (
55
)
66

77
func main() {
8-
logger.Print("This is the best Golang program, ever!\n")
8+
logger.Print("This is the best Golang program, ever!")
99
}

main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package main
22

33
import (
44
"testing"
5+
56
"github.com/stretchr/testify/assert"
67

7-
"os"
8-
"io"
98
"bytes"
9+
"io"
10+
"os"
1011
)
1112

1213
func TestMain(t *testing.T) {
1314
mainStdout := captureStdout(main)
1415

15-
assert.Equal(t, mainStdout, "This is the best Golang program, ever!\n")
16+
assert.Equal(t, "This is the best Golang program, ever!\n", mainStdout)
1617
}
1718

1819
// Source https://gist.github.com/mindscratch/0faa78bd3c0005d080bf

scripts/test.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)