Skip to content

Commit f3e5c8e

Browse files
committed
Convert pipeline to static and fill in values in java code
1 parent 5937ace commit f3e5c8e

File tree

6 files changed

+59
-100
lines changed

6 files changed

+59
-100
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,20 @@ public void run() {
145145
fi
146146
echo "PATH:$PATH"
147147
148+
update-ca-trust
149+
150+
# Go through certificates and insert them into the cacerts
151+
for cert in $(find /etc/pki/ca-trust/source/anchors -type f); do
152+
echo "Inserting $cert into java cacerts"
153+
keytool -import -alias $(basename $cert)-ca \\
154+
-file $cert \\
155+
-keystore /etc/pki/java/cacerts \\
156+
-storepass changeit --noprompt
157+
done
158+
148159
# End of generic build script
160+
161+
echo "Building the project ..."
149162
""";
150163

151164
if (isNotEmpty(buildScript)) {

java-components/cli/src/main/java/com/redhat/hacbs/cli/driver/Pipeline.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public void run() {
4444
.repositoryDependencyUrl(dependencies)
4545
.repositoryBuildContentId("test-maven-konflux-int-0001")
4646
.recipeImage(recipeImage)
47+
// Just use default from buildah-oci-ta for now.
48+
.podMemoryOverride("4Gi")
4749
.build();
4850
driver.create(request);
4951
}

java-components/driver/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
<groupId>io.quarkiverse.tektonclient</groupId>
2929
<artifactId>quarkus-tekton-client</artifactId>
3030
</dependency>
31-
<!-- <dependency>-->
32-
<!-- <groupId>io.quarkus</groupId>-->
33-
<!-- <artifactId>quarkus-openshift-client</artifactId>-->
34-
<!-- </dependency>-->
31+
<dependency>
32+
<groupId>io.quarkus</groupId>
33+
<artifactId>quarkus-openshift-client</artifactId>
34+
</dependency>
3535
<dependency>
3636
<groupId>io.quarkus</groupId>
3737
<artifactId>quarkus-kubernetes-client</artifactId>

java-components/driver/src/main/java/com/redhat/hacbs/driver/Driver.java

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.apache.commons.lang3.StringUtils.isEmpty;
44

55
import java.io.IOException;
6-
import java.nio.charset.StandardCharsets;
76
import java.nio.file.Path;
87
import java.util.HashMap;
98
import java.util.Map;
@@ -12,24 +11,22 @@
1211
import jakarta.enterprise.context.RequestScoped;
1312
import jakarta.inject.Inject;
1413

15-
import org.apache.commons.io.FileUtils;
1614
import org.apache.commons.io.IOUtils;
17-
import org.apache.commons.text.StringSubstitutor;
1815
import org.eclipse.microprofile.config.ConfigProvider;
1916
import org.eclipse.microprofile.config.inject.ConfigProperty;
2017
import org.eclipse.microprofile.rest.client.inject.RestClient;
2118
import org.slf4j.Logger;
2219
import org.slf4j.LoggerFactory;
2320

24-
import com.fasterxml.jackson.core.JsonProcessingException;
25-
import com.fasterxml.jackson.databind.ObjectMapper;
26-
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2721
import com.redhat.hacbs.driver.clients.IndyService;
2822
import com.redhat.hacbs.driver.clients.IndyTokenRequestDTO;
2923
import com.redhat.hacbs.driver.clients.IndyTokenResponseDTO;
3024
import com.redhat.hacbs.driver.dto.BuildRequest;
3125

26+
import io.fabric8.kubernetes.api.model.Quantity;
3227
import io.fabric8.kubernetes.client.KubernetesClient;
28+
import io.fabric8.tekton.client.TektonClient;
29+
import io.fabric8.tekton.pipeline.v1.ParamBuilder;
3330
import io.fabric8.tekton.pipeline.v1.PipelineRun;
3431
import io.quarkus.oidc.client.OidcClient;
3532
import lombok.Setter;
@@ -39,15 +36,12 @@ public class Driver {
3936

4037
private static final Logger logger = LoggerFactory.getLogger(Driver.class);
4138

42-
private static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
43-
4439
@Inject
4540
OidcClient oidcClient;
4641

4742
@RestClient
4843
IndyService indyService;
4944

50-
// TODO: Could use KubernetesClient or OpenShiftClient
5145
@Inject
5246
KubernetesClient client;
5347

@@ -72,40 +66,55 @@ public void create(BuildRequest buildRequest) {
7266
tokenResponseDTO = indyService.getAuthToken(
7367
new IndyTokenRequestDTO(buildRequest.getRepositoryBuildContentId()),
7468
"Bearer " + getFreshAccessToken());
75-
logger.debug("### new access token: {}", tokenResponseDTO.getToken()); // TODO: REMOVE
76-
7769
}
7870

7971
Map<String, String> templateProperties = new HashMap<>();
80-
templateProperties.put("REQUEST_PROCESSOR", processor);
81-
templateProperties.put("QUAY_REPO", quayRepo);
82-
templateProperties.put("URL", buildRequest.getScmUrl());
83-
templateProperties.put("REVISION", buildRequest.getScmRevision());
84-
templateProperties.put("RECIPE_IMAGE", buildRequest.getRecipeImage());
72+
templateProperties.put("ACCESS_TOKEN", tokenResponseDTO.getToken());
73+
templateProperties.put("BUILD_ID", buildRequest.getRepositoryBuildContentId());
74+
templateProperties.put("BUILD_SCRIPT", buildRequest.getBuildScript());
8575
templateProperties.put("BUILD_TOOL", buildRequest.getBuildTool());
8676
templateProperties.put("BUILD_TOOL_VERSION", buildRequest.getBuildToolVersion());
8777
templateProperties.put("JAVA_VERSION", buildRequest.getJavaVersion());
88-
templateProperties.put("BUILD_SCRIPT", buildRequest.getBuildScript());
89-
templateProperties.put("MVN_REPO_DEPLOY_URL", buildRequest.getRepositoryDeployUrl());
9078
templateProperties.put("MVN_REPO_DEPENDENCIES_URL", buildRequest.getRepositoryDependencyUrl());
91-
templateProperties.put("ACCESS_TOKEN", tokenResponseDTO.getToken());
92-
templateProperties.put("BUILD_ID", buildRequest.getRepositoryBuildContentId());
79+
templateProperties.put("MVN_REPO_DEPLOY_URL", buildRequest.getRepositoryDeployUrl());
80+
templateProperties.put("QUAY_REPO", quayRepo);
81+
templateProperties.put("RECIPE_IMAGE", buildRequest.getRecipeImage());
82+
templateProperties.put("JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE", processor);
83+
templateProperties.put("REVISION", buildRequest.getScmRevision());
84+
templateProperties.put("URL", buildRequest.getScmUrl());
9385

94-
String pipeline = "";
86+
PipelineRun pipelineRun = null;
9587
try {
88+
var tc = client.adapt(TektonClient.class);
89+
// Various ways to create the initial PipelineRun object. We can use an objectmapper,
90+
// client.getKubernetesSerialization() or the load calls on the Fabric8 objects.
9691
if (customPipeline.isEmpty()) {
97-
pipeline = IOUtils.resourceToString("pipeline.yaml", StandardCharsets.UTF_8,
98-
Thread.currentThread().getContextClassLoader());
92+
pipelineRun = tc.v1().pipelineRuns()
93+
.load(IOUtils.resourceToURL("pipeline.yaml", Thread.currentThread().getContextClassLoader())).item();
9994
} else {
100-
pipeline = FileUtils.readFileToString(Path.of(customPipeline.get()).toFile(), StandardCharsets.UTF_8);
95+
pipelineRun = tc.v1().pipelineRuns().load(Path.of(customPipeline.get()).toFile()).item();
10196
}
10297
} catch (IOException e) {
98+
e.printStackTrace();
10399
// TODO: process
104100
}
105-
106-
PipelineRun run = createModelNode(pipeline, templateProperties, PipelineRun.class);
107-
108-
var created = client.resource(run).inNamespace(buildRequest.getNamespace()).create();
101+
pipelineRun = pipelineRun.edit().editOrNewSpec()
102+
.addAllToParams(templateProperties.entrySet().stream()
103+
.map(t -> new ParamBuilder().withName(t.getKey()).withNewValue(t.getValue()).build()).toList())
104+
.editFirstTaskRunSpec()
105+
.editFirstStepSpec()
106+
.editComputeResources()
107+
.addToLimits("memory", new Quantity(buildRequest.getPodMemoryOverride()))
108+
.addToRequests("memory", new Quantity(buildRequest.getPodMemoryOverride()))
109+
.endComputeResources()
110+
.endStepSpec()
111+
.endTaskRunSpec()
112+
.endSpec().build();
113+
114+
System.err.println("### Got p " + pipelineRun);
115+
// PipelineRun run = createModelNode(pipeline, templateProperties, PipelineRun.class);
116+
//run.getSpec().setParams();
117+
var created = client.resource(pipelineRun).inNamespace(buildRequest.getNamespace()).create();
109118
}
110119

111120
/**
@@ -115,22 +124,6 @@ public void create(BuildRequest buildRequest) {
115124
* @return fresh access token
116125
*/
117126
public String getFreshAccessToken() {
118-
var result = oidcClient.getTokens().await().indefinitely().getAccessToken();
119-
logger.debug("### access token: {}", result); // TODO: REMOVE
120-
return result;
121-
}
122-
123-
private <T> T createModelNode(String resourceDefinition, Map<String, String> properties, Class<T> clazz) {
124-
String definition = StringSubstitutor.replace(resourceDefinition, properties, "%{", "}");
125-
126-
if (logger.isTraceEnabled()) {
127-
logger.trace("Node definition: {}", definition);
128-
}
129-
130-
try {
131-
return yamlMapper.readValue(definition, clazz);
132-
} catch (JsonProcessingException e) {
133-
throw new RuntimeException(e);
134-
}
127+
return oidcClient.getTokens().await().indefinitely().getAccessToken();
135128
}
136129
}

java-components/driver/src/main/java/com/redhat/hacbs/driver/dto/BuildRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ public class BuildRequest {
3939

4040
private final String namespace;
4141

42-
// TODO: NYI
43-
// private final String podMemoryOverride;
42+
private final String podMemoryOverride;
4443
}

java-components/driver/src/main/resources/pipeline.yaml

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ spec:
99
# TODO: This will eventually be build-definitions repository
1010
- name: url
1111
value: https://raw.githubusercontent.com/rnc/jvm-build-service/refs/heads/NCL8774/deploy/pipeline/mw-pipeline-v0.1.yaml
12-
#value: https://raw.githubusercontent.com/rnc/jvm-build-service/refs/heads/NCL8774/deploy/pipeline/mw-pipeline-v0.1.yaml
13-
1412
workspaces:
1513
- name: source
1614
# TODO: If we have a custom git step we can share this with prebuild thereby eliminating the need for a volumeClaimTemplate
@@ -27,50 +25,10 @@ spec:
2725
storage: 1Gi
2826
status: {}
2927
params:
30-
- name: QUAY_REPO
31-
value: "%{QUAY_REPO}"
32-
- name: URL
33-
value: "%{URL}"
34-
- name: REVISION
35-
value: "%{REVISION}"
36-
- name: RECIPE_IMAGE
37-
value: "%{RECIPE_IMAGE}"
38-
- name: BUILD_TOOL
39-
value: "%{BUILD_TOOL}"
40-
- name: BUILD_TOOL_VERSION
41-
value: "%{BUILD_TOOL_VERSION}"
42-
- name: JAVA_VERSION
43-
value: "%{JAVA_VERSION}"
44-
- name: BUILD_SCRIPT
45-
value: |
46-
update-ca-trust
47-
48-
# Go through certificates and insert them into the cacerts
49-
for cert in /etc/pki/ca-trust/source/anchors/*; do
50-
echo "inserting $cert into java cacerts"
51-
keytool -import -alias $(basename $cert)-ca \
52-
-file $cert \
53-
-keystore /etc/pki/java/cacerts \
54-
-storepass changeit --noprompt
55-
done;
56-
57-
echo "Building the project ..."
58-
59-
%{BUILD_SCRIPT}
60-
- name: MVN_REPO_DEPLOY_URL
61-
value: "%{MVN_REPO_DEPLOY_URL}"
62-
- name: MVN_REPO_DEPENDENCIES_URL
63-
value: "%{MVN_REPO_DEPENDENCIES_URL}"
64-
- name: ACCESS_TOKEN
65-
value: "%{ACCESS_TOKEN}"
66-
- name: BUILD_ID
67-
value: "%{BUILD_ID}"
6828
- name: caTrustConfigMapName
6929
value: custom-ca
7030
- name: ENABLE_INDY_PROXY
7131
value: "false"
72-
- name: JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE
73-
value: "%{REQUEST_PROCESSOR}"
7432
# TODO: Should PNC set both limits and requests? See
7533
# https://home.robusta.dev/blog/kubernetes-memory-limit
7634
# https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
@@ -79,13 +37,7 @@ spec:
7937
stepSpecs:
8038
- name: build
8139
computeResources:
82-
limits:
83-
# Default in buildah-oci-ta is 4Gi
84-
# TODO: Configure as %{MEMORY}
85-
memory: 5Gi
86-
requests:
87-
# Default in buildah-oci-ta is 1Gi
88-
memory: 5Gi
40+
# limits/requests memory are configured dynamically in Driver.
8941
taskRunTemplate:
9042
podTemplate:
9143
env:

0 commit comments

Comments
 (0)