1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-22 06:02:51 +00:00

This patch splits git-clone task from the git directory

Changes include:
  - moves git-clone task to the task directory
  - copies and modifies readme file for git-clone from git directory
  - copies examples and tests directory from git directory

Issue: #386

Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
This commit is contained in:
PuneetPunamiya 2020-07-06 14:16:32 +05:30 committed by tekton-robot
parent 0c380f77f4
commit 73124fa07f
13 changed files with 666 additions and 0 deletions

View File

@ -0,0 +1,56 @@
# Git Task
This `Task` is Git task to work with repositories used by other tasks
in your Pipeline.
## `git-clone`
**Please Note: this Task is only compatible with Tekton Pipelines versions 0.11-rc1 and greater!**
This `Task` has two required inputs:
1. The URL of a git repo to clone provided with the `url` param.
2. A Workspace called `output`.
The `git-clone` `Task` will clone a repo from the provided `url` into the
`output` Workspace. By default the repo will be cloned into the root of
your Workspace. You can clone into a subdirectory by setting this `Task`'s
`subdirectory` param.
This `Task` does the job of the legacy `GitResource` `PipelineResource` and
is intended as its replacement. This is part of our plan to [offer replacement
`Tasks` for Pipeline Resources](https://github.com/tektoncd/catalog/issues/95)
as well as
[document those replacements](https://github.com/tektoncd/pipeline/issues/1369).
### Workspaces
* **output**: A workspace for this Task to fetch the git repository in to.
### Parameters
* **url**: git url to clone (_required_)
* **revision**: git revision to checkout (branch, tag, sha, ref…) (_default:_ master)
* **refspec**: git refspec to fetch before checking out revision (_default_:refs/heads/master:refs/heads/master)
* **submodules**: defines if the resource should initialize and fetch the submodules (_default_: true)
* **depth**: performs a shallow clone where only the most recent commit(s) will be fetched (_default_: 1)
* **sslVerify**: defines if http.sslVerify should be set to true or false in the global git config (_default_: true)
* **subdirectory**: subdirectory inside the "output" workspace to clone the git repo into (_default:_ "")
* **deleteExisting**: clean out the contents of the repo's destination directory if it already exists before cloning the repo there (_default_: false)
* **httpProxy**: git HTTP proxy server for non-SSL requests
* **httpsProxy**: git HTTPS proxy server for SSL requests
* **noProxy**: git no proxy - opt out of proxying HTTP/HTTPS requests
### Results
* **commit**: The precise commit SHA that was fetched by this Task
## Usage
### `git-clone`
The following pipelines demonstrate usage of the git-clone Task:
- [Cloning a branch](./examples/git-clone-checking-out-a-branch.yaml)
- [Checking out a specific git commit](./examples/git-clone-checking-out-a-commit.yaml)
- [Checking out a git tag and using the "commit" Task Result](./examples/using-git-clone-task-result.yaml)

View File

@ -0,0 +1,63 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: git-pipeline
spec:
workspaces:
- name: shared-workspace
- name: input
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"
- name: git-cli
taskRef:
name: git-cli
runAfter:
- fetch-repository
workspaces:
- name: source
workspace: shared-workspace
- name: input
workspace: input
params:
- name: GIT_USER_NAME
value: git_username
- name: GIT_USER_EMAIL
value: git_email
- name: GIT_SCRIPT
value: |
cp $(workspaces.input.path)/* $(workspaces.source.path)
git add .
git commit -m 'Add sample file'
git push origin master
results:
- name: commit
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: git-pipeline-run
spec:
serviceAccountName: git-service-account
pipelineRef:
name: git-pipeline
workspaces:
- name: shared-workspace
persistentvolumeclaim:
claimName: source-pvc
- name: input
configmap:
name: files

View File

@ -0,0 +1,11 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: source-pvc
spec:
resources:
requests:
storage: 500Mi
accessModes:
- ReadWriteOnce

View File

@ -0,0 +1,13 @@
---
apiVersion: v1
kind: Secret
metadata:
name: github-auth
annotations:
# Replace with the desired domain name.
tekton.dev/git-0: https://github.com
type: kubernetes.io/basic-auth
stringData:
username: git_username
# Access token should be provided here, if 2 factor authentication is enabled.
password: git_password

View File

@ -0,0 +1,7 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: git-service-account
secrets:
- name: github-auth

View File

@ -0,0 +1,86 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: cat-branch-readme
spec:
description: |
cat-branch-readme takes a git repository and a branch name and
prints the README.md file from that branch. This is an example
Pipeline demonstrating the following:
- Using the git-clone catalog Task to clone a branch
- Passing a cloned repo to subsequent Tasks using a Workspace.
- Ordering Tasks in a Pipeline using "runAfter" so that
git-clone completes before we try to read from the Workspace.
- Using a volumeClaimTemplate Volume as a Workspace.
- Avoiding hard-coded paths by using a Workspace's path
variable instead.
params:
- name: repo-url
type: string
description: The git repository URL to clone from.
- name: branch-name
type: string
description: The git branch to clone.
workspaces:
- name: shared-data
description: |
This workspace will receive the cloned git repo and be passed
to the next Task for the repo's README.md file to be read.
tasks:
- name: fetch-repo
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-data
params:
- name: url
value: $(params.repo-url)
- name: revision
value: $(params.branch-name)
- name: cat-readme
runAfter: ["fetch-repo"] # Wait until the clone is done before reading the readme.
workspaces:
- name: source
workspace: shared-data
taskSpec:
workspaces:
- name: source
steps:
- image: zshusers/zsh:4.3.15
script: |
#!/usr/bin/env zsh
cat $(workspaces.source.path)/README.md
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: git-clone-checking-out-a-branch
spec:
podTemplate:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "tekton.dev/pipelineRun"
operator: In
values:
- git-clone-checking-out-a-branch
topologyKey: kubernetes.io/hostname
pipelineRef:
name: cat-branch-readme
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
params:
- name: repo-url
value: https://github.com/tektoncd/pipeline.git
- name: branch-name
value: release-v0.12.x

View File

@ -0,0 +1,87 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: checking-out-a-revision
spec:
description: |
checking-out-a-revision takes a git repository and a commit SHA
and validates that cloning the revision succeeds. This is an example
Pipeline demonstrating the following:
- Using the git-clone catalog Task to clone a specific commit
- Passing a cloned repo to subsequent Tasks using a Workspace.
- Ordering Tasks in a Pipeline using "runAfter" so that
git-clone completes before we try to read from the Workspace.
- Using a volumeClaimTemplate Volume as a Workspace.
- Avoiding hard-coded paths by using a Workspace's path
variable instead.
params:
- name: repo-url
type: string
description: The git repository URL to clone from.
- name: commit
type: string
description: The git commit to fetch.
workspaces:
- name: shared-data
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-repo
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-data
params:
- name: url
value: $(params.repo-url)
- name: revision
value: $(params.commit)
- name: compare-received-commit-to-expected
runAfter: ["fetch-repo"] # Wait until the clone is done before reading the readme.
params:
- name: expected-commit
value: $(params.commit)
workspaces:
- name: source
workspace: shared-data
taskSpec:
params:
- name: expected-commit
workspaces:
- name: source
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
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: git-clone-checking-out-a-commit-
spec:
pipelineRef:
name: checking-out-a-revision
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
params:
- name: repo-url
value: https://github.com/tektoncd/pipeline.git
- name: commit
value: 301b41380e95382a18b391c2165fa3a6a3de93b0 # Tekton Pipeline's first ever commit!

View File

@ -0,0 +1,74 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: git-rebase-pipeline
spec:
workspaces:
- name: shared-workspace
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: https://github.com/divyansh42/squash-test.git
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"
- name: depth
value: "10"
- name: refspec
value: "refs/heads/master:refs/heads/master"
- name: git-rebase
taskRef:
name: git-rebase
runAfter:
- fetch-repository
workspaces:
- name: source
workspace: shared-workspace
params:
- name: SQUASH_COUNT
value: "2"
- name: COMMIT_MSG
value: "squashed commit"
- name: GIT_USER_NAME
value: "divyansh42"
- name: GIT_USER_EMAIL
value: diagrwa@redhat.com
- name: PULL_REMOTE_NAME
value: origin
- name: PULL_REMOTE_URL
value: https://github.com/divyansh42/squash-test.git
- name: PULL_BRANCH_NAME
value: feature
- name: PUSH_REMOTE_NAME
value: origin
- name: PUSH_REMOTE_URL
value: https://github.com/divyansh42/squash-test.git
- name: PUSH_BRANCH_NAME
value: master
results:
- name: commit
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: git-rebase-pipeline-run
spec:
serviceAccountName: git-rebase-service-account
pipelineRef:
name: git-rebase-pipeline
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi

View File

@ -0,0 +1,10 @@
apiVersion: v1
kind: Secret
metadata:
name: github-auth
annotations:
tekton.dev/git-0: https://github.com # Replace with the desired domain name.
type: kubernetes.io/basic-auth
stringData:
username: $(username)
password: $(password) # Access token should be provided here, if 2 factor authentication is enabled.

View File

@ -0,0 +1,6 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: git-rebase-service-account
secrets:
- name: github-auth

View File

@ -0,0 +1,78 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: validate-tag-sha
spec:
description: |
validate-tag-sha takes a git repository, tag name, and a commit SHA and
checks whether the given tag resolves to that commit. This example
Pipeline demonstrates the following:
- How to use the git-clone catalog Task
- How to use the git-clone Task's "commit" Task Result from another Task.
- How to discard the contents of the git repo when it isn't needed by
passing an `emptyDir` Volume as its "output" workspace.
params:
- name: repo-url
type: string
description: The git repository URL to clone from.
- name: tag-name
type: string
description: The git tag to clone.
- name: expected-sha
type: string
description: The expected SHA to be received for the supplied revision.
workspaces:
- name: output
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: output
workspace: output
params:
- name: url
value: $(params.repo-url)
- name: revision
value: $(params.tag-name)
- name: validate-revision-sha
params:
- name: revision-name
value: $(params.tag-name)
- name: expected-sha
value: $(params.expected-sha)
- name: received-sha
value: $(tasks.fetch-repository.results.commit)
taskSpec:
params:
- name: revision-name
- name: expected-sha
- name: received-sha
steps:
- image: zshusers/zsh:4.3.15
script: |
#!/usr/bin/env zsh
if [ "$(params.expected-sha)" != "$(params.received-sha)" ]; then
echo "Expected revision $(params.revision-name) to have SHA $(params.expected-sha)."
exit 1
else
echo "Revision $(params.revision-name) has expected SHA $(params.expected-sha)."
fi
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: using-git-clone-result-
spec:
pipelineRef:
name: validate-tag-sha
workspaces:
- name: output
emptyDir: {} # We don't care about the repo contents in this example, just the "commit" result
params:
- name: repo-url
value: https://github.com/tektoncd/pipeline.git
- name: tag-name
value: v0.12.1
- name: expected-sha
value: a54dd3984affab47f3018852e61a1a6f9946ecfa

View File

@ -0,0 +1,175 @@
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: git-cli-run
spec:
taskRef:
name: git-cli
workspaces:
- name: source
emptyDir: {}
- name: input
emptyDir: {}
params:
- name: GIT_SCRIPT
value: |
git init
git remote add origin https://github.com/kelseyhightower/nocode
git pull origin master
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-noargs
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-tag
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: revision
value: 1.0.0
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-no-submodules
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/githubtraining/example-dependency
- name: submodules
value: "false"
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-no-depth-2
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: depth
value: "2"
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-sslverify-none
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: sslVerify
value: "false"
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-subdirectory
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: subdirectory
value: "hellomoto"
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-clone-run-delete-existing
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-clone
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: deleteExisting
value: "true"
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-batch-merge-test-mode-merge
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-batch-merge
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: mode
value: "merge"
- name: batchedRefs
value: "refs/pull/4014/head refs/pull/3894/head"
---
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: git-batch-merge-test-mode-merge-cherry-pick
spec:
workspaces:
- name: output
emptyDir: {}
taskRef:
name: git-batch-merge
inputs:
params:
- name: url
value: https://github.com/kelseyhightower/nocode
- name: mode
value: "cherry-pick"
- name: batchedRefs
value: "refs/pull/4014/head refs/pull/3894/head"