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;
}
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;
}
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());
}
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;
}
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);
}
Aggregations