@@ -19,9 +19,10 @@ import (
19
19
)
20
20
21
21
const (
22
- WorkspaceSource = "source"
23
- WorkspaceMount = "/var/workdir"
24
- WorkspaceTls = "tls"
22
+ PostBuildVolume = "post-build-volume"
23
+ PostBuildVolumeMount = "/var/workdir"
24
+ WorkspaceSource = "source"
25
+ WorkspaceTls = "tls"
25
26
26
27
GitTaskName = "git-clone"
27
28
PreBuildTaskName = "pre-build"
@@ -54,6 +55,8 @@ var buildEntryScript string
54
55
//go:embed scripts/Dockerfile.build-trusted-artifacts
55
56
var buildTrustedArtifacts string
56
57
58
+ // TODO: ### Either remove or replace with verification step *but* the contaminants/verification is all tied to the build pipeline in dependencybuild.go
59
+ /*
57
60
func createDeployPipelineSpec(jbsConfig *v1alpha1.JBSConfig, buildRequestProcessorImage string) (*tektonpipeline.PipelineSpec, error) {
58
61
// Original deploy pipeline used to run maven deployment and also tag the images using 'oras tag'
59
62
// with the SHA256 encoded sum of the GAVs.
@@ -128,6 +131,8 @@ func createDeployPipelineSpec(jbsConfig *v1alpha1.JBSConfig, buildRequestProcess
128
131
}
129
132
return ps, nil
130
133
}
134
+ */
135
+
131
136
func createPipelineSpec (log logr.Logger , tool string , commitTime int64 , jbsConfig * v1alpha1.JBSConfig , systemConfig * v1alpha1.SystemConfig , recipe * v1alpha1.BuildRecipe , db * v1alpha1.DependencyBuild , paramValues []tektonpipeline.Param , buildRequestProcessorImage string , buildId string , existingImages map [string ]string , orasOptions string ) (* tektonpipeline.PipelineSpec , string , error ) {
132
137
133
138
// Rather than tagging with hash of json build recipe, buildrequestprocessor image and db.Name as the former two
@@ -137,8 +142,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
137
142
verifyBuiltArtifactsArgs := verifyParameters (jbsConfig , recipe )
138
143
deployArgs := []string {
139
144
"verify" ,
140
- "--path=$(workspaces.source.path)/artifacts" ,
141
- "--logs-path=$(workspaces.source.path)/logs" ,
145
+ fmt .Sprintf ("--path=%s/deployment" , PostBuildVolumeMount ),
142
146
"--task-run-name=$(context.taskRun.name)" ,
143
147
"--build-id=" + buildId ,
144
148
"--scm-uri=" + db .Spec .ScmInfo .SCMURL ,
@@ -272,7 +276,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
272
276
runAfterBuild = append (runAfter , BuildTaskName )
273
277
274
278
ps := & tektonpipeline.PipelineSpec {
275
- Workspaces : []tektonpipeline.PipelineWorkspaceDeclaration {{Name : WorkspaceSource }, { Name : WorkspaceTls } },
279
+ Workspaces : []tektonpipeline.PipelineWorkspaceDeclaration {{Name : WorkspaceSource }},
276
280
}
277
281
278
282
if preBuildImageRequired {
@@ -344,7 +348,6 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
344
348
},
345
349
Workspaces : []tektonpipeline.WorkspacePipelineTaskBinding {
346
350
{Name : WorkspaceSource , Workspace : WorkspaceSource },
347
- {Name : WorkspaceTls , Workspace : WorkspaceTls },
348
351
},
349
352
Params : []tektonpipeline.Param {
350
353
{
@@ -463,7 +466,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
463
466
}
464
467
465
468
// Note - its also possible to refer to a remote pipeline ref as well as a task.
466
- resolver := tektonpipeline.ResolverRef {
469
+ buildResolver := tektonpipeline.ResolverRef {
467
470
// We can use either a http or git resolver. Using http as avoids cloning an entire repository.
468
471
Resolver : "http" ,
469
472
Params : []tektonpipeline.Param {
@@ -483,7 +486,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
483
486
RunAfter : runAfter ,
484
487
TaskRef : & tektonpipeline.TaskRef {
485
488
// Can't specify name and resolver as they clash.
486
- ResolverRef : resolver ,
489
+ ResolverRef : buildResolver ,
487
490
},
488
491
Timeout : & v12.Duration {Duration : time .Hour * v1alpha1 .DefaultTimeout },
489
492
Params : []tektonpipeline.Param {
@@ -533,14 +536,19 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
533
536
ps .Results = append (ps .Results , tektonpipeline.PipelineResult {Name : PipelineResultImageDigest , Value : tektonpipeline.ResultValue {Type : tektonpipeline .ParamTypeString , StringVal : "$(tasks." + BuildTaskName + ".results." + PipelineResultImageDigest + ")" }})
534
537
535
538
postBuildTask := tektonpipeline.TaskSpec {
536
- Workspaces : []tektonpipeline.WorkspaceDeclaration {{Name : WorkspaceSource , MountPath : WorkspaceMount }, {Name : WorkspaceTls }},
537
- Params : append (pipelineParams , tektonpipeline.ParamSpec {Name : PipelineResultPreBuildImageDigest , Type : tektonpipeline .ParamTypeString }),
539
+ // Using a default emptyDir volume as this task is unique to JBS and don't want it interfering with
540
+ // the shared workspace.
541
+ Volumes : []v1.Volume {{Name : PostBuildVolume , VolumeSource : v1.VolumeSource {EmptyDir : & v1.EmptyDirVolumeSource {}}}},
542
+ Params : append (pipelineParams , tektonpipeline.ParamSpec {Name : PipelineResultPreBuildImageDigest , Type : tektonpipeline .ParamTypeString }),
538
543
Results : []tektonpipeline.TaskResult {
539
544
{Name : PipelineResultContaminants },
540
545
{Name : PipelineResultDeployedResources },
541
546
{Name : PipelineResultPassedVerification },
542
547
{Name : PipelineResultVerificationResult },
543
548
},
549
+ StepTemplate : & tektonpipeline.StepTemplate {
550
+ VolumeMounts : []v1.VolumeMount {{Name : PostBuildVolume , MountPath : PostBuildVolumeMount }},
551
+ },
544
552
Steps : []tektonpipeline.Step {
545
553
{
546
554
Name : "restore-post-build-artifacts" ,
@@ -550,13 +558,13 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
550
558
Env : secretVariables ,
551
559
// While the manifest digest is available we need the manifest of the layer within the archive hence
552
560
// using 'oras manifest fetch' to extract the correct layer.
553
- Script : fmt .Sprintf (`echo "Restoring artifacts to workspace : $(workspaces.source.path) "
561
+ Script : fmt .Sprintf (`echo "Restoring artifacts"
554
562
export ORAS_OPTIONS="%s"
555
563
URL=%s
556
564
DIGEST=$(tasks.%s.results.IMAGE_DIGEST)
557
565
AARCHIVE=$(oras manifest fetch $ORAS_OPTIONS $URL@$DIGEST | jq --raw-output '.layers[0].digest')
558
566
echo "URL $URL DIGEST $DIGEST AARCHIVE $AARCHIVE"
559
- use-archive oci:$URL@$AARCHIVE=$(workspaces.source.path)/artifacts ` , orasOptions , registryArgsWithDefaults (jbsConfig , "" ), BuildTaskName ),
567
+ use-archive oci:$URL@$AARCHIVE=%s ` , orasOptions , registryArgsWithDefaults (jbsConfig , "" ), BuildTaskName , PostBuildVolumeMount ),
560
568
},
561
569
{
562
570
Name : "verify-and-check-for-contaminates" ,
@@ -580,17 +588,82 @@ use-archive oci:$URL@$AARCHIVE=$(workspaces.source.path)/artifacts`, orasOptions
580
588
},
581
589
Timeout : & v12.Duration {Duration : time .Hour * v1alpha1 .DefaultTimeout },
582
590
Params : []tektonpipeline.Param {{Name : PipelineResultPreBuildImageDigest , Value : tektonpipeline.ParamValue {Type : tektonpipeline .ParamTypeString , StringVal : preBuildImage }}},
583
- Workspaces : []tektonpipeline.WorkspacePipelineTaskBinding {
584
- {Name : WorkspaceSource , Workspace : WorkspaceSource },
585
- {Name : WorkspaceTls , Workspace : WorkspaceTls },
586
- },
587
591
}}
588
592
ps .Tasks = append (pipelineTask , ps .Tasks ... )
589
-
590
593
for _ , i := range postBuildTask .Results {
591
594
ps .Results = append (ps .Results , tektonpipeline.PipelineResult {Name : i .Name , Description : i .Description , Value : tektonpipeline.ResultValue {Type : tektonpipeline .ParamTypeString , StringVal : "$(tasks." + PostBuildTaskName + ".results." + i .Name + ")" }})
592
595
}
593
596
597
+ deployResolver := tektonpipeline.ResolverRef {
598
+ // We can use either a http or git resolver. Using http as avoids cloning an entire repository.
599
+ Resolver : "http" ,
600
+ Params : []tektonpipeline.Param {
601
+ {
602
+ Name : "url" ,
603
+ Value : tektonpipeline.ParamValue {
604
+ Type : tektonpipeline .ParamTypeString ,
605
+ StringVal : v1alpha1 .KonfluxMavenDeployDefinitions ,
606
+ },
607
+ },
608
+ },
609
+ }
610
+ ps .Tasks = append ([]tektonpipeline.PipelineTask {
611
+ {
612
+ Name : DeployTaskName ,
613
+ RunAfter : append (runAfterBuild , PostBuildTaskName ),
614
+ Workspaces : []tektonpipeline.WorkspacePipelineTaskBinding {
615
+ {Name : WorkspaceSource , Workspace : WorkspaceSource },
616
+ },
617
+ TaskRef : & tektonpipeline.TaskRef {
618
+ // Can't specify name and resolver as they clash.
619
+ ResolverRef : deployResolver ,
620
+ },
621
+ Params : []tektonpipeline.Param {
622
+ {
623
+ Name : PipelineResultImage ,
624
+ Value : tektonpipeline.ParamValue {
625
+ Type : tektonpipeline .ParamTypeString ,
626
+ StringVal : "$(tasks." + BuildTaskName + ".results." + PipelineResultImage + ")" ,
627
+ },
628
+ },
629
+ {
630
+ Name : PipelineResultImageDigest ,
631
+ Value : tektonpipeline.ParamValue {
632
+ Type : tektonpipeline .ParamTypeString ,
633
+ StringVal : "$(tasks." + BuildTaskName + ".results." + PipelineResultImageDigest + ")" ,
634
+ },
635
+ },
636
+ {
637
+ Name : "MVN_REPO" ,
638
+ Value : tektonpipeline.ParamValue {
639
+ Type : tektonpipeline .ParamTypeString ,
640
+ StringVal : jbsConfig .Spec .MavenDeployment .Repository ,
641
+ },
642
+ },
643
+ {
644
+ Name : "MVN_USERNAME" ,
645
+ Value : tektonpipeline.ParamValue {
646
+ Type : tektonpipeline .ParamTypeString ,
647
+ StringVal : jbsConfig .Spec .MavenDeployment .Username ,
648
+ },
649
+ },
650
+ {
651
+ Name : "MVN_PASSWORD" ,
652
+ Value : tektonpipeline.ParamValue {
653
+ Type : tektonpipeline .ParamTypeString ,
654
+ StringVal : v1alpha1 .MavenSecretName ,
655
+ },
656
+ },
657
+ {
658
+ Name : "JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE" ,
659
+ Value : tektonpipeline.ParamValue {
660
+ Type : tektonpipeline .ParamTypeString ,
661
+ StringVal : buildRequestProcessorImage ,
662
+ },
663
+ },
664
+ },
665
+ }}, ps .Tasks ... )
666
+
594
667
for _ , i := range pipelineParams {
595
668
ps .Params = append (ps .Params , tektonpipeline.ParamSpec {Name : i .Name , Description : i .Description , Default : i .Default , Type : i .Type })
596
669
var value tektonpipeline.ResultValue
@@ -786,7 +859,7 @@ func verifyParameters(jbsConfig *v1alpha1.JBSConfig, recipe *v1alpha1.BuildRecip
786
859
verifyBuiltArtifactsArgs := []string {
787
860
"verify-built-artifacts" ,
788
861
"--repository-url=$(params." + PipelineParamProxyUrl + ")" ,
789
- "--deploy-path=$(workspaces.source.path)/artifacts" ,
862
+ fmt . Sprintf ( "--deploy-path=%s/deployment" , PostBuildVolumeMount ) ,
790
863
"--task-run-name=$(context.taskRun.name)" ,
791
864
"--results-file=$(results." + PipelineResultPassedVerification + ".path)" ,
792
865
}
0 commit comments