forked from tektoncd/catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: tektoncd#386 Signed-off-by: Puneet Punamiya <[email protected]>
- Loading branch information
1 parent
2c8703e
commit b4ce0b6
Showing
13 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: source-pvc | ||
spec: | ||
resources: | ||
requests: | ||
storage: 500Mi | ||
accessModes: | ||
- ReadWriteOnce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: git-service-account | ||
secrets: | ||
- name: github-auth |
86 changes: 86 additions & 0 deletions
86
task/git-clone/0.1/examples/git-clone-checking-out-a-branch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
87 changes: 87 additions & 0 deletions
87
task/git-clone/0.1/examples/git-clone-checking-out-a-commit.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
Oops, something went wrong.