diff --git a/deploy/crds/base/jvmbuildservice.io_dependencybuilds.yaml b/deploy/crds/base/jvmbuildservice.io_dependencybuilds.yaml index 24e2ee5be..aff69cff4 100644 --- a/deploy/crds/base/jvmbuildservice.io_dependencybuilds.yaml +++ b/deploy/crds/base/jvmbuildservice.io_dependencybuilds.yaml @@ -123,6 +123,9 @@ spec: required: - imageDigest type: object + startTime: + format: int64 + type: integer succeeded: type: boolean required: diff --git a/deploy/overlays/dev-template/rbac.yaml b/deploy/overlays/dev-template/rbac.yaml index d78f0b9b0..23eff9012 100644 --- a/deploy/overlays/dev-template/rbac.yaml +++ b/deploy/overlays/dev-template/rbac.yaml @@ -9,6 +9,14 @@ rules: - jvmbuildservice.io resources: - artifactbuilds +<<<<<<< HEAD +======= + - artifactbuilds/status + - jvmimagescans + - jvmimagescans/status + - dependencybuilds + - dependencybuilds/status +>>>>>>> 17f80a76 (Console files) verbs: - get - list @@ -30,14 +38,54 @@ rules: - apiGroups: - tekton.dev resources: +<<<<<<< HEAD - taskruns/status - pipelineruns/status - taskruns/status +======= + - taskruns + - taskruns/status + - pipelineruns +>>>>>>> 17f80a76 (Console files) - pipelineruns/status verbs: - get - list - watch +<<<<<<< HEAD +======= + + - apiGroups: + - "" + resources: + - pods + - pods/log + verbs: + - get + - list + - watch + - apiGroups: + - "apps" + resources: + - deployments + verbs: + - get + - list + - watch + - apiGroups: + - "" + # note - tekton gives its controller read access to secrets, so any pods there can access secrets in the pods namespace + resources: + - secrets + resourceNames: + - jbs-user-secret + verbs: + - get + - create + - watch + - update + - patch +>>>>>>> 17f80a76 (Console files) --- apiVersion: v1 kind: ServiceAccount diff --git a/java-components/management-console/src/main/java/com/redhat/hacbs/management/importer/DependencyBuildImporter.java b/java-components/management-console/src/main/java/com/redhat/hacbs/management/importer/DependencyBuildImporter.java index 445e39e37..68161c147 100644 --- a/java-components/management-console/src/main/java/com/redhat/hacbs/management/importer/DependencyBuildImporter.java +++ b/java-components/management-console/src/main/java/com/redhat/hacbs/management/importer/DependencyBuildImporter.java @@ -65,14 +65,14 @@ public void doImport(DependencyBuild dependencyBuild) { scm.getPath(), dependencyBuild.getMetadata().getName()); StoredDependencyBuild storedBuild = StoredDependencyBuild - .find("buildIdentifier = :buildIdentifier and uid = :uid", - Parameters.with("buildIdentifier", identifier).and("uid", dependencyBuild.getMetadata().getUid())) + .find("buildIdentifier = :buildIdentifier", + Parameters.with("buildIdentifier", identifier)) .firstResult(); if (storedBuild == null) { storedBuild = new StoredDependencyBuild(); storedBuild.buildIdentifier = identifier; - storedBuild.uid = dependencyBuild.getMetadata().getUid(); } + storedBuild.uid = dependencyBuild.getMetadata().getUid(); if (s3Bucket != null) { storedBuild.buildYamlUrl = "s3://" + s3Bucket + "/builds/" + dependencyBuild.getMetadata().getName() + "/" + dependencyBuild.getMetadata().getUid() + ".yaml"; @@ -114,9 +114,19 @@ public void doImport(DependencyBuild dependencyBuild) { } if (dependencyBuild.getStatus().getBuildAttempts() != null) { for (var i : dependencyBuild.getStatus().getBuildAttempts()) { - BuildAttempt attempt = new BuildAttempt(); + boolean found = false; + BuildAttempt attempt = null; + for (var ba : storedBuild.buildAttempts) { + if (ba.startTime != null && ba.startTime.getTime() == i.getBuild().getStartTime()) { + //existing one, just update it + attempt = ba; + } + } + if (attempt == null) { + attempt = new BuildAttempt(); + storedBuild.buildAttempts.add(attempt); + } attempt.dependencyBuild = storedBuild; - storedBuild.buildAttempts.add(attempt); attempt.jdk = i.getBuildRecipe().getJavaVersion(); attempt.mavenVersion = i.getBuildRecipe().getToolVersions().get("maven"); attempt.gradleVersion = i.getBuildRecipe().getToolVersions().get("gradle"); @@ -136,10 +146,11 @@ public void doImport(DependencyBuild dependencyBuild) { : i.getBuildRecipe().getAllowedDifferences().stream() .collect(Collectors.joining("\n")); attempt.successful = Boolean.TRUE.equals(i.getBuild().getSucceeded()); + var finalAttempt = attempt; if (i.getBuildRecipe().getAdditionalDownloads() != null) { attempt.additionalDownloads = i.getBuildRecipe().getAdditionalDownloads().stream().map(s -> { AdditionalDownload download = new AdditionalDownload(); - download.buildAttempt = attempt; + download.buildAttempt = finalAttempt; download.binaryPath = s.getBinaryPath(); download.fileName = s.getFileName(); download.packageName = s.getPackageName(); @@ -149,7 +160,7 @@ public void doImport(DependencyBuild dependencyBuild) { return download; }).collect(Collectors.toList()); } - mavenRepo.ifPresent(s -> attempt.mavenRepository = s.replace("/repository/maven-releases", + mavenRepo.ifPresent(s -> finalAttempt.mavenRepository = s.replace("/repository/maven-releases", "/service/rest/repository/browse/maven-releases")); if (s3Bucket != null) { diff --git a/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/BuildAttempt.java b/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/BuildAttempt.java index 4c08c83f8..ca22a3965 100644 --- a/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/BuildAttempt.java +++ b/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/BuildAttempt.java @@ -1,5 +1,6 @@ package com.redhat.hacbs.management.model; +import java.util.Date; import java.util.List; import jakarta.persistence.CascadeType; @@ -7,6 +8,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; +import jakarta.persistence.Temporal; +import jakarta.persistence.TemporalType; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -74,6 +77,10 @@ public class BuildAttempt extends PanacheEntity { @Column(length = -1) public String gitArchiveUrl; + @Column + @Temporal(TemporalType.TIMESTAMP) + public Date startTime; + //this is pretty yuck, but we don't want a whole new table to store a List public void commandLine(List commandLine) { var mapper = Arc.container().instance(ObjectMapper.class); @@ -92,4 +99,5 @@ public List commandLine() { throw new RuntimeException(e); } } + } diff --git a/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/StoredDependencyBuild.java b/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/StoredDependencyBuild.java index cf10ad063..8332f260b 100644 --- a/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/StoredDependencyBuild.java +++ b/java-components/management-console/src/main/java/com/redhat/hacbs/management/model/StoredDependencyBuild.java @@ -18,7 +18,7 @@ import io.quarkus.hibernate.orm.panache.PanacheEntity; @Entity -@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "buildidentifier_id", "uid" })) +@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "buildidentifier_id" })) public class StoredDependencyBuild extends PanacheEntity { @ManyToOne(optional = false) diff --git a/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/DeploymentWatcher.java b/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/DeploymentWatcher.java index 879ba145b..b78579df7 100644 --- a/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/DeploymentWatcher.java +++ b/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/DeploymentWatcher.java @@ -59,7 +59,7 @@ public void setup() { @Override public void run() { - client.resources(Pod.class).inAnyNamespace().inform(new ResourceEventHandler() { + client.resources(Pod.class).inform(new ResourceEventHandler() { @Override public void onAdd(Pod resource) { if (resource.getMetadata().getName().contains("jvm-build-workspace-artifact-cache") diff --git a/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/JvmImageScanWatcher.java b/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/JvmImageScanWatcher.java index 7d8110629..146880a35 100644 --- a/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/JvmImageScanWatcher.java +++ b/java-components/management-console/src/main/java/com/redhat/hacbs/management/watcher/JvmImageScanWatcher.java @@ -55,7 +55,7 @@ public void setup() { Log.warnf("image scan importer disabled"); return; } - client.resources(JvmImageScan.class).inAnyNamespace().inform(new ResourceEventHandler() { + client.resources(JvmImageScan.class).inform(new ResourceEventHandler() { @Override public void onAdd(JvmImageScan obj) { ContainerImage image = ensureImageExists(obj); diff --git a/java-components/management-console/src/main/resources/db/migration/V1.0.0__management-console.sql b/java-components/management-console/src/main/resources/db/migration/V1.0.0__management-console.sql index 489dc5de5..491efe259 100644 --- a/java-components/management-console/src/main/resources/db/migration/V1.0.0__management-console.sql +++ b/java-components/management-console/src/main/resources/db/migration/V1.0.0__management-console.sql @@ -94,6 +94,7 @@ preBuildScript text, repositories varchar(255), sbtVersion varchar(255), + startTime timestamp(6), successful boolean not null, tool varchar(255), upstreamDifferences text, @@ -269,7 +270,7 @@ version varchar(255), buildIdentifier_id bigint not null, primary key (id), - constraint UKmqhxn62o5bhx4qwwrajohpgn unique (buildIdentifier_id, uid) + constraint UK3vhc9gqgiq7hppr3iglc2n0b8 unique (buildIdentifier_id) ); create table StoredDependencyBuild_BuildAttempt ( @@ -294,162 +295,162 @@ primary key (id) ); - alter table if exists AdditionalDownload - add constraint FK39eh5a8xxp46q3gtmeyncch1h - foreign key (buildAttempt_id) + alter table if exists AdditionalDownload + add constraint FK39eh5a8xxp46q3gtmeyncch1h + foreign key (buildAttempt_id) references BuildAttempt; - alter table if exists BuildAttempt - add constraint FK2vqtsy25ccjmikislqo3a0aim - foreign key (dependencyBuild_id) + alter table if exists BuildAttempt + add constraint FK2vqtsy25ccjmikislqo3a0aim + foreign key (dependencyBuild_id) references StoredDependencyBuild; - alter table if exists BuildAttempt_AdditionalDownload - add constraint FKbiicbxkn2vh9dllrjma0odjw0 - foreign key (additionalDownloads_id) + alter table if exists BuildAttempt_AdditionalDownload + add constraint FKbiicbxkn2vh9dllrjma0odjw0 + foreign key (additionalDownloads_id) references AdditionalDownload; - alter table if exists BuildAttempt_AdditionalDownload - add constraint FKbmavpy9fpr3g86o5qfkmf5srb - foreign key (BuildAttempt_id) + alter table if exists BuildAttempt_AdditionalDownload + add constraint FKbmavpy9fpr3g86o5qfkmf5srb + foreign key (BuildAttempt_id) references BuildAttempt; - alter table if exists BuildAttempt_BuildFile - add constraint FKaeo4m7letkmwfyoyopm8yj0gj - foreign key (storedBuildResults_id) + alter table if exists BuildAttempt_BuildFile + add constraint FKaeo4m7letkmwfyoyopm8yj0gj + foreign key (storedBuildResults_id) references BuildFile; - alter table if exists BuildAttempt_BuildFile - add constraint FKc5ag6faehmls1owi8oykcs9qy - foreign key (BuildAttempt_id) + alter table if exists BuildAttempt_BuildFile + add constraint FKc5ag6faehmls1owi8oykcs9qy + foreign key (BuildAttempt_id) references BuildAttempt; - alter table if exists BuildFile - add constraint FKmke5rkkm1roj9nq6c77yyr42j - foreign key (build_id) + alter table if exists BuildFile + add constraint FKmke5rkkm1roj9nq6c77yyr42j + foreign key (build_id) references BuildAttempt; - alter table if exists BuildIdentifier - add constraint FKhy8g6bovqm0fnesgul4293uv0 - foreign key (repository_id) + alter table if exists BuildIdentifier + add constraint FKhy8g6bovqm0fnesgul4293uv0 + foreign key (repository_id) references ScmRepository; - alter table if exists BuildQueue - add constraint FKdul89emvqjn1ne0jidcyqs6s1 - foreign key (mavenArtifact_id) + alter table if exists BuildQueue + add constraint FKdul89emvqjn1ne0jidcyqs6s1 + foreign key (mavenArtifact_id) references MavenArtifact; - alter table if exists BuildSBOMDiscoveryInfo - add constraint FKxguvu08ig0ktv7b0tnjr38dx - foreign key (build_id) + alter table if exists BuildSBOMDiscoveryInfo + add constraint FKxguvu08ig0ktv7b0tnjr38dx + foreign key (build_id) references StoredDependencyBuild; - alter table if exists ContainerImage - add constraint FKegmav1y7dg5t2ykl7bdn7sk3e - foreign key (dependencySet_id) + alter table if exists ContainerImage + add constraint FKegmav1y7dg5t2ykl7bdn7sk3e + foreign key (dependencySet_id) references DependencySet; - alter table if exists GithubActionsBuild - add constraint FK4b0h7wssxcjduxyntp07yonj - foreign key (dependencySet_id) + alter table if exists GithubActionsBuild + add constraint FK4b0h7wssxcjduxyntp07yonj + foreign key (dependencySet_id) references DependencySet; - alter table if exists IdentifiedDependency - add constraint FK3pnb3jtp9ckrvq5i7toiaqjh0 - foreign key (dependencySet_id) + alter table if exists IdentifiedDependency + add constraint FK3pnb3jtp9ckrvq5i7toiaqjh0 + foreign key (dependencySet_id) references DependencySet; - alter table if exists IdentifiedDependency - add constraint FKi7f1ero4w4os5o1b96ut7tncb - foreign key (mavenArtifact_id) + alter table if exists IdentifiedDependency + add constraint FKi7f1ero4w4os5o1b96ut7tncb + foreign key (mavenArtifact_id) references MavenArtifact; - alter table if exists jbs_user_Role - add constraint FKgm8053kwsm0bf8diecjsrm5wh - foreign key (roles_id) + alter table if exists jbs_user_Role + add constraint FKgm8053kwsm0bf8diecjsrm5wh + foreign key (roles_id) references Role; - alter table if exists jbs_user_Role - add constraint FKeojvfxx1yoge641w29ncfc5ih - foreign key (users_id) + alter table if exists jbs_user_Role + add constraint FKeojvfxx1yoge641w29ncfc5ih + foreign key (users_id) references jbs_user; - alter table if exists MavenArtifact - add constraint FKl9mu28j56nnr9dgmlelntn1rw - foreign key (identifier_id) + alter table if exists MavenArtifact + add constraint FKl9mu28j56nnr9dgmlelntn1rw + foreign key (identifier_id) references ArtifactIdentifier; - alter table if exists MavenArtifactLabel - add constraint FK655fjw29db296xsnwaa4cux02 - foreign key (artifact_id) + alter table if exists MavenArtifactLabel + add constraint FK655fjw29db296xsnwaa4cux02 + foreign key (artifact_id) references MavenArtifact; - alter table if exists MavenArtifactLabel - add constraint FK8dxbi5yqum5yaldfr2qa8a63q - foreign key (name_id) + alter table if exists MavenArtifactLabel + add constraint FK8dxbi5yqum5yaldfr2qa8a63q + foreign key (name_id) references ArtifactLabelName; - alter table if exists ShadingDetails - add constraint FKijuafi86lbamrk4rx9v9ih36n - foreign key (contaminant_id) + alter table if exists ShadingDetails + add constraint FKijuafi86lbamrk4rx9v9ih36n + foreign key (contaminant_id) references MavenArtifact; - alter table if exists ShadingDetails_MavenArtifact - add constraint FKcsmwpetci1vywfi82qewxi1g2 - foreign key (contaminatedArtifacts_id) + alter table if exists ShadingDetails_MavenArtifact + add constraint FKcsmwpetci1vywfi82qewxi1g2 + foreign key (contaminatedArtifacts_id) references MavenArtifact; - alter table if exists ShadingDetails_MavenArtifact - add constraint FKtebabkifoet26ei0xilant7l - foreign key (ShadingDetails_id) + alter table if exists ShadingDetails_MavenArtifact + add constraint FKtebabkifoet26ei0xilant7l + foreign key (ShadingDetails_id) references ShadingDetails; - alter table if exists StoredArtifactBuild - add constraint FK6pda7fm0eqj60yjy4v2bu7163 - foreign key (buildIdentifier_id) + alter table if exists StoredArtifactBuild + add constraint FK6pda7fm0eqj60yjy4v2bu7163 + foreign key (buildIdentifier_id) references BuildIdentifier; - alter table if exists StoredArtifactBuild - add constraint FKdc6wbe97oyhmpjww6ukg1u0q7 - foreign key (mavenArtifact_id) + alter table if exists StoredArtifactBuild + add constraint FKdc6wbe97oyhmpjww6ukg1u0q7 + foreign key (mavenArtifact_id) references MavenArtifact; - alter table if exists StoredDependencyBuild - add constraint FK7hob7xntbx8beddme3twb0mxm - foreign key (buildIdentifier_id) + alter table if exists StoredDependencyBuild + add constraint FK7hob7xntbx8beddme3twb0mxm + foreign key (buildIdentifier_id) references BuildIdentifier; - alter table if exists StoredDependencyBuild_BuildAttempt - add constraint FKmwoxb55k088vga72oev550d1 - foreign key (buildAttempts_id) + alter table if exists StoredDependencyBuild_BuildAttempt + add constraint FKmwoxb55k088vga72oev550d1 + foreign key (buildAttempts_id) references BuildAttempt; - alter table if exists StoredDependencyBuild_BuildAttempt - add constraint FKgfodrlq1erw0qn5p39axeb0fq - foreign key (StoredDependencyBuild_id) + alter table if exists StoredDependencyBuild_BuildAttempt + add constraint FKgfodrlq1erw0qn5p39axeb0fq + foreign key (StoredDependencyBuild_id) references StoredDependencyBuild; - alter table if exists StoredDependencyBuild_MavenArtifact - add constraint FKhche325otxfgggxd5a7u5hdtf - foreign key (producedArtifacts_id) + alter table if exists StoredDependencyBuild_MavenArtifact + add constraint FKhche325otxfgggxd5a7u5hdtf + foreign key (producedArtifacts_id) references MavenArtifact; - alter table if exists StoredDependencyBuild_MavenArtifact - add constraint FKrqvdnenqvtw15sprk88fx1rnc - foreign key (StoredDependencyBuild_id) + alter table if exists StoredDependencyBuild_MavenArtifact + add constraint FKrqvdnenqvtw15sprk88fx1rnc + foreign key (StoredDependencyBuild_id) references StoredDependencyBuild; - alter table if exists StoredDependencyBuild_ShadingDetails - add constraint FKsec76urqowvrcboayagv2dy2c - foreign key (shadingDetails_id) + alter table if exists StoredDependencyBuild_ShadingDetails + add constraint FKsec76urqowvrcboayagv2dy2c + foreign key (shadingDetails_id) references ShadingDetails; - alter table if exists StoredDependencyBuild_ShadingDetails - add constraint FKngenliybt8mfng3smkeugxvlf - foreign key (StoredDependencyBuild_id) + alter table if exists StoredDependencyBuild_ShadingDetails + add constraint FKngenliybt8mfng3smkeugxvlf + foreign key (StoredDependencyBuild_id) references StoredDependencyBuild; - alter table if exists VersionDiscoveryQueue - add constraint FKhfmeop7e32qo1um0phetom2ut - foreign key (artifactIdentifier_id) + alter table if exists VersionDiscoveryQueue + add constraint FKhfmeop7e32qo1um0phetom2ut + foreign key (artifactIdentifier_id) references ArtifactIdentifier; diff --git a/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_dependencybuilds.yaml b/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_dependencybuilds.yaml index 24e2ee5be..aff69cff4 100644 --- a/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_dependencybuilds.yaml +++ b/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_dependencybuilds.yaml @@ -123,6 +123,9 @@ spec: required: - imageDigest type: object + startTime: + format: int64 + type: integer succeeded: type: boolean required: diff --git a/pkg/apis/jvmbuildservice/v1alpha1/dependencybuild_types.go b/pkg/apis/jvmbuildservice/v1alpha1/dependencybuild_types.go index bd08da673..24b2c89c6 100644 --- a/pkg/apis/jvmbuildservice/v1alpha1/dependencybuild_types.go +++ b/pkg/apis/jvmbuildservice/v1alpha1/dependencybuild_types.go @@ -79,6 +79,7 @@ type BuildPipelineRun struct { Succeeded bool `json:"succeeded,omitempty"` DiagnosticDockerFile string `json:"diagnosticDockerFile,omitempty"` Results *BuildPipelineRunResults `json:"results,omitempty"` + StartTime int64 `json:"startTime,omitempty"` } type BuildPipelineRunResults struct { diff --git a/pkg/reconciler/dependencybuild/dependencybuild.go b/pkg/reconciler/dependencybuild/dependencybuild.go index 35f875b27..edace15a1 100644 --- a/pkg/reconciler/dependencybuild/dependencybuild.go +++ b/pkg/reconciler/dependencybuild/dependencybuild.go @@ -466,6 +466,7 @@ func (r *ReconcileDependencyBuild) handleStateSubmitBuild(ctx context.Context, d pipelineName := currentDependencyBuildPipelineName(db) ba.Build = &v1alpha1.BuildPipelineRun{ PipelineName: pipelineName, + StartTime: time.Now().Unix(), } //and remove if from the potential list db.Status.PotentialBuildRecipes = db.Status.PotentialBuildRecipes[1:]