Skip to content

Commit 4d37201

Browse files
committed
Refactor containerfile layouts
1 parent 7c1e668 commit 4d37201

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

pkg/reconciler/dependencybuild/buildrecipeyaml.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -256,73 +256,73 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
256256
if jbsConfig.Spec.CacheSettings.DisableTLS {
257257
cacheUrl = "http://jvm-build-workspace-artifact-cache." + jbsConfig.Namespace + ".svc.cluster.local/v2/cache/rebuild"
258258
}
259+
cacheUrl = cacheUrl + buildRepos + "/" + strconv.FormatInt(commitTime, 10)
259260

260261
//we generate a docker file that can be used to reproduce this build
261262
//this is for diagnostic purposes, if you have a failing build it can be really hard to figure out how to fix it without this
262263
log.Info(fmt.Sprintf("Generating dockerfile with recipe build image %#v", recipe.Image))
263-
preprocessorScript := "#!/bin/sh\n/root/software/system-java/bin/java -jar /root/software/build-request-processor/quarkus-run.jar " + doSubstitution(strings.Join(preprocessorArgs, " "), paramValues, commitTime, buildRepos) + "\n"
264+
preprocessorScript := "#!/bin/sh\n/var/workdir/software/system-java/bin/java -jar /var/workdir/software/build-request-processor/quarkus-run.jar " + doSubstitution(strings.Join(preprocessorArgs, " "), paramValues, commitTime, buildRepos) + "\n"
264265
buildScript := doSubstitution(build, paramValues, commitTime, buildRepos)
265266
envVars := extractEnvVar(toolEnv)
266267
cmdArgs := extractArrayParam(PipelineParamGoals, paramValues)
267268
konfluxScript := "#!/bin/sh\n" + envVars + "\nset -- \"$@\" " + cmdArgs + "\n\n" + buildScript
268269

269270
// Diagnostic Containerfile
270-
// TODO: While it doesn't functionally matter, ideally we should match Konflux layout (i.e. /var/workdir etc).
271271
df := "FROM " + buildRequestProcessorImage + " AS build-request-processor" +
272272
"\nFROM " + strings.ReplaceAll(buildRequestProcessorImage, "hacbs-jvm-build-request-processor", "hacbs-jvm-cache") + " AS cache" +
273273
"\nFROM " + recipe.Image +
274274
"\nUSER 0" +
275-
"\nWORKDIR /root" +
275+
"\nWORKDIR /var/workdir" +
276276
"\nENV CACHE_URL=" + doSubstitution("$(params."+PipelineParamCacheUrl+")", paramValues, commitTime, buildRepos) +
277-
"\nRUN mkdir -p /root/project /root/software/settings /original-content/marker && microdnf install procps-ng" +
277+
"\nRUN mkdir -p /var/workdir/software/settings /original-content/marker" +
278278
// TODO: Debug only
279279
"\nRUN rpm -ivh https://vault.centos.org/8.5.2111/BaseOS/x86_64/os/Packages/tree-1.7.0-15.el8.x86_64.rpm" +
280-
"\nCOPY --from=build-request-processor /deployments/ /root/software/build-request-processor" +
280+
"\nCOPY --from=build-request-processor /deployments/ /var/workdir/software/build-request-processor" +
281281
// Copying JDK17 for the cache.
282282
// TODO: Could we determine if we are using UBI8 and avoid this?
283-
"\nCOPY --from=build-request-processor /lib/jvm/jre-17 /root/software/system-java" +
283+
"\nCOPY --from=build-request-processor /lib/jvm/jre-17 /var/workdir/software/system-java" +
284284
"\nCOPY --from=build-request-processor /etc/java/java-17-openjdk /etc/java/java-17-openjdk" +
285-
"\nCOPY --from=cache /deployments/ /root/software/cache" +
285+
"\nCOPY --from=cache /deployments/ /var/workdir/software/cache" +
286286
// Use git script rather than the preBuildImages as they are OCI archives and can't be used with docker/podman.
287+
// TODO: ### Is this gitscript using the correct SHA? The Konflux one is but this is using pre preprocessor changes.
287288
"\nRUN " + doSubstitution(gitScript, paramValues, commitTime, buildRepos) +
288-
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte("#!/bin/sh\n/root/software/system-java/bin/java -Dbuild-policy.default.store-list=rebuilt,central,jboss,redhat -Dkube.disabled=true -Dquarkus.kubernetes-client.trust-certs=true -jar /root/software/cache/quarkus-run.jar >/root/cache.log &"+
289-
"\nwhile ! cat /root/cache.log | grep 'Listening on:'; do\n echo \"Waiting for Cache to start\"\n sleep 1\ndone \n")) + " | base64 -d >/root/start-cache.sh" +
290-
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte(preprocessorScript)) + " | base64 -d >/root/preprocessor.sh" +
291-
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte(buildScript)) + " | base64 -d >/root/build.sh" +
292-
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte("#!/bin/sh\n/root/preprocessor.sh\n"+envVars+"\n/root/build.sh "+cmdArgs+"\n")) + " | base64 -d >/root/run-full-build.sh" +
293-
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte(dockerfileEntryScript)) + " | base64 -d >/root/entry-script.sh" +
294-
"\nRUN chmod +x /root/*.sh" +
295-
"\nCMD [ \"/bin/bash\", \"/root/entry-script.sh\" ]"
289+
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte("#!/bin/sh\n/var/workdir/software/system-java/bin/java -Dbuild-policy.default.store-list=rebuilt,central,jboss,redhat -Dkube.disabled=true -Dquarkus.kubernetes-client.trust-certs=true -jar /var/workdir/software/cache/quarkus-run.jar >/var/workdir/cache.log &"+
290+
"\nwhile ! cat /var/workdir/cache.log | grep 'Listening on:'; do\n echo \"Waiting for Cache to start\"\n sleep 1\ndone \n")) + " | base64 -d >/var/workdir/start-cache.sh" +
291+
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte(preprocessorScript)) + " | base64 -d >/var/workdir/preprocessor.sh" +
292+
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte(buildScript)) + " | base64 -d >/var/workdir/build.sh" +
293+
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte("#!/bin/sh\n/var/workdir/preprocessor.sh\n"+envVars+"\n/var/workdir/build.sh "+cmdArgs+"\n")) + " | base64 -d >/var/workdir/run-full-build.sh" +
294+
"\nRUN echo " + base64.StdEncoding.EncodeToString([]byte(dockerfileEntryScript)) + " | base64 -d >/var/workdir/entry-script.sh" +
295+
"\nRUN chmod +x /var/workdir/*.sh" +
296+
"\nCMD [ \"/bin/bash\", \"/var/workdir/entry-script.sh\" ]"
296297

297298
// Konflux Containerfile
298-
// TODO: While it doesn't functionally matter, ideally we should match Konflux layout (i.e. /var/workdir etc).
299299
kf := "FROM " + recipe.Image +
300300
"\nUSER 0" +
301-
"\nWORKDIR /root" +
302-
"\nRUN mkdir -p /root/project /root/software/settings /original-content/marker" +
301+
"\nWORKDIR /var/workdir" +
302+
"\nRUN mkdir -p /var/workdir/software/settings /original-content/marker" +
303303
// TODO ### HACK : How to use SSL to avoid certificate problem with buildah task?
304304
// "\nENV CACHE_URL=" + "http://jvm-build-workspace-artifact-cache." + jbsConfig.Namespace + ".svc.cluster.local/v2/cache/rebuild" + buildRepos + "/" + strconv.FormatInt(commitTime, 10) +
305305
"\nENV JBS_DISABLE_CACHE=true" +
306-
"\nCOPY .jbs/run-build.sh /root" +
307-
"\nCOPY . /root/project/source/" +
308-
"\nRUN /root/run-build.sh"
306+
"\nCOPY .jbs/run-build.sh /var/workdir" +
307+
"\nCOPY . /var/workdir/workspace/source/" +
308+
"\nRUN /var/workdir/run-build.sh"
309309
// TODO: This is a bit of a hack but as Ant doesn't deploy and the previous implementation relied upon using the
310310
// BuildRequestProcessorImage we need to modify the Containerfile. In future the ant-build.sh should probably
311311
// encapsulate this.
312312
if tool == "ant" {
313313
kf = kf +
314314
"\nFROM " + buildRequestProcessorImage + " AS build-request-processor" +
315315
"\nUSER 0" +
316-
"\nWORKDIR /root" +
317-
"\nCOPY --from=0 /root/project/ /root/project/" +
316+
"\nWORKDIR /var/workdir" +
317+
"\nCOPY --from=0 /var/workdir/ /var/workdir/" +
318318
// Don't think we need to mess with keystore as copy-artifacts is simply calling copy commands.
319319
"\nRUN /opt/jboss/container/java/run/run-java.sh " + doSubstitution(strings.Join(copyArtifactsArgs, " "), []tektonpipeline.Param{}, commitTime, buildRepos) +
320320
"\nFROM scratch" +
321-
"\nCOPY --from=1 /root/project/artifacts /"
321+
"\nCOPY --from=1 /var/workdir/workspace/artifacts /"
322322
} else {
323323
kf = kf +
324324
"\nFROM scratch" +
325-
"\nCOPY --from=0 /root/project/artifacts /"
325+
"\nCOPY --from=0 /var/workdir/workspace/artifacts /"
326326
}
327327

328328
pullPolicy := pullPolicy(buildRequestProcessorImage)
@@ -345,7 +345,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
345345
{Name: PipelineParamPath, Type: tektonpipeline.ParamTypeString},
346346
{Name: PipelineParamEnforceVersion, Type: tektonpipeline.ParamTypeString},
347347
{Name: PipelineParamProjectVersion, Type: tektonpipeline.ParamTypeString},
348-
{Name: PipelineParamCacheUrl, Type: tektonpipeline.ParamTypeString, Default: &tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: cacheUrl + buildRepos + "/" + strconv.FormatInt(commitTime, 10)}},
348+
{Name: PipelineParamCacheUrl, Type: tektonpipeline.ParamTypeString, Default: &tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: cacheUrl}},
349349
}
350350
secretVariables := secretVariables(jbsConfig)
351351

@@ -446,7 +446,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
446446
}
447447

448448
if jbsConfig.Spec.ContainerBuilds {
449-
// TODO: ### Note - its also possible to refer to a remote pipeline ref as well as a task.
449+
// Note - its also possible to refer to a remote pipeline ref as well as a task.
450450
resolver := tektonpipeline.ResolverRef{
451451
Resolver: "git",
452452
Params: []tektonpipeline.Param{
@@ -458,7 +458,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
458458
},
459459
},
460460
{
461-
// TODO: ### Currently always using 'head' of branch.
461+
// Currently always using 'head' of branch.
462462
Name: "revision",
463463
Value: tektonpipeline.ParamValue{
464464
Type: tektonpipeline.ParamTypeString,
@@ -1037,9 +1037,9 @@ func doSubstitution(script string, paramValues []tektonpipeline.Param, commitTim
10371037
}
10381038
}
10391039
script = strings.ReplaceAll(script, "$(params.CACHE_URL)", "http://localhost:8080/v2/cache/rebuild"+buildRepos+"/"+strconv.FormatInt(commitTime, 10)+"/")
1040-
script = strings.ReplaceAll(script, "$(workspaces.build-settings.path)", "/root/software/settings")
1041-
script = strings.ReplaceAll(script, "$(workspaces.source.path)", "/root/project")
1042-
script = strings.ReplaceAll(script, "$(workspaces.tls.path)", "/root/project/tls/service-ca.crt")
1040+
script = strings.ReplaceAll(script, "$(workspaces.build-settings.path)", "/var/workdir/software/settings")
1041+
script = strings.ReplaceAll(script, "$(workspaces.source.path)", "/var/workdir/workspace")
1042+
script = strings.ReplaceAll(script, "$(workspaces.tls.path)", "/var/workdir/software/tls/service-ca.crt")
10431043
return script
10441044
}
10451045

0 commit comments

Comments
 (0)