diff --git a/tekton/pipeline/golang-build-publish/0.1/golang-build-publish.yaml b/tekton/pipeline/golang-build-publish/0.1/golang-build-publish.yaml new file mode 100644 index 0000000000000000000000000000000000000000..aa3fbe73597f212f5df94228aea1999b8e5f67b8 --- /dev/null +++ b/tekton/pipeline/golang-build-publish/0.1/golang-build-publish.yaml @@ -0,0 +1,101 @@ +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 diff --git a/tekton/pipeline/kustomization.yaml b/tekton/pipeline/kustomization.yaml index a6eebc4904d040ca4475d0d59e8c0d266dbb34fe..a32c5285bf97772a32635f2834053063c36f4900 100644 --- a/tekton/pipeline/kustomization.yaml +++ b/tekton/pipeline/kustomization.yaml @@ -4,4 +4,5 @@ kind: Kustomization resources: - ./demo/0.1/demo.yaml - ./build-upload-gitops-docs/0.1/build-upload-gitops-docs.yaml - - ./monthly-gitops-release/0.1/monthly-gitops-release.yaml \ No newline at end of file + - ./monthly-gitops-release/0.1/monthly-gitops-release.yaml + - ./golang-build-publish/0.1/golang-build-publish.yaml diff --git a/tekton/task/golang-build/0.3/golang-build.yaml b/tekton/task/golang-build/0.3/golang-build.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b12b0143cf24345ca3724c2f86b190db3ae371b3 --- /dev/null +++ b/tekton/task/golang-build/0.3/golang-build.yaml @@ -0,0 +1,80 @@ +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 diff --git a/tekton/task/golang-test/0.3/golang-test.yaml b/tekton/task/golang-test/0.3/golang-test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8107baaebe7430b38af5f000eefa72b1097c2074 --- /dev/null +++ b/tekton/task/golang-test/0.3/golang-test.yaml @@ -0,0 +1,73 @@ +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 diff --git a/tekton/task/golangci-lint/0.3/golangci-lint.yaml b/tekton/task/golangci-lint/0.3/golangci-lint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..096354cf4f6f70c760e9da4ed136c1931f3e2ed2 --- /dev/null +++ b/tekton/task/golangci-lint/0.3/golangci-lint.yaml @@ -0,0 +1,85 @@ +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 diff --git a/tekton/task/ko-build/0.1/ko-build.yaml b/tekton/task/ko-build/0.1/ko-build.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9c4328afd68fa997a3e011e24ad963ee30c047d1 --- /dev/null +++ b/tekton/task/ko-build/0.1/ko-build.yaml @@ -0,0 +1,63 @@ +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 diff --git a/tekton/task/kustomization.yaml b/tekton/task/kustomization.yaml index 7d6e71a872c199d9233fbca1c8cea2e18035a939..70fd3bd756b76745f5a40edfbb33003d251bb635 100644 --- a/tekton/task/kustomization.yaml +++ b/tekton/task/kustomization.yaml @@ -8,4 +8,8 @@ resources: - ./mc-mirror/0.1/mc-mirror.yaml - ./mdbook-build/0.1/mdbook-build.yaml - ./git-chglog/0.1/git-chglog.yaml - - ./create-gitlab-release/0.1/create-gitlab-release.yaml \ No newline at end of file + - ./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