Skip to content
Snippets Groups Projects
Verified Commit 4d16c6b4 authored by Sheogorath's avatar Sheogorath :european_castle:
Browse files

ci(tekton): Add tasks and pipeline for basic golang build

parent 88b81d39
Branches
Tags
No related merge requests found
Pipeline #25708 passed
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: golang-build-publish
spec:
params:
- name: repo-url
type: string
description: The git repository URL to clone from.
- name: revision
type: string
description: Git branch that is used to fetch
default: "main"
- name: packages
description: Path to your golang packages
default: "."
- name: container-registry
type: string
description: Container regsitry e.g. `example.com/some/image`
workspaces:
- name: git-repository
description: |
This workspace contains the cloned repo files, so they can be read by the next task.
tasks:
- name: fetch-source
taskRef:
name: git-clone
workspaces:
- name: output
workspace: git-repository
params:
- name: url
value: "https://$(params.repo-url).git"
- name: revision
value: "$(params.revision)"
- name: verbose
value: "false"
- name: lint
taskRef:
name: golangci-lint
workspaces:
- name: source
workspace: git-repository
params:
- name: package
value: "$(params.repo-url)"
- name: flags
value:
- --fast
- --timeout=5m
- --modules-download-mode=vendor
runAfter:
- fetch-source
- name: test
taskRef:
name: golang-test
workspaces:
- name: source
workspace: git-repository
params:
- name: package
value: "$(params.repo-url)"
- name: packages
value: "$(params.packages)"
runAfter:
- fetch-source
- name: go-build
taskRef:
name: golang-build
workspaces:
- name: source
workspace: git-repository
params:
- name: package
value: "$(params.repo-url)"
- name: packages
value: "$(params.packages)"
- name: flags
value: ""
runAfter:
- fetch-source
- name: ko-build
taskRef:
name: ko
workspaces:
- name: source
workspace: git-repository
params:
- name: package
value: "$(params.repo-url)"
- name: flags
value:
- build
- --bare
- --tags=$(params.revision)
- "$(params.packages)"
- name: KO_DOCKER_REPO
value: "$(params.container-registry)"
runAfter:
- lint
- test
...@@ -5,3 +5,4 @@ resources: ...@@ -5,3 +5,4 @@ resources:
- ./demo/0.1/demo.yaml - ./demo/0.1/demo.yaml
- ./build-upload-gitops-docs/0.1/build-upload-gitops-docs.yaml - ./build-upload-gitops-docs/0.1/build-upload-gitops-docs.yaml
- ./monthly-gitops-release/0.1/monthly-gitops-release.yaml - ./monthly-gitops-release/0.1/monthly-gitops-release.yaml
- ./golang-build-publish/0.1/golang-build-publish.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: golang-build
labels:
app.kubernetes.io/version: "0.3"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/categories: Build Tools
tekton.dev/tags: build-tool
tekton.dev/displayName: "golang build"
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
spec:
description: >-
This Task is Golang task to build Go projects.
params:
- name: package
description: base package to build in
- name: packages
description: "packages to build (default: ./cmd/...)"
default: "./cmd/..."
- name: flags
description: flags to use for the test command
default: -v
- name: GOOS
description: "running program's operating system target"
default: linux
- name: GOARCH
description: "running program's architecture target"
default: ""
- name: GO111MODULE
description: "value of module support"
default: auto
- name: GOCACHE
description: "Go caching directory path"
default: ""
- name: GOMODCACHE
description: "Go mod caching directory path"
default: ""
- name: CGO_ENABLED
description: "Toggle cgo tool during Go build. Use value '0' to disable cgo (for static builds)."
default: "0"
- name: GOSUMDB
description: "Go checksum database url. Use value 'off' to disable checksum validation."
default: ""
workspaces:
- name: source
mountPath: /go/src/$(params.package)
steps:
- name: build
image: docker.io/library/golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418
workingDir: $(workspaces.source.path)
script: |
git config --global --add safe.directory "/go/src/$(params.package)"
go build $(params.flags) $(params.packages)
env:
- name: GOOS
value: "$(params.GOOS)"
- name: GOARCH
value: "$(params.GOARCH)"
- name: GO111MODULE
value: "$(params.GO111MODULE)"
- name: GOCACHE
value: "$(params.GOCACHE)"
- name: GOMODCACHE
value: "$(params.GOMODCACHE)"
- name: CGO_ENABLED
value: "$(params.CGO_ENABLED)"
- name: GOSUMDB
value: "$(params.GOSUMDB)"
- name: HOME
value: /tekton/home
volumeMounts:
- name: home
mountPath: /tekton/home
volumes:
- name: home
emptyDir:
medium: Memory
\ No newline at end of file
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: golang-test
labels:
app.kubernetes.io/version: "0.3"
annotations:
tekton.dev/pipelines.minVersion: "0.50.0"
tekton.dev/categories: Testing
tekton.dev/tags: test
tekton.dev/displayName: "golang test"
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
spec:
description: >-
This Task is Golang task to test Go projects.
params:
- name: package
description: package (and its children) under test
- name: packages
description: "packages to test (default: ./...)"
default: "./..."
- name: context
description: path to the directory to use as context.
default: "."
- name: flags
description: flags to use for the test command
default: -race -cover -v
- name: GOOS
description: "running program's operating system target"
default: linux
- name: GOARCH
description: "running program's architecture target"
default: ""
- name: GO111MODULE
description: "value of module support"
default: auto
- name: GOCACHE
description: "Go caching directory path"
default: ""
- name: GOMODCACHE
description: "Go mod caching directory path"
default: ""
workspaces:
- name: source
mountPath: /go/src/$(params.package)
steps:
- name: unit-test
image: docker.io/library/golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418
workingDir: $(workspaces.source.path)
script: |
go test $(params.flags) $(params.packages)
env:
- name: GOOS
value: "$(params.GOOS)"
- name: GOARCH
value: "$(params.GOARCH)"
- name: GO111MODULE
value: "$(params.GO111MODULE)"
- name: GOCACHE
value: "$(params.GOCACHE)"
- name: GOMODCACHE
value: "$(params.GOMODCACHE)"
- name: HOME
value: /tekton/home
volumeMounts:
- name: home
mountPath: /tekton/home
volumes:
- name: home
emptyDir:
medium: Memory
\ No newline at end of file
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: golangci-lint
labels:
app.kubernetes.io/version: "0.3"
annotations:
tekton.dev/pipelines.minVersion: "0.5001"
tekton.dev/categories: Code Quality
tekton.dev/tags: lint
tekton.dev/displayName: "golangci lint"
tekton.dev/platforms: "linux/amd64"
spec:
description: >-
This Task is Golang task to validate Go projects.
params:
- name: package
description: base package (and its children) under validation
type: string
- name: context
description: path to the directory to use as context.
default: "."
type: string
- name: flags
description: flags to use for the test command
type: array
default:
- --verbose
- name: GOOS
description: "running operating system target"
default: linux
type: string
- name: GOARCH
description: "running architecture target"
default: amd64
type: string
- name: GO111MODULE
description: "value of module support"
default: auto
type: string
- name: GOCACHE
description: "Go caching directory path"
default: ""
type: string
- name: GOMODCACHE
description: "Go mod caching directory path"
default: ""
type: string
- name: GOLANGCI_LINT_CACHE
description: "golangci-lint cache path"
default: ""
type: string
steps:
- name: lint
image: docker.io/golangci/golangci-lint:v1.64.8@sha256:2987913e27f4eca9c8a39129d2c7bc1e74fbcf77f181e01cea607be437aa5cb8
workingDir: $(workspaces.source.path)/$(params.context)
args:
- run
- $(params.flags[*])
env:
- name: GOOS
value: "$(params.GOOS)"
- name: GOARCH
value: "$(params.GOARCH)"
- name: GO111MODULE
value: "$(params.GO111MODULE)"
- name: GOCACHE
value: "$(params.GOCACHE)"
- name: GOMODCACHE
value: "$(params.GOMODCACHE)"
- name: GOLANGCI_LINT_CACHE
value: "$(params.GOLANGCI_LINT_CACHE)"
- name: HOME
value: /tekton/home
volumeMounts:
- name: home
mountPath: /tekton/home
volumes:
- name: home
emptyDir:
medium: Memory
workspaces:
- name: source
description: The workspace containing all content
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: ko
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.50.0"
tekton.dev/categories: Image Build
tekton.dev/tags: image-build
tekton.dev/displayName: "Build and upload container image using ko"
tekton.dev/platforms: "linux/amd64,linux/arm64"
spec:
description: >-
This Task builds source into a container image using ko.
params:
- name: main
description: import path of package main
default: "."
- name: extra-args
description: additional arguments to ko build
type: array
default: []
- name: KO_DOCKER_REPO
description: ko environment variable which identifies where to push images
type: string
- name: KO_DEFAULTBASEIMAGE
description: base image for ko build
default: ""
steps:
- name: build
image: ghcr.io/ko-build/ko:v0.17.1@sha256:97b809c27679c4d1a6ed4a9acc18562a6b3688033cd3404c6e3722296cbdc802
workingDir: $(workspaces.source.path)
args:
- build
- $(params.main)
- $(params.extra-args[*])
script: |
#!/bin/sh
set -e
git config --global --add safe.directory "$(workspaces.source.path)"
ko $*
env:
- name: KO_DOCKER_REPO
value: "$(params.KO_DOCKER_REPO)"
- name: KO_DEFAULTBASEIMAGE
value: "$(params.KO_DEFAULTBASEIMAGE)"
- name: HOME
value: /tekton/home
volumeMounts:
- name: home
mountPath: /tekton/home
volumes:
- name: home
emptyDir:
medium: Memory
workspaces:
- name: source
description: Go source code to build
- name: dockerconfig
description: Includes a docker `config.json`
optional: true
mountPath: /tekton/home/.docker
\ No newline at end of file
...@@ -9,3 +9,7 @@ resources: ...@@ -9,3 +9,7 @@ resources:
- ./mdbook-build/0.1/mdbook-build.yaml - ./mdbook-build/0.1/mdbook-build.yaml
- ./git-chglog/0.1/git-chglog.yaml - ./git-chglog/0.1/git-chglog.yaml
- ./create-gitlab-release/0.1/create-gitlab-release.yaml - ./create-gitlab-release/0.1/create-gitlab-release.yaml
- ./golangci-lint/0.3/golangci-lint.yaml
- ./golang-test/0.3/golang-test.yaml
- ./golang-build/0.3/golang-build.yaml
- ./ko-build/0.1/ko-build.yaml
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment