/** * 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); }
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; } }
@Override public String toString() { return getPath(); }
@Override public boolean equals(Object obj) { if (obj instanceof Volume) { Volume other = (Volume) obj; return new EqualsBuilder().append(path, other.getPath()).isEquals(); } else { return super.equals(obj); } }
/** * {@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)); }
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; } }
@Override public void serialize(Volumes volumes, JsonGenerator jsonGen, SerializerProvider serProvider) throws IOException, JsonProcessingException { jsonGen.writeStartObject(); for (Volume volume : volumes.getVolumes()) { jsonGen.writeFieldName(volume.getPath()); jsonGen.writeStartObject(); jsonGen.writeEndObject(); } jsonGen.writeEndObject(); }
@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 void serialize(VolumeRW volumeRW, JsonGenerator jsonGen, SerializerProvider serProvider) throws IOException, JsonProcessingException { jsonGen.writeStartObject(); jsonGen.writeFieldName(volumeRW.getVolume().getPath()); jsonGen.writeString(Boolean.toString(volumeRW.getAccessMode().toBoolean())); jsonGen.writeEndObject(); }
@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 void serialize(VolumesRW value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); for (final VolumeRW volumeRW : value.volumesRW) { jgen.writeBooleanField(volumeRW.getVolume().getPath(), volumeRW.getAccessMode().toBoolean()); } jgen.writeEndObject(); }
@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()])); } }
/** * Returns a string representation of this {@link Bind} suitable for inclusion in a JSON message. * The format is <code><host path>:<container path>:<access mode></code>, * like the argument in {@link #parse(String)}. * * @return a string representation of this {@link Bind} */ @Override public String toString() { return String.format("%s:%s:%s%s%s%s", path, volume.getPath(), accessMode.toString(), secMode != SELContext.none ? "," + secMode.toString() : "", noCopy != null ? ",nocopy" : "", propagationMode != PropagationMode.DEFAULT_MODE ? "," + propagationMode.toString() : ""); } }
@Override public String toString() { return getPath(); }
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());
@Override public boolean equals(Object obj) { if (obj instanceof Volume) { Volume other = (Volume) obj; return new EqualsBuilder().append(path, other.getPath()).isEquals(); } else { return super.equals(obj); } }
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; }
@Override public void serialize(Volumes volumes, JsonGenerator jsonGen, SerializerProvider serProvider) throws IOException, JsonProcessingException { jsonGen.writeStartObject(); for (Volume volume : volumes.getVolumes()) { jsonGen.writeFieldName(volume.getPath()); jsonGen.writeStartObject(); jsonGen.writeEndObject(); } jsonGen.writeEndObject(); }
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; }