Sample config (using go modules and caching)

This example uses the yaml format and defines a run that will fetch the repository source, restore and save a cache of go modules, build and run it

  1. version: v0
  2. runs:
  3. - name: agola example go run
  4. tasks:
  5. - name: build go 1.12
  6. runtime:
  7. type: pod
  8. arch: amd64
  9. containers:
  10. - image: golang:1.12-stretch
  11. environment:
  12. GO111MODULE: "on"
  13. steps:
  14. - clone:
  15. - restore_cache:
  16. keys:
  17. - cache-sum-{{ md5sum "go.sum" }}
  18. - cache-date-
  19. ## golang image sets GOPATH to /go
  20. dest_dir: /go/pkg/mod/cache
  21. ## This will create a binary called `agola-example-go` under ./bin
  22. - run:
  23. name: build the program
  24. command: go build .
  25. ## Copy the built binary to the workspace
  26. - save_to_workspace:
  27. contents:
  28. - source_dir: .
  29. dest_dir: /bin/
  30. paths:
  31. - agola-example-go
  32. - save_cache:
  33. key: cache-sum-{{ md5sum "go.sum" }}
  34. contents:
  35. - source_dir: /go/pkg/mod/cache
  36. - save_cache:
  37. key: cache-date-{{ year }}-{{ month }}-{{ day }}
  38. contents:
  39. - source_dir: /go/pkg/mod/cache
  40. - name: run
  41. ## This task will run the built binary in the parent task and leverages the workspace capabilities
  42. runtime:
  43. type: pod
  44. arch: amd64
  45. containers:
  46. - image: debian:stretch
  47. steps:
  48. - restore_workspace:
  49. dest_dir: .
  50. - run: ./bin/agola-example-go
  51. depends:
  52. - build go 1.12

Matrix build

This example enhances the above one using the jsonnet format and adds matrix builds based on two go versions and two different architectures

  1. local go_runtime(version, arch) = {
  2. arch: arch,
  3. containers: [
  4. { image: 'golang:' + version + '-stretch' },
  5. ],
  6. };
  7. local task_build_go(version, arch) = {
  8. name: 'build go ' + version + ' ' + arch,
  9. runtime: go_runtime(version, arch),
  10. working_dir: '/go/src/github.com/sorintlab/agola',
  11. environment: {
  12. GO111MODULE: 'on',
  13. },
  14. steps: [
  15. { type: 'clone' },
  16. { type: 'restore_cache', keys: ['cache-sum-{{ md5sum "go.sum" }}', 'cache-date-'], dest_dir: '/go/pkg/mod/cache' },
  17. { type: 'run', name: 'build the program', command: 'go build .' },
  18. { type: 'save_to_workspace', contents: [{ source_dir: '.', dest_dir: '/bin/', paths: ['agola-example-go'] }] },
  19. { type: 'save_cache', key: 'cache-sum-{{ md5sum "go.sum" }}', contents: [{ source_dir: '/go/pkg/mod/cache' }] },
  20. { type: 'save_cache', key: 'cache-date-{{ year }}-{{ month }}-{{ day }}', contents: [{ source_dir: '/go/pkg/mod/cache' }] },
  21. ],
  22. };
  23. {
  24. runs: [
  25. {
  26. name: 'agola build/test',
  27. tasks: [
  28. task_build_go(version, arch)
  29. for version in ['1.11', '1.12']
  30. for arch in ['amd64', 'arm64']
  31. ] + [
  32. {
  33. name: 'run',
  34. runtime: {
  35. arch: 'amd64',
  36. containers: [
  37. { image: 'debian:stretch' }
  38. ],
  39. },
  40. steps: [
  41. { type: 'restore_workspace', dest_dir: '.' },
  42. { type: 'run', command: './bin/agola-example-go' },
  43. ],
  44. depends: [
  45. 'build go 1.12 amd64',
  46. ],
  47. },
  48. ],
  49. },
  50. ],
  51. }