use of io.fabric8.agent.model.Repository in project che by eclipse.
the class OpenShiftConnector method getImageStreamTagFromRepo.
/**
* Gets the ImageStreamTag corresponding to a given tag name (i.e. without the repository)
* @param imageStreamTagName the tag name to search for
* @return
* @throws IOException if either no matching tag is found, or there are multiple matches.
*/
private ImageStreamTag getImageStreamTagFromRepo(String imageStreamTagName) throws IOException {
// Since repository + tag are limited to 63 chars, it's possible that the entire
// tag name did not fit, so we have to match a substring.
String imageTagTrimmed = imageStreamTagName.length() > 30 ? imageStreamTagName.substring(0, 30) : imageStreamTagName;
// Note: ideally, ImageStreamTags could be identified with a label, but it seems like
// ImageStreamTags do not support labels.
List<ImageStreamTag> imageStreams = openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).list().getItems();
// We only get ImageStreamTag names here, since these ImageStreamTags do not include
// Docker metadata, for some reason.
List<String> imageStreamTags = imageStreams.stream().filter(e -> e.getMetadata().getName().contains(imageTagTrimmed)).map(e -> e.getMetadata().getName()).collect(Collectors.toList());
if (imageStreamTags.size() < 1) {
throw new OpenShiftException(String.format("ImageStreamTag %s not found!", imageStreamTagName));
} else if (imageStreamTags.size() > 1) {
throw new OpenShiftException(String.format("Multiple ImageStreamTags found for name %s", imageStreamTagName));
}
String imageStreamTag = imageStreamTags.get(0);
// Finally, get the ImageStreamTag, with Docker metadata.
return openShiftClient.imageStreamTags().inNamespace(openShiftCheProjectName).withName(imageStreamTag).get();
}
use of io.fabric8.agent.model.Repository in project che by eclipse.
the class OpenShiftConnector method createContainer.
/**
* @param createContainerParams
* @return
* @throws IOException
*/
@Override
public ContainerCreated createContainer(CreateContainerParams createContainerParams) throws IOException {
String containerName = KubernetesStringUtils.convertToContainerName(createContainerParams.getContainerName());
String workspaceID = getCheWorkspaceId(createContainerParams);
// Generate workspaceID if CHE_WORKSPACE_ID env var does not exist
workspaceID = workspaceID.isEmpty() ? KubernetesStringUtils.generateWorkspaceID() : workspaceID;
// imageForDocker is the docker version of the image repository. It's needed for other
// OpenShiftConnector API methods, but is not acceptable as an OpenShift name
String imageForDocker = createContainerParams.getContainerConfig().getImage();
// imageStreamTagName is imageForDocker converted into a form that can be used
// in OpenShift
String imageStreamTagName = KubernetesStringUtils.convertPullSpecToTagName(imageForDocker);
// imageStreamTagName is not enough to fill out a pull spec; it is only the tag, so we
// have to get the ImageStreamTag from the tag, and then get the full ImageStreamTag name
// from that tag. This works because the tags used in Che are unique.
ImageStreamTag imageStreamTag = getImageStreamTagFromRepo(imageStreamTagName);
String imageStreamTagPullSpec = imageStreamTag.getMetadata().getName();
// Next we need to get the address of the registry where the ImageStreamTag is stored
String imageStreamName = KubernetesStringUtils.getImageStreamNameFromPullSpec(imageStreamTagPullSpec);
ImageStream imageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
if (imageStream == null) {
throw new OpenShiftException("ImageStream not found");
}
String registryAddress = imageStream.getStatus().getDockerImageRepository().split("/")[0];
// The above needs to be combined to form a pull spec that will work when defining a container.
String dockerPullSpec = String.format("%s/%s/%s", registryAddress, openShiftCheProjectName, imageStreamTagPullSpec);
Set<String> containerExposedPorts = createContainerParams.getContainerConfig().getExposedPorts().keySet();
Set<String> imageExposedPorts = inspectImage(InspectImageParams.create(imageForDocker)).getConfig().getExposedPorts().keySet();
Set<String> exposedPorts = getExposedPorts(containerExposedPorts, imageExposedPorts);
boolean runContainerAsRoot = runContainerAsRoot(imageForDocker);
String[] envVariables = createContainerParams.getContainerConfig().getEnv();
String[] volumes = createContainerParams.getContainerConfig().getHostConfig().getBinds();
Map<String, String> additionalLabels = createContainerParams.getContainerConfig().getLabels();
String containerID;
try {
createOpenShiftService(workspaceID, exposedPorts, additionalLabels);
String deploymentName = createOpenShiftDeployment(workspaceID, dockerPullSpec, containerName, exposedPorts, envVariables, volumes, runContainerAsRoot);
containerID = waitAndRetrieveContainerID(deploymentName);
if (containerID == null) {
throw new OpenShiftException("Failed to get the ID of the container running in the OpenShift pod");
}
} catch (IOException e) {
// Make sure we clean up deployment and service in case of an error -- otherwise Che can end up
// in an inconsistent state.
LOG.info("Error while creating Pod, removing deployment");
String deploymentName = CHE_OPENSHIFT_RESOURCES_PREFIX + workspaceID;
cleanUpWorkspaceResources(deploymentName);
openShiftClient.resource(imageStreamTag).delete();
throw e;
}
return new ContainerCreated(containerID, null);
}
use of io.fabric8.agent.model.Repository in project docker-maven-plugin by fabric8io.
the class AuthConfigFactory method createAuthConfig.
/**
* Create an authentication config object which can be used for communication with a Docker registry
*
* The authentication information is looked up at various places (in this order):
*
* <ul>
* <li>From system properties</li>
* <li>From the provided map which can contain key-value pairs</li>
* <li>From the openshift settings in ~/.config/kube</li>
* <li>From the Maven settings stored typically in ~/.m2/settings.xml</li>
* <li>From the Docker settings stored in ~/.docker/config.json</li>
* </ul>
*
* The following properties (prefix with 'docker.') and config key are evaluated:
*
* <ul>
* <li>username: User to authenticate</li>
* <li>password: Password to authenticate. Can be encrypted</li>
* <li>email: Optional EMail address which is send to the registry, too</li>
* </ul>
*
* If the repository is in an aws ecr registry and skipExtendedAuth is not true, if found
* credentials are not from docker settings, they will be interpreted as iam credentials
* and exchanged for ecr credentials.
*
* @param isPush if true this AuthConfig is created for a push, if false it's for a pull
* @param skipExtendedAuth if false, do not execute extended authentication methods
* @param authConfig String-String Map holding configuration info from the plugin's configuration. Can be <code>null</code> in
* which case the settings are consulted.
* @param settings the global Maven settings object
* @param user user to check for
* @param registry registry to use, might be null in which case a default registry is checked,
* @return the authentication configuration or <code>null</code> if none could be found
*
* @throws MojoFailureException
*/
public AuthConfig createAuthConfig(boolean isPush, boolean skipExtendedAuth, Map authConfig, Settings settings, String user, String registry) throws MojoExecutionException {
AuthConfig ret = createStandardAuthConfig(isPush, authConfig, settings, user, registry);
if (ret != null) {
if (registry == null || skipExtendedAuth) {
return ret;
}
try {
return extendedAuthentication(ret, registry);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
// Finally check ~/.docker/config.json
ret = getAuthConfigFromDockerConfig(registry);
if (ret != null) {
log.debug("AuthConfig: credentials from ~.docker/config.json");
return ret;
}
log.debug("AuthConfig: no credentials found");
return null;
}
use of io.fabric8.agent.model.Repository in project docker-maven-plugin by fabric8io.
the class DockerAssemblyManagerTest method mockMojoParams.
private MojoParameters mockMojoParams(MavenProject project) {
Settings settings = new Settings();
ArtifactRepository localRepository = new MockUp<ArtifactRepository>() {
@Mock
public String getBasedir() {
return "repository";
}
}.getMockInstance();
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(null, settings, localRepository, null, null, Collections.<String>emptyList(), ".", null, null, new Date());
return new MojoParameters(session, project, null, null, null, settings, "src", "target", Collections.singletonList(project));
}
use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class AetherBasedResolver method selectRepositories.
private List<RemoteRepository> selectRepositories() {
List<RemoteRepository> list = new ArrayList<RemoteRepository>();
List<MavenRepositoryURL> urls = Collections.emptyList();
try {
urls = m_config.getRepositories();
} catch (MalformedURLException exc) {
LOG.error("invalid repository URLs", exc);
}
for (MavenRepositoryURL r : urls) {
if (r.isMulti()) {
addSubDirs(list, r.getFile());
} else {
addRepo(list, r);
}
}
return list;
}
Aggregations