use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class LogMatchCallbackTest method matchingPartitialLineSucceeds.
@Test(expected = LogCallback.DoneException.class)
public void matchingPartitialLineSucceeds() throws Exception {
final String patterString = "waiting for connections";
final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patterString);
new Expectations() {
{
callback.matched();
times = 1;
}
};
logMatchCallback.log(1, new Timestamp(), "2017-11-21T12:44:43.678+0000 I NETWORK [initandlisten] waiting for connections on port 27017");
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class StopMojo method getNetworksToRemove.
private Set<Network> getNetworksToRemove(QueryService queryService, PomLabel pomLabel) throws DockerAccessException {
if (!autoCreateCustomNetworks) {
return Collections.emptySet();
}
Set<Network> customNetworks = new HashSet<>();
Set<Network> networks = queryService.getNetworks();
for (ImageConfiguration image : getResolvedImages()) {
final NetworkConfig config = image.getRunConfiguration().getNetworkingConfig();
if (config.isCustomNetwork()) {
Network network = getNetworkByName(networks, config.getCustomNetwork());
if (network != null) {
customNetworks.add(network);
for (Container container : getContainersToStop(queryService, image)) {
if (!shouldStopContainer(container, pomLabel, image)) {
// it's sill in use don't collect it
customNetworks.remove(network);
}
}
}
}
}
return customNetworks;
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class DockerComposeServiceWrapper method getNetworkConfig.
NetworkConfig getNetworkConfig() {
String net = asString("network_mode");
if (net != null) {
return new NetworkConfig(net);
}
Object networks = asObject("networks");
if (networks == null) {
return null;
}
if (networks instanceof List) {
List<String> toJoin = (List<String>) networks;
if (toJoin.size() > 1) {
throwIllegalArgumentException("'networks:' Only one custom network to join is supported currently");
}
return new NetworkConfig(NetworkConfig.Mode.custom, toJoin.get(0));
} else if (networks instanceof Map) {
Map<String, Object> toJoin = (Map<String, Object>) networks;
if (toJoin.size() > 1) {
throwIllegalArgumentException("'networks:' Only one custom network to join is supported currently");
}
String custom = toJoin.keySet().iterator().next();
NetworkConfig ret = new NetworkConfig(NetworkConfig.Mode.custom, custom);
Object aliases = toJoin.get(custom);
if (aliases != null) {
if (aliases instanceof List) {
for (String alias : (List<String>) aliases) {
ret.addAlias(alias);
}
} else if (aliases instanceof Map) {
Map<String, List<String>> map = (Map<String, List<String>>) aliases;
if (map.containsKey("aliases")) {
for (String alias : map.get("aliases")) {
ret.addAlias(alias);
}
} else {
throwIllegalArgumentException("'networks:' Aliases must be given as a map of strings. 'aliases' key not founded");
}
} else {
throwIllegalArgumentException("'networks:' No aliases entry found in network config map");
}
}
return ret;
} else {
throwIllegalArgumentException("'networks:' must beu either a list or a map");
return null;
}
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class BuildService method buildImage.
/**
* Build an image
*
* @param imageConfig the image configuration
* @param params mojo params for the project
* @param noCache if not null, dictate the caching behaviour. Otherwise its taken from the build configuration
* @param buildArgs docker build args
* @throws DockerAccessException
* @throws MojoExecutionException
*/
protected void buildImage(ImageConfiguration imageConfig, MojoParameters params, boolean noCache, boolean squash, Map<String, String> buildArgs, File dockerArchive) throws DockerAccessException, MojoExecutionException {
String imageName = imageConfig.getName();
ImageName.validate(imageName);
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
String oldImageId = null;
CleanupMode cleanupMode = buildConfig.cleanupMode();
if (cleanupMode.isRemove()) {
oldImageId = queryService.getImageId(imageName);
}
if (buildConfig.getDockerArchive() != null) {
File tarArchive = buildConfig.getAbsoluteDockerTarPath(params);
String archiveImageName = getArchiveImageName(buildConfig, tarArchive);
long time = System.currentTimeMillis();
docker.loadImage(imageName, tarArchive);
log.info("%s: Loaded tarball in %s", buildConfig.getDockerArchive(), EnvUtil.formatDurationTill(time));
if (archiveImageName != null && !archiveImageName.equals(imageName)) {
docker.tag(archiveImageName, imageName, true);
}
return;
}
Map<String, String> mergedBuildMap = prepareBuildArgs(buildArgs, buildConfig);
// auto is now supported by docker, consider switching?
BuildOptions opts = new BuildOptions(buildConfig.getBuildOptions()).dockerfile(getDockerfileName(buildConfig)).forceRemove(cleanupMode.isRemove()).noCache(noCache).squash(squash).cacheFrom(buildConfig.getCacheFrom()).network(buildConfig.getNetwork()).buildArgs(mergedBuildMap);
String newImageId = doBuildImage(imageName, dockerArchive, opts);
log.info("%s: Built image %s", imageConfig.getDescription(), newImageId);
removeDanglingImage(imageName, oldImageId, newImageId, cleanupMode, true);
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class DockerAccessWithHcClient method listNetworks.
@Override
public List<Network> listNetworks() throws DockerAccessException {
String url = urlBuilder.listNetworks();
try {
String response = delegate.get(url, HTTP_OK);
JsonArray array = JsonFactory.newJsonArray(response);
List<Network> networks = new ArrayList<>(array.size());
for (int i = 0; i < array.size(); i++) {
networks.add(new NetworksListElement(array.get(i).getAsJsonObject()));
}
return networks;
} catch (IOException e) {
throw new DockerAccessException(e.getMessage());
}
}
Aggregations