Skip to content

Instantly share code, notes, and snippets.

@linuxbsdfreak
Created October 23, 2020 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxbsdfreak/22ea98c2371e21aab89ae945204a8970 to your computer and use it in GitHub Desktop.
Save linuxbsdfreak/22ea98c2371e21aab89ae945204a8970 to your computer and use it in GitHub Desktop.
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: gobuild-pipeline
spec:
params:
- name: repositoryurl
type: string
description: The git repository URL to clone from.
- name: revision
type: string
description: The git commit to fetch.
- name: dockerrepopath
description: Docker Repo path
workspaces:
- name: shared-workspace
description: |
This workspace will receive the cloned git repo and be passed
to the next Task for the commit to be checked.
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: source
workspace: shared-workspace
params:
- name: repositoryurl
value: $(params.repositoryurl)
- name: revision
value: $(params.revision)
- name: compare-received-commit-to-expected
runAfter:
- fetch-repository # Wait until the clone is done before reading the readme.
params:
- name: expected-commit
value: $(params.revision)
workspaces:
- name: shared-workspace
workspace: shared-workspace
taskSpec:
params:
- name: expected-commit
workspaces:
- name: shared-workspace
#workspace: shared-workspace
steps:
- image: alpine/git:v2.24.3
script: |
#!/usr/bin/env sh
cd $(workspaces.source.path)
receivedCommit=$(git rev-parse HEAD)
if [ $receivedCommit != $(params.expected-commit) ]; then
echo "Expected commit $(params.expected-commit) but received $receivedCommit."
exit 1
else
echo "Received commit $receivedCommit as expected."
fi
- name: golang-unit-tests
runAfter:
- compare-received-commit-to-expected
taskRef:
name: golang-test
workspaces:
- name: source
workspace: shared-workspace
params:
- name: package
value: $(tasks.fetch-repository.results.url)
- name: golang-build-push-kaniko
runAfter:
- golang-unit-tests
taskRef:
name: kaniko
workspaces:
- name: source
workspace: shared-workspace
params:
- name: IMAGE_PATH
value: $(params.dockerrepopath)
- name: REVISION
value: $(tasks.fetch-repository.results.commit)
- name: EXTRA_ARGS
value: "--skip-tls-verify"
- name: golang-build-verify-digest
runAfter:
- golang-build-push-kaniko
params:
- name: digest
value: $(tasks.golang-build-push-kaniko.results.IMAGE-DIGEST)
taskSpec:
params:
- name: digest
steps:
- name: bash
image: ubuntu
script: |
echo $(params.digest)
case .$(params.digest) in
".sha"*) exit 0 ;;
*) echo "Digest value is not correct" && exit 1 ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment