Skip to content

Commit

Permalink
git resource for pipeline #58
Browse files Browse the repository at this point in the history
 - add resource to Build as an input source
  • Loading branch information
nader-ziada authored and knative-prow-robot committed Oct 4, 2018
1 parent 591b367 commit c108f3e
Show file tree
Hide file tree
Showing 4 changed files with 493 additions and 0 deletions.
79 changes: 79 additions & 0 deletions docs/pipeline-resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
### Pipeline Resources

## Git Resource

Git resource represents a [git](https://git-scm.com/) repository, that containes the source code to be built by the pipeline. Adding the git resource as an input to a task will clone this repository and allow the task to perform the required actions on the contents of the repo.

Use the following example to understand the syntax and strucutre of a Git Resource

#### Create a git resource using the `PipelineResource` CRD

```
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
metadata:
name: wizzbang-git
namespace: default
spec:
type: git
params:
- name: url
value: github.com/wizzbangcorp/wizzbang
```

Params that can be added are the following:

1. URL: represents the location of the git repository
1. Revision: Git [revision](https://git-scm.com/docs/gitrevisions#_specifying_revisions ) (branch, tag, commit SHA or ref) to clone. If no revision is specified, the resource will default to `latest` from `master`
1. Service Account: specifies the `name` of a `ServiceAccount` resource object. Add this paramater to run your task with the privileges of the specified service account. If no serviceAccountName field is specified, your task runs using the default service account that is in the namespace of the Pipeline resource object.

#### Use the defined git resource in a `Task` definition

```
apiVersion: pipeline.knative.dev/v1alpha1
kind: Task
metadata:
name: build-push-task
namespace: default
spec:
inputs:
resources:
- name: wizzbang-git
type: git
params:
- name: PATH_TO_DOCKERFILE
value: string
outputs:
resources:
- name: builtImage
buildSpec:
template:
name: kaniko
arguments:
- name: DOCKERFILE
value: ${PATH_TO_DOCKERFILE}
- name: REGISTRY
value: ${REGISTRY}
```

#### And finally set the version in the `TaskRun` definition

```
apiVersion: pipeline.knative.dev/v1alpha1
kind: TaskRun
metadata:
name: build-push-task-run
namespace: default
spec:
taskRef:
name: build-push-task
inputs:
resourcesVersion:
- resourceRef:
name: wizzbang-git
version: HEAD
outputs:
artifacts:
- name: builtImage
type: image
```
28 changes: 28 additions & 0 deletions pkg/apis/pipeline/v1alpha1/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ limitations under the License.

package v1alpha1

import (
"strings"
)

// GitResource is an endpoint from which to get data which is required
// by a Build/Task for context (e.g. a repo from which to build an image).
type GitResource struct {
Expand All @@ -30,6 +34,25 @@ type GitResource struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// NewGitResource create a new git resource to pass to Knativve Build
func NewGitResource(r *PipelineResource) *GitResource {
gitResource := GitResource{
Name: r.Name,
Type: r.Spec.Type,
}
for _, param := range r.Spec.Params {
switch {
case strings.EqualFold(param.Name, "URL"):
gitResource.URL = param.Value
case strings.EqualFold(param.Name, "serviceAccount"):
gitResource.ServiceAccount = param.Value
case strings.EqualFold(param.Name, "Revision"):
gitResource.Revision = param.Value
}
}
return &gitResource
}

// GetName returns the name of the resource
func (s GitResource) GetName() string {
return s.Name
Expand All @@ -52,5 +75,10 @@ func (s *GitResource) GetServiceAccountName() string {
return s.ServiceAccount
}

// GetURL returns the url to be used with this resource
func (s *GitResource) GetURL() string {
return s.URL
}

// GetParams returns the resoruce params
func (s GitResource) GetParams() []Param { return []Param{} }
Loading

0 comments on commit c108f3e

Please sign in to comment.