Skip to content

Commit

Permalink
Add GitArchive information to BuildAttempt
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Nov 27, 2023
1 parent e1a5f3d commit c05a625
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 59 deletions.
10 changes: 10 additions & 0 deletions deploy/crds/base/jvmbuildservice.io_dependencybuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ spec:
items:
type: string
type: array
gitArchive:
description: Git Archive information
properties:
url:
type: string
tag:
type: string
sha:
type: string
type: object
hermeticBuildImage:
description: The hermetic build image produced by the
build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public void run() {
try {
Set<String> gavs = new HashSet<>();
Map<String, Set<String>> contaminatedPaths = new HashMap<>();
Map<String, Set<String>> contaminatedGavs = new HashMap<>();
Map<String, String> archivedSourceTags = new HashMap<>();
Map<String, Contaminates> contaminatedGavs = new HashMap<>();
Git.GitStatus archivedSourceTags = new Git.GitStatus();

// Save the source first regardless of deployment checks
if (isNotEmpty(gitIdentity) && gitToken.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;

import org.eclipse.jgit.api.errors.GitAPIException;
Expand All @@ -27,7 +25,7 @@ public abstract class Git {
public abstract void create(String name)
throws IOException, URISyntaxException;

public abstract Map<String, String> add(Path path, String commit, String imageId)
public abstract GitStatus add(Path path, String commit, String imageId)
throws IOException;

/**
Expand Down Expand Up @@ -65,7 +63,7 @@ public static Git builder(String endpoint, String identity, String token, boolea
}
}

protected Map<String, String> pushRepository(Path path, String httpTransportUrl, String commit, String imageId) {
protected GitStatus pushRepository(Path path, String httpTransportUrl, String commit, String imageId) {
try (var jGit = org.eclipse.jgit.api.Git.init().setDirectory(path.toFile()).call()) {
// Find the tag name associated with the commit. Then append the unique imageId. This is from the Go code
// and is a hash of abr.Status.SCMInfo.SCMURL + abr.Status.SCMInfo.Tag + abr.Status.SCMInfo.Path
Expand Down Expand Up @@ -109,9 +107,8 @@ protected Map<String, String> pushRepository(Path path, String httpTransportUrl,
+ result.getRemoteUpdates());
}

return Collections.singletonMap(Repository.shortenRefName(tagRefUnique.getName()),
return new GitStatus(httpTransportUrl, Repository.shortenRefName(tagRefUnique.getName()),
jRepo.getRefDatabase().peel(tagRefUnique).getPeeledObjectId().getName());

} catch (GitAPIException | IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -134,4 +131,24 @@ protected String parseScmURI(String scmUri)
}

abstract String groupSplit();

public static class GitStatus {
public String url;
public String tag;
public String sha;

public GitStatus() {
}

public GitStatus(String url, String tag, String sha) {
this.url = url;
this.tag = tag;
this.sha = sha;
}

@Override
public String toString() {
return "GitStatus{url='" + url + "', tag='" + tag + "', sha='" + sha + "'}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Map;

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.kohsuke.github.GHRepository;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void create(String scmUri)
}

@Override
public Map<String, String> add(Path path, String commit, String imageId) {
public GitStatus add(Path path, String commit, String imageId) {
if (repository == null) {
throw new RuntimeException("Call create first");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Map;

import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.gitlab4j.api.GitLabApi;
Expand Down Expand Up @@ -41,7 +40,6 @@ public GitLab(String endpoint, String identity, String token, boolean ssl) {
public void create(String scmUri)
throws URISyntaxException {
String name = parseScmURI(scmUri);
Log.infof("Creating repository with name %s", name);
try {
project = gitLabApi.getProjectApi().getUserProjectsStream(owner, new ProjectFilter().withSearch(name))
.filter(p -> p.getName().equals(name))
Expand All @@ -68,7 +66,7 @@ public void create(String scmUri)
}

@Override
public Map<String, String> add(Path path, String commit, String imageId)
public GitStatus add(Path path, String commit, String imageId)
throws IOException {
if (project == null) {
throw new RuntimeException("Call create first");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.builder.DiffResult;
import org.jboss.logging.Logger;

import com.redhat.hacbs.container.verifier.asm.AsmDiffable;

public class DiffUtils {
private static final Logger Log = Logger.getLogger(DiffUtils.class);

public record DiffResults(Set<String> shared, Set<String> added, Set<String> deleted,
Map<String, DiffResult<?>> diffResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
import org.eclipse.aether.util.repository.DefaultMirrorSelector;
import org.jboss.logging.Logger;

import io.quarkus.logging.Log;

public class MavenUtils {
private static final Logger Log = Logger.getLogger(MavenUtils.class);

public static Settings newSettings(Path globalSettingsFile, Path settingsFile) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,19 @@
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.repository.RemoteRepository.Builder;
import org.jboss.logging.Logger;

import com.redhat.hacbs.container.results.ResultsUpdater;
import com.redhat.hacbs.container.verifier.asm.JarInfo;

import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.logging.Log;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "verify-built-artifacts")
public class VerifyBuiltArtifactsCommand implements Callable<Integer> {
private static final Logger Log = Logger.getLogger(VerifyBuiltArtifactsCommand.class);

static class LocalOptions {
@Option(required = true, names = { "-of", "--original-file" })
Expand Down Expand Up @@ -139,7 +138,6 @@ public Integer call() {
session.setReadOnly();
}

Log.debugf("Deploy path: %s", options.mavenOptions.deployPath);
var futureResults = new HashMap<String, Future<List<String>>>();

Files.walkFileTree(options.mavenOptions.deployPath, new SimpleFileVisitor<>() {
Expand Down Expand Up @@ -191,7 +189,7 @@ public List<String> call() throws Exception {
}
if (taskRunName != null) {
var json = ResultsUpdater.MAPPER.writeValueAsString(verificationResults);
io.quarkus.logging.Log.infof("Writing verification results %s", json);
Log.infof("Writing verification results %s", json);
resultsUpdater.get().updateResults(taskRunName, Map.of("VERIFICATION_RESULTS", json));
}
return (failed && !reportOnly ? 1 : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.jboss.logging.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;

import com.redhat.hacbs.container.verifier.DiffUtils;

public record JarInfo(String name, Map<String, ClassInfo> classes) implements AsmDiffable<JarInfo> {
import io.quarkus.logging.Log;

private static final Logger Log = Logger.getLogger(JarInfo.class);
public record JarInfo(String name, Map<String, ClassInfo> classes) implements AsmDiffable<JarInfo> {

// diffClass excluding name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.LogRecord;

Expand Down Expand Up @@ -78,7 +77,7 @@ public void create(String name) {
}

@Override
public Map<String, String> add(Path path, String commit, String imageId) {
public GitStatus add(Path path, String commit, String imageId) {
return null;
}

Expand All @@ -87,7 +86,7 @@ public String groupSplit() {
return null;
}
};
Map<String, String> tagResults = test.pushRepository(
Git.GitStatus tagResults = test.pushRepository(
initialRepo,
testRepoURI,
"c396268fb90335bde5c9272b9a194c3d4302bf24",
Expand All @@ -105,23 +104,16 @@ public String groupSplit() {

List<Ref> tags = testRepository.tagList().call();
assertEquals(2, tags.size());
assertEquals(1, tagResults.size());

assertTrue(tags.stream().anyMatch(r -> r.getName().equals("refs/tags/0.1-75ecd81c7a2b384151c990975eb1dd10")));

tagResults.forEach((k, v) -> {
var found = tags.stream().filter(t -> Repository.shortenRefName(t.getName()).matches(k)).findFirst();
assertTrue(found.isPresent());
try {
assertTrue(v.matches(testRepository.getRepository()
.getRefDatabase()
.peel(found.get())
.getPeeledObjectId()
.getName()));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
var found = tags.stream().filter(t -> Repository.shortenRefName(t.getName()).matches(tagResults.tag)).findFirst();
assertTrue(found.isPresent());
assertTrue(tagResults.url.contains(testRepoURI));
assertTrue(tagResults.sha.matches(testRepository.getRepository()
.getRefDatabase()
.peel(found.get())
.getPeeledObjectId()
.getName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.jboss.logging.Logger;

import com.redhat.hacbs.recipies.scm.AbstractPomScmLocator;

import io.quarkus.logging.Log;

@ApplicationScoped
public class CachePomScmLocator extends AbstractPomScmLocator {

private static final Logger log = Logger.getLogger(CachePomScmLocator.class);
@Inject
CacheFacade cache;

Expand All @@ -27,7 +27,7 @@ protected AbstractPomScmLocator.PomClient createPomClient() {
public Optional<Model> getPom(String group, String artifact, String version) {
var response = cache.getArtifactFile("default", group.replace(".", "/"), artifact, version, artifact
+ "-" + version + ".pom", false);
if (!response.isPresent()) {
if (response.isEmpty()) {
return Optional.empty();
}
try {
Expand All @@ -38,7 +38,7 @@ public Optional<Model> getPom(String group, String artifact, String version) {
}

} catch (Exception e) {
log.errorf(e, "Failed to get pom for %s:%s:%s", group, artifact, version);
Log.errorf(e, "Failed to get pom for %s:%s:%s", group, artifact, version);
return Optional.empty();
} finally {
try {
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/jvmbuildservice/v1alpha1/dependencybuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ type BuildPipelineRunResults struct {
Gavs []string `json:"gavs,omitempty"`
// The hermetic build image produced by the build
HermeticBuildImage string `json:"hermeticBuildImage,omitempty"`
// The git archive source information
GitArchive GitArchive `json:"gitArchive,omitempty"`

// The Tekton results
PipelineResults *PipelineResults `json:"pipelineResults,omitempty"`
}

type GitArchive struct {
URL string `json:"url,omitempty"`
Tag string `json:"tag,omitempty"`
SHA string `json:"sha,omitempty"`
}

func (r *DependencyBuildStatus) GetBuildPipelineRun(pipeline string) *BuildAttempt {
for i := range r.BuildAttempts {
ba := r.BuildAttempts[i]
Expand Down
13 changes: 3 additions & 10 deletions pkg/reconciler/artifactbuild/artifactbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ const (
DependencyBuildIdLabel = "jvmbuildservice.io/dependencybuild-id"
PipelineRunLabel = "jvmbuildservice.io/pipelinerun"

PipelineResultScmUrl = "scm-url"
PipelineResultScmTag = "scm-tag"
PipelineResultScmHash = "scm-hash"
PipelineResultScmType = "scm-type"
PipelineResultContextPath = "context"
PipelineResultMessage = "message"
PipelineResultPrivate = "private"

PreBuildTaskName = "pre-build"
BuildTaskName = "build"
HermeticBuildTaskName = "hermetic-build"
Expand All @@ -54,12 +46,13 @@ const (
PipelineResultVerificationResult = "VERIFICATION_RESULTS"
PipelineResultPassedVerification = "PASSED_VERIFICATION" //#nosec
PipelineResultHermeticBuildImage = "HERMETIC_BUILD_IMAGE"
PipelineResultGitArchive = "GIT_ARCHIVE"
PipelineResultGavs = "GAVS"

RebuildAnnotation = "jvmbuildservice.io/rebuild"
//annotation that is applied after a rebuild, it will affect the dependencybuild behaviour
// RebuiltAnnotation annotation that is applied after a rebuild, it will affect the dependencybuild behaviour
RebuiltAnnotation = "jvmbuildservice.io/rebuilt"
//if this annotation is present it will be deleted after a set time to live
// HoursToLive if this annotation is present it will be deleted after a set time to live
//useful when doing builds that are being deployed to maven, and you don't want to accumulate them in the cluster
HoursToLive = "jvmbuildservice.io/hours-to-live"
)
Expand Down
8 changes: 8 additions & 0 deletions pkg/reconciler/dependencybuild/buildrecipeyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func createPipelineSpec(tool string, commitTime int64, jbsConfig *v1alpha12.JBSC
{Name: PipelineResultImageDigest},
{Name: artifactbuild.PipelineResultPassedVerification},
{Name: artifactbuild.PipelineResultVerificationResult},
{Name: artifactbuild.PipelineResultGitArchive},
}...),
Steps: []pipelinev1beta1.Step{
{
Expand Down Expand Up @@ -296,6 +297,7 @@ func createPipelineSpec(tool string, commitTime int64, jbsConfig *v1alpha12.JBSC
{Name: PipelineResultImageDigest},
{Name: artifactbuild.PipelineResultPassedVerification},
{Name: artifactbuild.PipelineResultVerificationResult},
{Name: artifactbuild.PipelineResultGitArchive},
},
Steps: []pipelinev1beta1.Step{
{
Expand Down Expand Up @@ -421,9 +423,15 @@ func createPipelineSpec(tool string, commitTime int64, jbsConfig *v1alpha12.JBSC
}
ps.Tasks = append(ps.Tasks, tagPipelineTask)

fmt.Printf("### buildTask.Results %#v \n", buildTask.Results)

for _, i := range buildTask.Results {
fmt.Printf("### attempting to append %#v \n", i.Name)
ps.Results = append(ps.Results, pipelinev1beta1.PipelineResult{Name: i.Name, Description: i.Description, Value: pipelinev1beta1.ResultValue{Type: pipelinev1beta1.ParamTypeString, StringVal: "$(tasks." + artifactbuild.BuildTaskName + ".results." + i.Name + ")"}})
}

fmt.Printf("### PipelineSpec.Results %#v \n", ps.Results)

for _, i := range buildSetup.Params {
ps.Params = append(ps.Params, pipelinev1beta1.ParamSpec{Name: i.Name, Description: i.Description, Default: i.Default, Type: i.Type})
var value pipelinev1beta1.ResultValue
Expand Down
Loading

0 comments on commit c05a625

Please sign in to comment.