Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a git task to clone a repository without PipelineResource #123

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Git tasks

These Tasks are Git tasks to clone a repository in the workspace to be
used by other tasks in a Pipeline.

This is a `Task` that does the job of the `GitResource`
`PipelineResource`. This is linked to
[tektoncd/pipeline#1369](https://github.com/tektoncd/pipeline/issues/1369).

## `fetch-git`

### Inputs

#### Parameters

* **url**: git url to clone
* **revision**: git revision to checkout (branch, tag, sha, ref…) (_default:_ master)
* **workingDirectory**: working directory to clone (_default:_ .)
* **submodules**: init and fetch recursively submodules (_default:_ true)

## Usage

### `fetch-git`

This pipeline uses the Task to clone the
[`tektoncd/pipeline`](https://github.com/tektoncd/pipeline) repository
and display the README in the next step

```yaml
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: cat-readme
spec:
steps:
- name: clone
image: ubuntu
workingdir: /workspace/src/
command:
- /bin/bash
- -c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab -> spaces

args:
- "cat README"
volumeMounts:
- name: source
mountPath: /workspace/src
---
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
name: cat-pipeline-readme
spec:
tasks:
- name: fetch-repository
taskRef:
name: fetch-git
params:
- name: url
value: github.com/tektoncd/pipeline

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running into below error when trying to play around with this locally:
Error running git [remote add origin github.com/tektoncd/pipeline]: exit status 128\nfatal: remote origin already exists.
Is this something special with git-init command?

- name: cat-readme
taskRef:
name: echo-readme

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be cat-readme?

```
This pipeline can be used as the following `PipelineRun` does.

```yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: source
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
name: cat-pipeline-readme-run
spec:
pipelineRef:
name: cat-pipeline-readme
podTemplate:
volumes:
- name: source
persistentVolumeClaim:
claimName: source
```
41 changes: 41 additions & 0 deletions git/fetch-git.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: fetch-git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about calling this by the git action? i.e: git-pull

spec:
inputs:
params:
- name: url
description: git url to clone
type: string
- name: revision
description: git revision to checkout (branch, tag, sha, ref…)
type: string
default: master
- name: workingDirectory
description: working directory to clone
type: string
default: .
- name: submodules
description: init and fetch recursively submodules
type: string
default: "true"
steps:
- name: clone
image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:latest
workingdir: /workspace/src/
command:
- /ko-app/git-init
args:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the parameter -depth and default to 1 this way it can be use in git clone --branch master --depth 1 and download 10KB instead of the whole history 100MB of the repo?
cc @vdemeester

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@csantanapr yeah we will add support for --depth. We need to update this yaml to use something else than git-init, using the git binary itself and script most likely.

- -url
- $(inputs.params.url)
- -revision
- $(inputs.params.revision)
- -path
- $(inputs.params.workingDirectory)
- -submodules
- $(inputs.params.submodules)
stepTemplate:
volumeMounts:
- name: source
mountPath: /workspace/src