Skip to content

Commit

Permalink
Integrate maven repo deployment code
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Oct 19, 2023
1 parent 3bce7ab commit 06adf04
Show file tree
Hide file tree
Showing 18 changed files with 421 additions and 132 deletions.
6 changes: 4 additions & 2 deletions deploy/base-development.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi
DIR=`dirname $0`
kubectl apply -f $DIR/namespace.yaml
kubectl config set-context --current --namespace=test-jvm-namespace
kubectl delete --ignore-not-found secret jvm-build-image-secrets jvm-build-git-secrets
kubectl delete --ignore-not-found secret jvm-build-image-secrets jvm-build-git-secrets jvm-build-maven-repo-secrets

if [ -n "$QUAY_ORG" ] && [ -n "$QUAY_TOKEN" ]; then
kubectl delete --ignore-not-found secret -n image-controller quaytoken
Expand All @@ -28,10 +28,12 @@ kubectl create secret generic jvm-build-git-secrets --from-literal .git-credenti
https://$GITHUB_E2E_ORGANIZATION:$GITHUB_TOKEN@github.com
https://test:[email protected]
"
if [ -n "$MAVEN_PASSWORD" ]; then
kubectl create secret generic jvm-build-maven-repo-secrets --from-literal mavenpassword="$MAVEN_PASSWORD"
fi

JVM_BUILD_SERVICE_IMAGE=quay.io/$QUAY_USERNAME/hacbs-jvm-controller \
JVM_BUILD_SERVICE_CACHE_IMAGE=quay.io/$QUAY_USERNAME/hacbs-jvm-cache \
JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE=quay.io/$QUAY_USERNAME/hacbs-jvm-build-request-processor:dev \
$DIR/patch-yaml.sh
kubectl apply -k $DIR/overlays/development

7 changes: 7 additions & 0 deletions deploy/crds/base/jvmbuildservice.io_jbsconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ spec:
additionalProperties:
type: string
type: object
mavenDeployment:
properties:
repository:
type: string
username:
type: string
type: object
owner:
type: string
port:
Expand Down
7 changes: 6 additions & 1 deletion deploy/overlays/dev-template/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ kind: JBSConfig
metadata:
name: jvm-build-config
spec:
owner: QUAY_USERNAME
# TODO: Should this be qualified by 'registry' ? Same for ci-template?
registry:
owner: QUAY_USERNAME
mavenDeployment:
username: MAVEN_USERNAME
repository: MAVEN_REPOSITORY
relocationPatterns:
- relocationPattern:
buildPolicy: "default"
Expand Down
8 changes: 8 additions & 0 deletions deploy/patch-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ find $DIR -path \*development\*.yaml -exec $SED -i s%jvm-build-service-cache-ima
find $DIR -path \*development\*.yaml -exec $SED -i s%jvm-build-service-reqprocessor-image%${JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE}% {} \;
find $DIR -path \*development\*.yaml -exec $SED -i s/dev-template/development/ {} \;
find $DIR -path \*development\*.yaml -exec $SED -i s/QUAY_TOKEN/${QUAY_TOKEN}/ {} \;
if [ -z "${MAVEN_USERNAME}" ]; then
MAVEN_USERNAME=""
fi
if [ -z "${MAVEN_REPOSITORY}" ]; then
MAVEN_REPOSITORY=""
fi
find $DIR -path \*development\*.yaml -exec $SED -i s/MAVEN_USERNAME/${MAVEN_USERNAME}/ {} \;
find $DIR -path \*development\*.yaml -exec $SED -i s%MAVEN_REPOSITORY%${MAVEN_REPOSITORY}% {} \;
if [ -n "$QUAY_TOKEN" ]; then
$SED -i '/owner: QUAY_USERNAME/d' $DIR/overlays/development/config.yaml
fi
Expand Down
90 changes: 24 additions & 66 deletions java-components/build-request-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,19 @@
</parent>
<artifactId>hacbs-build-request-processor</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.amazonservices</groupId>
<artifactId>quarkus-amazon-s3</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
</dependency>
<dependency>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>hacbs-classfile-tracker</artifactId>
</dependency>
<dependency>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-core-java</artifactId>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>hacbs-build-recipies-database</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>hacbs-resource-model</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
Expand All @@ -45,10 +34,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-jib</artifactId>
</dependency>
<dependency>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>hacbs-resource-model</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-picocli</artifactId>
Expand All @@ -58,29 +43,40 @@
<artifactId>quarkus-jgit</artifactId>
</dependency>
<dependency>
<groupId>io.github.redhat-appstudio.jvmbuild</groupId>
<artifactId>hacbs-build-recipies-database</artifactId>
<groupId>io.quarkiverse.mavenresolver</groupId>
<artifactId>quarkus-maven-resolver</artifactId>
</dependency>

<dependency>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-core-java</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
</dependency>

<dependency>
<groupId>org.gradle</groupId>
<artifactId>gradle-tooling-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand All @@ -91,54 +87,16 @@
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.redhat.hacbs.container.analyser.deploy;

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

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -19,6 +21,7 @@
import java.util.stream.Stream;

import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.inject.Inject;

import org.cyclonedx.BomGeneratorFactory;
import org.cyclonedx.CycloneDxSchema;
Expand All @@ -28,14 +31,17 @@
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.mavenrepository.MavenRepositoryDeployer;
import com.redhat.hacbs.container.results.ResultsUpdater;
import com.redhat.hacbs.recipies.util.FileUtil;
import com.redhat.hacbs.resources.model.v1alpha1.dependencybuildstatus.Contaminates;
import com.redhat.hacbs.resources.util.HashUtil;

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

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@CommandLine.Command(name = "deploy")
public class DeployCommand implements Runnable {

Expand All @@ -47,22 +53,22 @@ public class DeployCommand implements Runnable {
final BeanManager beanManager;
final ResultsUpdater resultsUpdater;

@CommandLine.Option(required = false, names = "--allowed-sources", defaultValue = "redhat,rebuilt", split = ",")
@CommandLine.Option(names = "--allowed-sources", defaultValue = "redhat,rebuilt", split = ",")
Set<String> allowedSources;

@CommandLine.Option(required = true, names = "--path")
Path deploymentPath;

@CommandLine.Option(required = false, names = "--task-run-name")
@CommandLine.Option(names = "--task-run-name")
String taskRun;

@CommandLine.Option(required = true, names = "--source-path")
Path sourcePath;

@CommandLine.Option(required = false, names = "--logs-path")
@CommandLine.Option(names = "--logs-path")
Path logsPath;

@CommandLine.Option(required = false, names = "--build-info-path")
@CommandLine.Option(names = "--build-info-path")
Path buildInfoPath;

@CommandLine.Option(required = true, names = "--scm-uri")
Expand All @@ -78,7 +84,7 @@ public class DeployCommand implements Runnable {
@CommandLine.Option(names = "--registry-owner", defaultValue = "hacbs")
String owner;
@ConfigProperty(name = "registry.token")
Optional<String> token;
Optional<String> token = Optional.empty();
@CommandLine.Option(names = "--registry-repository", defaultValue = "artifact-deployments")
String repository;
@CommandLine.Option(names = "--registry-insecure", defaultValue = "false")
Expand All @@ -92,9 +98,26 @@ 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 = Optional.empty();

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

// Testing only ; used to disable image deployment
protected boolean imageDeployment = true;

protected String imageName;
protected String imageDigest;

@Inject
BootstrapMavenContext mvnCtx;

public DeployCommand(BeanManager beanManager,
ResultsUpdater resultsUpdater) {
this.beanManager = beanManager;
Expand Down Expand Up @@ -198,15 +221,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO

Files.walkFileTree(deploymentPath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Log.errorf("Contents: %s", file);
return FileVisitResult.CONTINUE;
}
});
throw new RuntimeException("deploy failed");
}
//we still deploy, but without the contaminates
java.nio.file.Path deployFile = deploymentPath;
// 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.
for (var i : contaminatedGavs.entrySet()) {
Expand All @@ -217,7 +239,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
if (!gavs.isEmpty()) {
try {
cleanBrokenSymlinks(sourcePath);
doDeployment(deployFile, sourcePath, logsPath, gavs);
doDeployment(sourcePath, logsPath, gavs);
} catch (Throwable t) {
Log.error("Deployment failed", t);
flushLogs();
Expand Down Expand Up @@ -301,18 +323,26 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th

}

protected void doDeployment(Path deployDir, Path sourcePath, Path logsPath, Set<String> gavs) throws Exception {

ContainerRegistryDeployer deployer = new ContainerRegistryDeployer(host, port, owner, token.orElse(""), repository,
insecure,
prependTag, imageId);
deployer.deployArchive(deployDir, sourcePath, logsPath, gavs, new BiConsumer<String, String>() {
@Override
public void accept(String s, String hash) {
imageName = s;
imageDigest = hash;
}
});
protected void doDeployment(Path sourcePath, Path logsPath, Set<String> gavs) throws Exception {
// TODO: Putting mvn deployment first as image deployment deletes the file tree
if (isNotEmpty(mvnRepo)) {
// Maven Repo Deployment
MavenRepositoryDeployer deployer = new MavenRepositoryDeployer(mvnCtx, mvnUser, mvnPassword.orElse(""), mvnRepo,
deploymentPath);
deployer.deploy();
}
if (imageDeployment) {
ContainerRegistryDeployer deployer = new ContainerRegistryDeployer(host, port, owner, token.orElse(""), repository,
insecure, prependTag,
imageId);
deployer.deployArchive(deploymentPath, sourcePath, logsPath, gavs, new BiConsumer<String, String>() {
@Override
public void accept(String s, String hash) {
imageName = s;
imageDigest = hash;
}
});
}
}

private void flushLogs() {
Expand Down
Loading

0 comments on commit 06adf04

Please sign in to comment.