Search in sources :

Example 1 with DockerRegistry

use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.

the class ToolGroupManager method create.

@Transactional(propagation = Propagation.REQUIRED)
public ToolGroup create(final ToolGroup group) {
    Assert.notNull(group.getName(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_NULL_OR_EMPTY, "name"));
    Assert.notNull(group.getRegistryId(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_NULL_OR_EMPTY, "registryId"));
    DockerRegistry registry = dockerRegistryManager.load(group.getRegistryId());
    group.setParent(registry);
    if (!StringUtils.hasText(group.getOwner())) {
        group.setOwner(authManager.getAuthorizedUser());
    }
    Assert.isTrue(!toolGroupDao.loadToolGroup(group.getName(), group.getRegistryId()).isPresent(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_ALREADY_EXIST, group.getName(), registry.getName()));
    toolGroupDao.createToolGroup(group);
    return group;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DockerRegistry

use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.

the class ToolManager method delete.

/**
 * Deletes a Tool from the database and from Docker Registry
 * @param registry registry identifier
 * @param image Tool's image
 * @param hard flag determines if the real image from Docker Registry should be deleted
 * @return the deleted Tool entity
 */
@Transactional(propagation = Propagation.REQUIRED)
public Tool delete(String registry, final String image, boolean hard) {
    Tool tool = loadTool(registry, image);
    if (hard) {
        DockerRegistry dockerRegistry = dockerRegistryManager.load(tool.getRegistryId());
        List<String> tags = dockerRegistryManager.loadImageTags(dockerRegistry, image);
        for (String tag : tags) {
            Optional<ManifestV2> manifestOpt = dockerRegistryManager.deleteImage(dockerRegistry, tool.getImage(), tag);
            manifestOpt.ifPresent(manifest -> {
                dockerRegistryManager.deleteLayer(dockerRegistry, image, manifest.getConfig().getDigest());
                Collections.reverse(manifest.getLayers());
                for (ManifestV2.Config layer : manifest.getLayers()) {
                    dockerRegistryManager.deleteLayer(dockerRegistry, image, layer.getDigest());
                }
            });
        }
    }
    toolVulnerabilityDao.loadAllToolVersionScans(tool.getId()).values().forEach(versionScan -> deleteToolVersionScan(tool.getId(), versionScan.getVersion()));
    toolDao.deleteToolIcon(tool.getId());
    toolVersionManager.deleteToolVersions(tool.getId());
    toolDao.deleteTool(tool.getId());
    return tool;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ManifestV2(com.epam.pipeline.entity.docker.ManifestV2) Tool(com.epam.pipeline.entity.pipeline.Tool) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DockerRegistry

use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.

the class ToolManager method getExternalToolName.

public String getExternalToolName(String toolName) {
    Matcher matcher = REPOSITORY_AND_IMAGE.matcher(toolName);
    Assert.state(matcher.find(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_INVALID_IMAGE, toolName));
    String registryPath = matcher.group(1);
    DockerRegistry dockerRegistry = dockerRegistryManager.loadByNameOrId(registryPath);
    Assert.state(StringUtils.hasText(dockerRegistry.getExternalUrl()), messageHelper.getMessage(MessageConstants.ERROR_DOCKER_REGISTRY_NO_EXTERNAL, dockerRegistry.getPath()));
    return toolName.replace(registryPath, dockerRegistry.getExternalUrl());
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Matcher(java.util.regex.Matcher)

Example 4 with DockerRegistry

use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.

the class ToolManager method deleteToolVersion.

/**
 * Deletes Tool's version (a tag) from Docker Registry
 *
 * @param registry registry identifier
 * @param image Tool's image
 * @param version tag from registry
 * @return Tool entity, which version was deleted
 */
@Transactional(propagation = Propagation.REQUIRED)
public Tool deleteToolVersion(String registry, final String image, String version) {
    Tool tool = loadTool(registry, image);
    deleteToolVersionScan(tool.getId(), version);
    toolVersionManager.deleteToolVersion(tool.getId(), version);
    DockerRegistry dockerRegistry = dockerRegistryManager.load(tool.getRegistryId());
    dockerRegistryManager.deleteImage(dockerRegistry, tool.getImage(), version);
    return tool;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Tool(com.epam.pipeline.entity.pipeline.Tool) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DockerRegistry

use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.

the class DockerRegistryDaoTest method deleteDockerRegistry.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void deleteDockerRegistry() throws Exception {
    DockerRegistry created = getDockerRegistry();
    registryDao.createDockerRegistry(created);
    registryDao.deleteDockerRegistry(created.getId());
    DockerRegistry loaded = registryDao.loadDockerRegistry(created.getId());
    Assert.assertNull(loaded);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)57 Transactional (org.springframework.transaction.annotation.Transactional)24 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)22 Tool (com.epam.pipeline.entity.pipeline.Tool)19 Test (org.junit.Test)14 Before (org.junit.Before)10 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)6 MessageHelper (com.epam.pipeline.common.MessageHelper)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 DockerClient (com.epam.pipeline.manager.docker.DockerClient)4 DockerRegistryManager (com.epam.pipeline.manager.docker.DockerRegistryManager)4 IOException (java.io.IOException)4 List (java.util.List)4 Optional (java.util.Optional)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 MessageConstants (com.epam.pipeline.common.MessageConstants)3 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)3 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)3