Skip to content

Commit b674871

Browse files
authored
Merge pull request #2224 from rnc/PIPELINE
Use single pipeline
2 parents 3d4db13 + 63ced54 commit b674871

File tree

8 files changed

+173
-96
lines changed

8 files changed

+173
-96
lines changed

deploy/tasks/maven-deployment.yaml

+5-9
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ spec:
3232
description: Name of the processor image. Useful to override for development.
3333
type: string
3434
default: "quay.io/redhat-appstudio/hacbs-jvm-build-request-processor:dev"
35-
volumes:
36-
- name: workdir
37-
emptyDir: {}
38-
stepTemplate:
39-
volumeMounts:
40-
- mountPath: /var/workdir
41-
name: workdir
35+
workspaces:
36+
- name: source
37+
mountPath: /var/workdir
4238
steps:
4339
- name: restore-trusted-artifact
4440
image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:81c4864dae6bb11595f657be887e205262e70086a05ed16ada827fd6391926ac
@@ -48,7 +44,7 @@ spec:
4844
DIGEST=$IMAGE_DIGEST
4945
AARCHIVE=$(oras manifest fetch $ORAS_OPTIONS $URL@$DIGEST | jq --raw-output '.layers[0].digest')
5046
echo "URL $URL DIGEST $DIGEST AARCHIVE $AARCHIVE"
51-
use-archive oci:$URL@$AARCHIVE=/var/workdir/artifacts
47+
use-archive oci:$URL@$AARCHIVE=/var/workdir/
5248
env:
5349
- name: IMAGE_DIGEST
5450
value: $(params.IMAGE_DIGEST)
@@ -77,6 +73,6 @@ spec:
7773
key: mavenpassword
7874
args:
7975
- deploy
80-
- --directory=/var/workdir/artifacts
76+
- --directory=/var/workdir/deployment
8177
- --mvn-repo=$(params.MVN_REPO)
8278
- --mvn-username=$(params.MVN_USERNAME)

deploy/tasks/pre-build.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ spec:
6767
- description: The git repo will be cloned onto the volume backing this Workspace.
6868
name: source
6969
mountPath: /var/workdir
70-
- name: tls
7170
steps:
7271
- name: preprocessor
7372
image: $(params.JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE)

java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void run() {
105105
export MAVEN_HOME=${MAVEN_HOME:=/opt/maven/3.8.8}
106106
export GRADLE_USER_HOME="${JBS_WORKDIR}/software/settings/.gradle"
107107
108-
mkdir -p ${JBS_WORKDIR}/logs ${JBS_WORKDIR}/packages ${HOME}/.sbt/1.0 ${GRADLE_USER_HOME} ${HOME}/.m2
108+
mkdir -p ${JBS_WORKDIR}/logs ${JBS_WORKDIR}/packages ${JBS_WORKDIR}/settings ${HOME}/.sbt/1.0 ${GRADLE_USER_HOME} ${HOME}/.m2
109109
cd ${JBS_WORKDIR}/source
110110
111111
if [ -n "${JAVA_HOME}" ]; then
@@ -119,6 +119,7 @@ public void run() {
119119
runBuild += getMavenSetup();
120120

121121
runBuild += """
122+
cp -a ${HOME}/.m2/*.xml ${JBS_WORKDIR}/settings
122123
fi
123124
124125
if [ -n "${GRADLE_HOME}" ]; then
@@ -190,16 +191,20 @@ private String getContainerFile() {
190191
COPY --from=0 /var/workdir/ /var/workdir/
191192
RUN /opt/jboss/container/java/run/run-java.sh copy-artifacts --source-path=/var/workdir/workspace/source --deploy-path=/var/workdir/workspace/artifacts
192193
FROM scratch
193-
COPY --from=1 /var/workdir/workspace/artifacts /
194+
COPY --from=1 /var/workdir/workspace/settings /settings/
195+
COPY --from=1 /var/workdir/workspace/artifacts /deployment/
194196
""".formatted(buildRequestProcessorImage);
195197
} else {
196198
containerFile +=
197199
"""
198200
FROM scratch
199-
COPY --from=0 /var/workdir/workspace/artifacts /
201+
COPY --from=0 /var/workdir/workspace/settings /settings/
202+
COPY --from=0 /var/workdir/workspace/artifacts /deployment/
200203
""";
201204
}
202205

206+
Log.warnf("### containerFile is\n%s", containerFile);
207+
203208
return containerFile;
204209
}
205210

java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/deploy/BuildVerifyCommand.java

-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ public class BuildVerifyCommand implements Runnable {
5353
@CommandLine.Option(names = "--task-run-name")
5454
String taskRun;
5555

56-
@CommandLine.Option(names = "--logs-path")
57-
Path logsPath;
58-
5956
@CommandLine.Option(required = true, names = "--scm-uri")
6057
String scmUri;
6158

pkg/apis/jvmbuildservice/v1alpha1/systemconfig_types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type SystemConfigList struct {
4747

4848
const (
4949
KonfluxGitDefinition = "https://raw.githubusercontent.com/konflux-ci/build-definitions/refs/heads/main/task/git-clone/0.1/git-clone.yaml"
50-
KonfluxPreBuildDefinitions = "https://raw.githubusercontent.com/redhat-appstudio/jvm-build-service/main/deploy/tasks/pre-build.yaml"
50+
KonfluxPreBuildDefinitions = "https://raw.githubusercontent.com/rnc/jvm-build-service/PIPELINE/deploy/tasks/pre-build.yaml"
5151
KonfluxBuildDefinitions = "https://raw.githubusercontent.com/konflux-ci/build-definitions/refs/heads/main/task/buildah-oci-ta/0.2/buildah-oci-ta.yaml"
52-
KonfluxMavenDeployDefinitions = "https://raw.githubusercontent.com/redhat-appstudio/jvm-build-service/main/deploy/tasks/maven-deployment.yaml"
52+
KonfluxMavenDeployDefinitions = "https://raw.githubusercontent.com/rnc/jvm-build-service/PIPELINE/deploy/tasks/maven-deployment.yaml"
5353
)

pkg/reconciler/dependencybuild/buildrecipeyaml.go

+92-19
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import (
1919
)
2020

2121
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"
2526

2627
GitTaskName = "git-clone"
2728
PreBuildTaskName = "pre-build"
@@ -54,6 +55,8 @@ var buildEntryScript string
5455
//go:embed scripts/Dockerfile.build-trusted-artifacts
5556
var buildTrustedArtifacts string
5657

58+
// TODO: ### Either remove or replace with verification step *but* the contaminants/verification is all tied to the build pipeline in dependencybuild.go
59+
/*
5760
func createDeployPipelineSpec(jbsConfig *v1alpha1.JBSConfig, buildRequestProcessorImage string) (*tektonpipeline.PipelineSpec, error) {
5861
// Original deploy pipeline used to run maven deployment and also tag the images using 'oras tag'
5962
// with the SHA256 encoded sum of the GAVs.
@@ -128,6 +131,8 @@ func createDeployPipelineSpec(jbsConfig *v1alpha1.JBSConfig, buildRequestProcess
128131
}
129132
return ps, nil
130133
}
134+
*/
135+
131136
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) {
132137

133138
// 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
137142
verifyBuiltArtifactsArgs := verifyParameters(jbsConfig, recipe)
138143
deployArgs := []string{
139144
"verify",
140-
"--path=$(workspaces.source.path)/artifacts",
141-
"--logs-path=$(workspaces.source.path)/logs",
145+
fmt.Sprintf("--path=%s/deployment", PostBuildVolumeMount),
142146
"--task-run-name=$(context.taskRun.name)",
143147
"--build-id=" + buildId,
144148
"--scm-uri=" + db.Spec.ScmInfo.SCMURL,
@@ -272,7 +276,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
272276
runAfterBuild = append(runAfter, BuildTaskName)
273277

274278
ps := &tektonpipeline.PipelineSpec{
275-
Workspaces: []tektonpipeline.PipelineWorkspaceDeclaration{{Name: WorkspaceSource}, {Name: WorkspaceTls}},
279+
Workspaces: []tektonpipeline.PipelineWorkspaceDeclaration{{Name: WorkspaceSource}},
276280
}
277281

278282
if preBuildImageRequired {
@@ -344,7 +348,6 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
344348
},
345349
Workspaces: []tektonpipeline.WorkspacePipelineTaskBinding{
346350
{Name: WorkspaceSource, Workspace: WorkspaceSource},
347-
{Name: WorkspaceTls, Workspace: WorkspaceTls},
348351
},
349352
Params: []tektonpipeline.Param{
350353
{
@@ -463,7 +466,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
463466
}
464467

465468
// Note - its also possible to refer to a remote pipeline ref as well as a task.
466-
resolver := tektonpipeline.ResolverRef{
469+
buildResolver := tektonpipeline.ResolverRef{
467470
// We can use either a http or git resolver. Using http as avoids cloning an entire repository.
468471
Resolver: "http",
469472
Params: []tektonpipeline.Param{
@@ -483,7 +486,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
483486
RunAfter: runAfter,
484487
TaskRef: &tektonpipeline.TaskRef{
485488
// Can't specify name and resolver as they clash.
486-
ResolverRef: resolver,
489+
ResolverRef: buildResolver,
487490
},
488491
Timeout: &v12.Duration{Duration: time.Hour * v1alpha1.DefaultTimeout},
489492
Params: []tektonpipeline.Param{
@@ -533,14 +536,19 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
533536
ps.Results = append(ps.Results, tektonpipeline.PipelineResult{Name: PipelineResultImageDigest, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: "$(tasks." + BuildTaskName + ".results." + PipelineResultImageDigest + ")"}})
534537

535538
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}),
538543
Results: []tektonpipeline.TaskResult{
539544
{Name: PipelineResultContaminants},
540545
{Name: PipelineResultDeployedResources},
541546
{Name: PipelineResultPassedVerification},
542547
{Name: PipelineResultVerificationResult},
543548
},
549+
StepTemplate: &tektonpipeline.StepTemplate{
550+
VolumeMounts: []v1.VolumeMount{{Name: PostBuildVolume, MountPath: PostBuildVolumeMount}},
551+
},
544552
Steps: []tektonpipeline.Step{
545553
{
546554
Name: "restore-post-build-artifacts",
@@ -550,13 +558,13 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
550558
Env: secretVariables,
551559
// While the manifest digest is available we need the manifest of the layer within the archive hence
552560
// 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"
554562
export ORAS_OPTIONS="%s"
555563
URL=%s
556564
DIGEST=$(tasks.%s.results.IMAGE_DIGEST)
557565
AARCHIVE=$(oras manifest fetch $ORAS_OPTIONS $URL@$DIGEST | jq --raw-output '.layers[0].digest')
558566
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),
560568
},
561569
{
562570
Name: "verify-and-check-for-contaminates",
@@ -580,17 +588,82 @@ use-archive oci:$URL@$AARCHIVE=$(workspaces.source.path)/artifacts`, orasOptions
580588
},
581589
Timeout: &v12.Duration{Duration: time.Hour * v1alpha1.DefaultTimeout},
582590
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-
},
587591
}}
588592
ps.Tasks = append(pipelineTask, ps.Tasks...)
589-
590593
for _, i := range postBuildTask.Results {
591594
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 + ")"}})
592595
}
593596

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+
594667
for _, i := range pipelineParams {
595668
ps.Params = append(ps.Params, tektonpipeline.ParamSpec{Name: i.Name, Description: i.Description, Default: i.Default, Type: i.Type})
596669
var value tektonpipeline.ResultValue
@@ -786,7 +859,7 @@ func verifyParameters(jbsConfig *v1alpha1.JBSConfig, recipe *v1alpha1.BuildRecip
786859
verifyBuiltArtifactsArgs := []string{
787860
"verify-built-artifacts",
788861
"--repository-url=$(params." + PipelineParamProxyUrl + ")",
789-
"--deploy-path=$(workspaces.source.path)/artifacts",
862+
fmt.Sprintf("--deploy-path=%s/deployment", PostBuildVolumeMount),
790863
"--task-run-name=$(context.taskRun.name)",
791864
"--results-file=$(results." + PipelineResultPassedVerification + ".path)",
792865
}

0 commit comments

Comments
 (0)