Search in sources :

Example 1 with DockerImage

use of org.jfrog.build.extractor.docker.types.DockerImage in project build-info by JFrogDev.

the class BuildDockerCreator method execute.

@Override
public BuildInfo execute() {
    logger.info("Generating build info for: " + imageFile);
    try {
        List<Module> modules = new ArrayList<>();
        List<ImageFileWithDigest> imageFilesWithDigest = imageFileType == ImageFileType.KANIKO ? getKanikoImageFileWithDigests(imageFile) : getJibImageFilesWithDigests(imageFile);
        if (imageFilesWithDigest.isEmpty()) {
            throw new RuntimeException("No image files found at path '" + imageFile + "'");
        }
        for (ImageFileWithDigest imageFileWithDigest : imageFilesWithDigest) {
            DockerImage image = new DockerImage("", imageFileWithDigest.imageName, imageFileWithDigest.manifestSha256, sourceRepo, artifactoryManagerBuilder, "", "");
            Module module = image.generateBuildInfoModule(logger, DockerUtils.CommandType.Push);
            if (module.getArtifacts() == null || module.getArtifacts().size() == 0) {
                logger.warn("Could not find docker image: " + imageFileWithDigest.imageName + " in Artifactory.");
            } else {
                setImageLayersProps(image.getLayers(), artifactProperties, artifactoryManagerBuilder);
            }
            modules.add(module);
            logger.info("Successfully created build info for image: " + imageFileWithDigest.imageName);
        }
        BuildInfo buildInfo = new BuildInfo();
        buildInfo.setModules(modules);
        return buildInfo;
    } catch (Exception e) {
        logger.error(ExceptionUtils.getRootCauseMessage(e), e);
        throw new RuntimeException(e);
    }
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ArrayList(java.util.ArrayList) DockerImage(org.jfrog.build.extractor.docker.types.DockerImage) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException)

Example 2 with DockerImage

use of org.jfrog.build.extractor.docker.types.DockerImage in project build-info by JFrogDev.

the class DockerPush method execute.

@Override
public BuildInfo execute() {
    String message = "Pushing image: " + imageTag;
    if (StringUtils.isNotEmpty(host)) {
        message += " using docker daemon host: " + host;
    }
    logger.info(message);
    try {
        DockerJavaWrapper.pushImage(imageTag, username, password, host, env, logger);
        String imageId = DockerJavaWrapper.getImageIdFromTag(imageTag, host, env, logger);
        DockerImage image = new DockerImage(imageId, imageTag, "", targetRepository, artifactoryManagerBuilder, "", "");
        Module module = image.generateBuildInfoModule(logger, DockerUtils.CommandType.Push);
        if (module.getArtifacts() == null || module.getArtifacts().size() == 0) {
            logger.warn("Could not find docker image: " + imageTag + " in Artifactory.");
        } else {
            setImageLayersProps(image.getLayers(), artifactProperties, artifactoryManagerBuilder);
        }
        BuildInfo buildInfo = new BuildInfo();
        modulesList.add(module);
        buildInfo.setModules(modulesList);
        logger.info("Successfully pushed docker image: " + imageTag);
        return buildInfo;
    } catch (IOException | InterruptedException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) DockerImage(org.jfrog.build.extractor.docker.types.DockerImage) IOException(java.io.IOException) Module(org.jfrog.build.extractor.ci.Module)

Example 3 with DockerImage

use of org.jfrog.build.extractor.docker.types.DockerImage in project build-info by JFrogDev.

the class DockerPull method execute.

@Override
public BuildInfo execute() {
    String message = "Pulling image: " + imageTag;
    if (StringUtils.isNotEmpty(host)) {
        message += " using docker daemon host: " + host;
    }
    logger.info(message);
    try {
        DockerJavaWrapper.pullImage(imageTag, username, password, host, env, logger);
        String imageId = DockerJavaWrapper.getImageIdFromTag(imageTag, host, env, logger);
        Pair<String, String> archDetails = DockerJavaWrapper.getImageArch(imageTag, host, env, logger);
        DockerImage image = new DockerImage(imageId, imageTag, "", targetRepository, artifactoryManagerBuilder, archDetails.getLeft(), archDetails.getRight());
        Module module = image.generateBuildInfoModule(logger, DockerUtils.CommandType.Pull);
        if (module.getDependencies() == null || module.getDependencies().size() == 0) {
            logger.warn("Could not find docker image: " + imageTag + " in Artifactory.");
        }
        BuildInfo buildInfo = new BuildInfo();
        modulesList.add(module);
        buildInfo.setModules(modulesList);
        logger.info("Successfully pulled docker image: " + imageTag);
        return buildInfo;
    } catch (IOException | InterruptedException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) DockerImage(org.jfrog.build.extractor.docker.types.DockerImage) IOException(java.io.IOException) Module(org.jfrog.build.extractor.ci.Module)

Aggregations

IOException (java.io.IOException)3 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)3 Module (org.jfrog.build.extractor.ci.Module)3 DockerImage (org.jfrog.build.extractor.docker.types.DockerImage)3 ArrayList (java.util.ArrayList)1