/** * Handles the {@code { "Destination" : { "path" : "/path/to/mount" } }} variant. * @param path the destination path of the bind mounted volume * @return a volume instance referring to the given path. */ @Nonnull @JsonCreator public static Volume parse(@JsonProperty("path") String path) { return new Volume(path); }
/** * {@inheritDoc} */ @Override public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) { final MountableFile mountableFile = MountableFile.forHostPath(hostPath); binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext)); }
@Override public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); String volume = field.getKey(); AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean()); return new VolumeRW(new Volume(volume), accessMode); } else { return null; } } }
@Override public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<Volume> volumes = new ArrayList<Volume>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); if (!field.getValue().equals(NullNode.getInstance())) { String path = field.getKey(); Volume volume = new Volume(path); volumes.add(volume); } } return new Volumes(volumes.toArray(new Volume[0])); } }
@Override public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<VolumeRW> volumesRW = new ArrayList<VolumeRW>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); JsonNode value = field.getValue(); if (!value.equals(NullNode.getInstance())) { if (!value.isBoolean()) { throw deserializationContext.mappingException("Expected access mode for '" + field.getKey() + "' in host but got '" + value + "'."); } VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean())); volumesRW.add(bind); } } return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()])); } }
private boolean checkMountableFile() { DockerClient dockerClient = client(); MountableFile mountableFile = MountableFile.forClasspathResource(ResourceReaper.class.getName().replace(".", "/") + ".class"); Volume volume = new Volume("/dummy"); try { return runInsideDocker( createContainerCmd -> createContainerCmd.withBinds(new Bind(mountableFile.getResolvedPath(), volume, AccessMode.ro)), (__, containerId) -> { try (InputStream stream = dockerClient.copyArchiveFromContainerCmd(containerId, volume.getPath()).exec()) { stream.read(); return true; } catch (Exception e) { return false; } } ); } catch (Exception e) { log.debug("Failure while checking for mountable file support", e); return false; } }
public void runBuild(String image, String cmd, Path repoPath) { log.info("Run Build Start"); String fileName = repoPath.getFileName().toString(); Volume volume = new Volume(File.separator + fileName); Volume mvnVolume = new Volume(DOCKER_MVN_CACHE_FOLDER); log.info("Run Build Start - " + Paths.get(repoPath.getParent().toString(), REPOSITORY).toString());
private static final Volume[] toVolumes(Collection<String> volumesList) { Volume[] volumes = new Volume[volumesList.size()]; int i = 0; for (String volume : volumesList) { String[] volumeSection = volume.split(":"); if (volumeSection.length == 2 || volumeSection.length == 3) { volumes[i] = new Volume(volumeSection[1]); } else { volumes[i] = new Volume(volumeSection[0]); } i++; } return volumes; }
private static final Volume[] toVolumes(Collection<String> volumesList) { Volume[] volumes = new Volume[volumesList.size()]; int i = 0; for (String volume : volumesList) { String[] volumeSection = volume.split(":"); if (volumeSection.length == 2 || volumeSection.length == 3) { volumes[i] = new Volume(volumeSection[1]); } else { volumes[i] = new Volume(volumeSection[0]); } i++; } return volumes; }
/** * Handles the {@code { "Destination" : { "path" : "/path/to/mount" } }} variant. * @param path the destination path of the bind mounted volume * @return a volume instance referring to the given path. */ @Nonnull @JsonCreator public static Volume parse(@JsonProperty("path") String path) { return new Volume(path); }
/** * {@inheritDoc} */ @Override public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) { final MountableFile mountableFile = MountableFile.forHostPath(hostPath); binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext)); }
@Override public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); String volume = field.getKey(); AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean()); return new VolumeRW(new Volume(volume), accessMode); } else { return null; } } }
@Override public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<Volume> volumes = new ArrayList<Volume>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); if (!field.getValue().equals(NullNode.getInstance())) { String path = field.getKey(); Volume volume = new Volume(path); volumes.add(volume); } } return new Volumes(volumes.toArray(new Volume[0])); } }
@Override public CreateContainerCmd build(ServiceDescriptor sd, CreateContainerCmd cmd, Volume v) { Bind[] binds = cmd.getBinds(); String hostPath = v.useClasspath() ? Thread.currentThread().getContextClassLoader() .getResource(v.host()).getPath() : v.host(); Bind bind = new Bind(hostPath, new com.github.dockerjava.api.model.Volume(v.container()), AccessMode.fromBoolean(v.accessMode().equals(Volume.AccessMode.RW))); List<Bind> bindsList = new ArrayList<>(); if(binds != null) { bindsList.addAll(Arrays.asList(binds)); } bindsList.add(bind); return cmd.withBinds(bindsList); }
public void mountFiles(CreateContainerCmd createContainerCmd) { String videoFilesDiskPath = "/var/lib/jenkins/test-files"; Volume configVol = new Volume(KurentoTest.getTestFilesDiskPath()); createContainerCmd.withVolumes(configVol).withBinds(new Bind(videoFilesDiskPath, configVol)); }
public void mountFiles(CreateContainerCmd createContainerCmd) { String videoFilesDiskPath = "/var/lib/jenkins/test-files"; Volume configVol = new Volume(KurentoTest.getTestFilesDiskPath()); createContainerCmd.withVolumes(configVol).withBinds(new Bind(videoFilesDiskPath, configVol)); }
public void createContainer(String imageId, String containerName, boolean mountFolders, String... env) { pullImageIfNecessary(imageId, false); log.debug("Creating container {}", containerName); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withName(containerName).withEnv(env) .withVolumes(new Volume("/var/run/docker.sock")); if (mountFolders) { mountDefaultFolders(createContainerCmd); } createContainerCmd.exec(); log.debug("Container {} started...", containerName); }
public void createContainer(String imageId, String containerName, boolean mountFolders, String... env) { pullImageIfNecessary(imageId, false); log.debug("Creating container {}", containerName); CreateContainerCmd createContainerCmd = getClient().createContainerCmd(imageId).withName(containerName).withEnv(env) .withVolumes(new Volume("/var/run/docker.sock")); if (mountFolders) { mountDefaultFolders(createContainerCmd); } createContainerCmd.exec(); log.debug("Container {} started...", containerName); }
private boolean checkMountableFile() { DockerClient dockerClient = client(); MountableFile mountableFile = MountableFile.forClasspathResource(ResourceReaper.class.getName().replace(".", "/") + ".class"); Volume volume = new Volume("/dummy"); try { return runInsideDocker(createContainerCmd -> createContainerCmd.withBinds(new Bind(mountableFile.getResolvedPath(), volume, AccessMode.ro)), (__, containerId) -> { try (InputStream stream = dockerClient.copyArchiveFromContainerCmd(containerId, volume.getPath()).exec()) { stream.read(); return true; } catch (Exception e) { return false; } }); } catch (Exception e) { log.debug("Failure while checking for mountable file support", e); return false; } }