Search in sources :

Example 11 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class DeployTask method handleBuildInfoDeployment.

private void handleBuildInfoDeployment(ArtifactoryClientConfiguration accRoot, BuildInfo buildInfo, Map<String, Set<DeployDetails>> allDeployDetails) throws IOException {
    String contextUrl = accRoot.publisher.getContextUrl();
    if (contextUrl != null) {
        try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(accRoot.publisher.getContextUrl(), accRoot.publisher.getUsername(), accRoot.publisher.getPassword(), new GradleClientLogger(log))) {
            if (isPublishBuildInfo(accRoot)) {
                // If export property set always save the file before sending it to artifactory
                exportBuildInfo(buildInfo, getExportFile(accRoot));
                if (accRoot.info.isIncremental()) {
                    log.debug("Publishing build info modules to artifactory at: '{}'", contextUrl);
                    artifactoryManager.sendModuleInfo(buildInfo);
                } else {
                    log.debug("Publishing build info to artifactory at: '{}'", contextUrl);
                    Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, accRoot);
                }
            }
            if (isGenerateDeployableArtifactsToFile(accRoot)) {
                try {
                    exportDeployableArtifacts(allDeployDetails, new File(accRoot.info.getDeployableArtifactsFilePath()), accRoot.info.isBackwardCompatibleDeployableArtifacts());
                } catch (Exception e) {
                    log.error("Failed writing deployable artifacts to file: ", e);
                    throw new RuntimeException("Failed writing deployable artifacts to file", e);
                }
            }
        }
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) File(java.io.File) IOException(java.io.IOException)

Example 12 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class DeployTask method deployArtifacts.

private void deployArtifacts(ArtifactoryClientConfiguration accRoot, Map<String, String> propsRoot, Map<String, Set<DeployDetails>> allDeployDetails, ArtifactoryTask artifactoryTask, String logPrefix) {
    try {
        if (artifactoryTask.getDidWork()) {
            ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(artifactoryTask.getProject());
            if (publisher != null && publisher.getContextUrl() != null) {
                Map<String, String> moduleProps = new HashMap<String, String>(propsRoot);
                moduleProps.putAll(publisher.getProps());
                publisher.getProps().putAll(moduleProps);
                String contextUrl = publisher.getContextUrl();
                String username = publisher.getUsername();
                String password = publisher.getPassword();
                if (StringUtils.isBlank(username)) {
                    username = "";
                }
                if (StringUtils.isBlank(password)) {
                    password = "";
                }
                if (publisher.isPublishArtifacts()) {
                    try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, new GradleClientLogger(log))) {
                        log.debug("Uploading artifacts to Artifactory at '{}'", contextUrl);
                        IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
                        configureProxy(accRoot, artifactoryManager);
                        configConnectionTimeout(accRoot, artifactoryManager);
                        configRetriesParams(accRoot, artifactoryManager);
                        configInsecureTls(accRoot, artifactoryManager);
                        deployArtifacts(artifactoryTask.deployDetails, artifactoryManager, patterns, logPrefix, publisher.getMinChecksumDeploySizeKb());
                    }
                }
                if (!artifactoryTask.deployDetails.isEmpty()) {
                    Set<DeployDetails> deployDetailsSet = new LinkedHashSet<>();
                    for (GradleDeployDetails details : artifactoryTask.deployDetails) {
                        deployDetailsSet.add(details.getDeployDetails());
                    }
                    allDeployDetails.put(artifactoryTask.getProject().getName(), deployDetailsSet);
                }
            }
        } else {
            log.debug("Task '{}' did no work", artifactoryTask.getPath());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)

Example 13 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class DockerImage method loadLayers.

private void loadLayers(String manifestPath) throws IOException {
    try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
        layers = getLayers(artifactoryManager, manifestPath);
        List<DockerLayer> markerLayers = layers.getLayers().stream().filter(layer -> layer.getFileName().endsWith(".marker")).collect(Collectors.toList());
        // Transform all marker layers into regular layer.
        if (markerLayers.size() > 0) {
            for (DockerLayer markerLayer : markerLayers) {
                // Get image name without '.marker' suffix.
                String imageDigests = StringUtils.removeEnd(markerLayer.getDigest(), ".marker");
                String imageName = StringUtils.substringBetween(imageTag, "/", ":");
                DockerUtils.downloadMarkerLayer(targetRepo, imageName, imageDigests, artifactoryManager);
            }
            layers = getLayers(artifactoryManager, manifestPath);
        }
    }
}
Also used : ArtifactoryVersion(org.jfrog.build.client.ArtifactoryVersion) DockerUtils(org.jfrog.build.extractor.docker.DockerUtils) java.util(java.util) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) DownloadResponse(org.jfrog.build.client.DownloadResponse) SHA256_HEADER_NAME(org.jfrog.build.client.DownloadResponse.SHA256_HEADER_NAME) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) Header(org.apache.http.Header) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Collectors(java.util.stream.Collectors) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ModuleType(org.jfrog.build.api.builder.ModuleType) Serializable(java.io.Serializable) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) Log(org.jfrog.build.api.util.Log) Artifact(org.jfrog.build.extractor.ci.Artifact) ArtifactoryManagerBuilder(org.jfrog.build.extractor.clientConfiguration.ArtifactoryManagerBuilder) Pair(org.apache.commons.lang3.tuple.Pair) Module(org.jfrog.build.extractor.ci.Module) AqlSearchResult(org.jfrog.build.api.search.AqlSearchResult) Dependency(org.jfrog.build.extractor.ci.Dependency) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)

Example 14 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class GoRun method execute.

public BuildInfo execute() {
    try (ArtifactoryManager artifactoryClient = (artifactoryManagerBuilder != null ? artifactoryManagerBuilder.build() : null)) {
        if (artifactoryClient != null) {
            preparePrerequisites(resolutionRepository, artifactoryClient);
            setResolverAsGoProxy(artifactoryClient);
        }
        // We create the GoDriver here as env might had changed.
        this.goDriver = new GoDriver(GO_CLIENT_CMD, env, path.toFile(), logger);
        // First try to run 'go version' to make sure go is in PATH, and write the output to logger.
        goDriver.version(true);
        goDriver.runCmd(goCmdArgs, true);
        populateModuleAndDeps();
        return createBuild();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) GoDriver(org.jfrog.build.extractor.go.GoDriver) IOException(java.io.IOException)

Example 15 with ArtifactoryManager

use of org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager in project build-info by JFrogDev.

the class DockerImage method generateBuildInfoModule.

public Module generateBuildInfoModule(Log logger, DockerUtils.CommandType cmdType) throws IOException, InterruptedException {
    try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
        ModuleBuilder moduleBuilder = new ModuleBuilder().type(ModuleType.DOCKER).id(substringAfterLast(imageTag, "/")).repository(targetRepo);
        try {
            findAndSetManifestFromArtifactory(artifactoryManager, logger, cmdType);
        } catch (IOException e) {
            // The manifest could not be found in Artifactory.
            // Yet, we do not fail the build, but return an empty build-info instead.
            // The reason for not failing build is that there's a chance that the image was replaced
            // with another image, deployed to the same repo path.
            // This can happen if two parallel jobs build the same image. In that case, the build-info
            // for this build will be empty.
            logger.error("The manifest could not be fetched from Artifactory.");
            return moduleBuilder.build();
        }
        logger.info("Fetching details of published docker layers from Artifactory...");
        if (cmdType == DockerUtils.CommandType.Push) {
            setDependenciesAndArtifacts(moduleBuilder, artifactoryManager);
        } else {
            setDependencies(moduleBuilder);
        }
        setBuildInfoModuleProps(moduleBuilder);
        return moduleBuilder.build();
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) IOException(java.io.IOException)

Aggregations

ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)21 IOException (java.io.IOException)11 File (java.io.File)3 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)3 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)3 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)2 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)2 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)2 ConsumerRunnableBase (org.jfrog.build.extractor.producerConsumer.ConsumerRunnableBase)2 ProducerConsumerExecutor (org.jfrog.build.extractor.producerConsumer.ProducerConsumerExecutor)2 ProducerRunnableBase (org.jfrog.build.extractor.producerConsumer.ProducerRunnableBase)2 Serializable (java.io.Serializable)1 java.util (java.util)1 Date (java.util.Date)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Header (org.apache.http.Header)1