Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions java-components/build-request-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>hacbs-resource-model</artifactId>
</dependency>
<dependency>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>common-images</artifactId>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import com.redhat.hacbs.container.analyser.build.LookupBuildInfoCommand;
import com.redhat.hacbs.container.analyser.dependencies.AnalyseDependencies;
import com.redhat.hacbs.container.analyser.deploy.ContainerTagCommand;
import com.redhat.hacbs.container.analyser.deploy.CopyArtifactsCommand;
import com.redhat.hacbs.container.analyser.deploy.DeployCommand;
import com.redhat.hacbs.container.analyser.deploy.DeployHermeticPreBuildImageCommand;
import com.redhat.hacbs.container.analyser.deploy.DeployPreBuildImageCommand;
import com.redhat.hacbs.container.analyser.location.LookupScmLocationCommand;
import com.redhat.hacbs.container.build.preprocessor.ant.AntPrepareCommand;
import com.redhat.hacbs.container.build.preprocessor.gradle.GradlePrepareCommand;
import com.redhat.hacbs.container.build.preprocessor.maven.MavenPrepareCommand;
import com.redhat.hacbs.container.build.preprocessor.sbt.SBTPrepareCommand;
import com.redhat.hacbs.container.deploy.ContainerTagCommand;
import com.redhat.hacbs.container.deploy.CopyArtifactsCommand;
import com.redhat.hacbs.container.deploy.DeployCommand;
import com.redhat.hacbs.container.deploy.DeployHermeticPreBuildImageCommand;
import com.redhat.hacbs.container.deploy.DeployPreBuildImageCommand;
import com.redhat.hacbs.container.deploy.MavenDeployCommand;
import com.redhat.hacbs.container.verifier.VerifyBuiltArtifactsCommand;

import io.quarkus.picocli.runtime.annotations.TopCommand;
Expand All @@ -31,7 +32,8 @@
AntPrepareCommand.class,
DeployPreBuildImageCommand.class,
DeployHermeticPreBuildImageCommand.class,
ContainerTagCommand.class
ContainerTagCommand.class,
MavenDeployCommand.class
})
public class EntryPoint {
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import com.redhat.hacbs.container.analyser.build.ant.AntUtils;
import com.redhat.hacbs.container.analyser.build.gradle.GradleUtils;
import com.redhat.hacbs.container.analyser.build.maven.MavenJavaVersionDiscovery;
import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerUtil;
import com.redhat.hacbs.container.deploy.containerregistry.ContainerUtil;
import com.redhat.hacbs.container.results.ResultsUpdater;
import com.redhat.hacbs.recipes.build.BuildRecipeInfo;
import com.redhat.hacbs.recipes.scm.ScmInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.google.cloud.tools.jib.registry.credentials.CredentialRetrievalException;
import com.redhat.hacbs.classfile.tracker.NoCloseInputStream;
import com.redhat.hacbs.classfile.tracker.TrackingData;
import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerUtil;
import com.redhat.hacbs.container.deploy.containerregistry.ContainerUtil;

import io.quarkus.arc.Unremovable;
import io.quarkus.logging.Log;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import java.util.List;
import java.util.Optional;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerRegistryDeployer;
import com.redhat.hacbs.container.deploy.containerregistry.ContainerRegistryDeployer;

import picocli.CommandLine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import static com.redhat.hacbs.container.verifier.MavenUtils.gavToCoords;
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import static org.apache.commons.lang3.ObjectUtils.isEmpty;
import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand All @@ -21,7 +19,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

Expand All @@ -33,19 +30,11 @@
import org.cyclonedx.CycloneDxSchema;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.codeartifact.AWSCodeArtifactClientBuilder;
import com.amazonaws.services.codeartifact.model.GetAuthorizationTokenRequest;
import com.amazonaws.util.AwsHostNameUtils;
import com.redhat.hacbs.classfile.tracker.ClassFileTracker;
import com.redhat.hacbs.classfile.tracker.TrackingData;
import com.redhat.hacbs.container.analyser.dependencies.SBomGenerator;
import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerRegistryDeployer;
import com.redhat.hacbs.container.analyser.deploy.git.Git;
import com.redhat.hacbs.container.analyser.deploy.mavenrepository.CodeArtifactRepository;
import com.redhat.hacbs.container.analyser.deploy.mavenrepository.MavenRepositoryDeployer;
import com.redhat.hacbs.container.deploy.containerregistry.ContainerRegistryDeployer;
import com.redhat.hacbs.container.deploy.git.Git;
import com.redhat.hacbs.container.results.ResultsUpdater;
import com.redhat.hacbs.recipes.util.FileUtil;
import com.redhat.hacbs.resources.model.v1alpha1.dependencybuildstatus.Contaminates;
Expand Down Expand Up @@ -116,19 +105,9 @@ public class DeployCommand implements Runnable {
@CommandLine.Option(names = "--registry-prepend-tag", defaultValue = "")
String prependTag;

// Maven Repo Deployment specification
@CommandLine.Option(names = "--mvn-username")
String mvnUser;

@ConfigProperty(name = "maven.password")
Optional<String> mvnPassword;

@ConfigProperty(name = "aws.profile")
Optional<String> awsProfile;

@CommandLine.Option(names = "--mvn-repo")
String mvnRepo;

@ConfigProperty(name = "git.deploy.token")
Optional<String> gitToken;

Expand Down Expand Up @@ -301,50 +280,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
}
}
generateBuildSbom();
CodeArtifactRepository codeArtifactRepository = null;
if (isNotEmpty(mvnRepo) && mvnPassword.isEmpty()) {
Log.infof("Maven repository specified as %s and no password specified", mvnRepo);
URL url = new URL(mvnRepo);
String repo = url.getHost();
// This is special handling for AWS CodeArtifact. It will automatically retrieve a token
// (which normally only last up to 12 hours). Token information will be retrieved from
// the AWS configuration which will utilise the configuration file and/or scan environment
// variables such as AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_PROFILE
if (repo.endsWith(".amazonaws.com")) {
if (isEmpty(mvnUser)) {
Log.warnf("Username for deployment is empty");
}
Matcher matcher = CODE_ARTIFACT_PATTERN.matcher(mvnRepo);
if (matcher.matches()) {
var mr = matcher.toMatchResult();
int firstDash = repo.indexOf("-");
String parsedRegion = AwsHostNameUtils.parseRegion(repo, null);
String domain = repo.substring(0, firstDash);
String domainOwner = repo.substring(firstDash + 1, repo.indexOf("."));
Log.infof("Generating AWS token for domain %s, owner %s, region %s", domain, domainOwner, parsedRegion);

Regions region = Regions.fromName(parsedRegion);
var awsClient = AWSCodeArtifactClientBuilder.standard()
.withCredentials(awsProfile.isEmpty() ? DefaultAWSCredentialsProviderChain.getInstance()
: new ProfileCredentialsProvider(awsProfile.get()))
.withRegion(region).build();
mvnPassword = Optional.of(awsClient.getAuthorizationToken(
new GetAuthorizationTokenRequest().withDomain(domain).withDomainOwner(domainOwner))
.getAuthorizationToken());
codeArtifactRepository = new CodeArtifactRepository(awsClient, mr.group(1), mr.group(2));
} else {
Log.errorf("Unable to parse AWS CodeArtifact URL: %s", mvnRepo);
}
}
}

//we still deploy, but without the contaminates
// This means the build failed to produce any deployable output.
// If everything is contaminated we still need the task to succeed so we can resolve the contamination.
if (!gavs.isEmpty()) {
try {
cleanBrokenSymlinks(sourcePath);
doDeployment(sourcePath, logsPath, gavs, codeArtifactRepository);
doDeployment(sourcePath, logsPath, gavs);
} catch (Throwable t) {
Log.error("Deployment failed", t);
flushLogs();
Expand Down Expand Up @@ -429,7 +372,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th

}

protected void doDeployment(Path sourcePath, Path logsPath, Set<String> gavs, CodeArtifactRepository codeArtifactRepository)
protected void doDeployment(Path sourcePath, Path logsPath, Set<String> gavs)
throws Exception {
if (imageDeployment) {
ContainerRegistryDeployer deployer = new ContainerRegistryDeployer(host, port, owner, token.orElse(""), repository,
Expand All @@ -443,12 +386,6 @@ public void accept(String s, String hash) {
}
});
}
if (isNotEmpty(mvnRepo)) {
// Maven Repo Deployment
MavenRepositoryDeployer deployer = new MavenRepositoryDeployer(mvnCtx, mvnUser, mvnPassword.orElse(""), mvnRepo,
deploymentPath, codeArtifactRepository);
deployer.deploy();
}
}

private void flushLogs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import java.nio.file.Path;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -8,7 +8,7 @@

import org.eclipse.microprofile.config.inject.ConfigProperty;

import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerRegistryDeployer;
import com.redhat.hacbs.container.deploy.containerregistry.ContainerRegistryDeployer;

import picocli.CommandLine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -8,7 +8,7 @@

import org.eclipse.microprofile.config.inject.ConfigProperty;

import com.redhat.hacbs.container.analyser.deploy.containerregistry.ContainerRegistryDeployer;
import com.redhat.hacbs.container.deploy.containerregistry.ContainerRegistryDeployer;

import picocli.CommandLine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.hacbs.container.analyser.deploy;
package com.redhat.hacbs.container.deploy;

import java.util.Objects;

Expand Down
Loading