Skip to content

Commit

Permalink
feat: embed tkn tasks in func binary
Browse files Browse the repository at this point in the history
Embed Tekton tasks for PaC build.

Signed-off-by: Matej Vašek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Jun 26, 2024
1 parent 0404518 commit 069e9e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
59 changes: 22 additions & 37 deletions pkg/pipelines/tekton/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,6 @@ const (
defaultPipelinesTargetBranch = "main"
)

var (
FuncRepoRef = "knative/func"
FuncRepoBranchRef = "main"

taskBasePath = "https://github.com/raw/" +
FuncRepoRef + "/" + FuncRepoBranchRef + "/pkg/pipelines/resources/tekton/task/"
BuildpackTaskURL string
S2ITaskURL string
DeployTaskURL string
)

// sets the values only if they have not been set via the linker "-X" flag
func init() {
if BuildpackTaskURL == "" {
BuildpackTaskURL = taskBasePath + "func-buildpacks/0.2/func-buildpacks.yaml"
}
if S2ITaskURL == "" {
S2ITaskURL = taskBasePath + "func-s2i/0.1/func-s2i.yaml"
}
if DeployTaskURL == "" {
DeployTaskURL = taskBasePath + "func-deploy/0.1/func-deploy.yaml"
}
}

type templateData struct {
FunctionName string
Annotations map[string]string
Expand Down Expand Up @@ -151,15 +127,27 @@ type templateData struct {
// it creates the resource in the project directory
func createPipelineTemplatePAC(f fn.Function, labels map[string]string) error {
data := templateData{
FunctionName: f.Name,
Annotations: f.Deploy.Annotations,
Labels: labels,
PipelineName: getPipelineName(f),
RunAfterFetchSources: runAfterFetchSourcesRef,
GitCloneTaskRef: taskGitClonePACTaskRef,
FuncBuildpacksTaskRef: taskFuncBuildpacksPACTaskRef,
FuncS2iTaskRef: taskFuncS2iPACTaskRef,
FuncDeployTaskRef: taskFuncDeployPACTaskRef,
FunctionName: f.Name,
Annotations: f.Deploy.Annotations,
Labels: labels,
PipelineName: getPipelineName(f),
RunAfterFetchSources: runAfterFetchSourcesRef,
GitCloneTaskRef: taskGitClonePACTaskRef,
}

for _, val := range []struct {
ref string
field *string
}{
{getBuildpackTask(), &data.FuncBuildpacksTaskRef},
{getS2ITask(), &data.FuncS2iTaskRef},
{getDeployTask(), &data.FuncDeployTaskRef},
} {
ts, err := getTaskSpec(val.ref)
if err != nil {
return err
}
*val.field = ts
}

var template string
Expand Down Expand Up @@ -225,10 +213,7 @@ func createPipelineRunTemplatePAC(f fn.Function, labels map[string]string) error

PipelinesTargetBranch: pipelinesTargetBranch,

GitCloneTaskRef: taskGitCloneRef,
FuncBuildpacksTaskRef: BuildpackTaskURL,
FuncS2iTaskRef: S2ITaskURL,
FuncDeployTaskRef: DeployTaskURL,
GitCloneTaskRef: taskGitCloneRef,

PipelineYamlURL: fmt.Sprintf("%s/%s", resourcesDirectory, pipelineFileNamePAC),

Expand Down
9 changes: 0 additions & 9 deletions pkg/pipelines/tekton/templates_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,6 @@ metadata:
# Fetch the git-clone task from hub
pipelinesascode.tekton.dev/task: {{.GitCloneTaskRef}}
# Fetch the func-buildpacks task
pipelinesascode.tekton.dev/task-1: {{.FuncBuildpacksTaskRef}}
# Fetch the func-deploy task
pipelinesascode.tekton.dev/task-2: {{.FuncDeployTaskRef}}
# Fetch the pipelie definition from the .tekton directory
pipelinesascode.tekton.dev/pipeline: {{.PipelineYamlURL}}
# How many runs we want to keep attached to this event
pipelinesascode.tekton.dev/max-keep-runs: "5"
Expand Down

0 comments on commit 069e9e7

Please sign in to comment.