Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/with-volumes-from support #289

Merged
merged 2 commits into from
Feb 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public String getStderr() {
*/
SELF withFileSystemBind(String hostPath, String containerPath, BindMode mode);

/**
* Adds container volumes.
*
* @param container the container to add volumes from
* @param mode the bind mode
* @return this
*/
SELF withVolumesFrom(Container container, BindMode mode);

/**
* Set the ports that this container listens on
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public class GenericContainer<SELF extends GenericContainer<SELF>>
@NonNull
private boolean privilegedMode;

@NonNull
private List<VolumesFrom> volumesFroms = new ArrayList<>();

@NonNull
private Map<String, LinkableContainer> linkedContainers = new HashMap<>();

Expand Down Expand Up @@ -344,6 +347,10 @@ private void applyConfiguration(CreateContainerCmd createCommand) {
.toArray(Bind[]::new);
createCommand.withBinds(bindsArray);

VolumesFrom[] volumesFromsArray = volumesFroms.stream()
.toArray(VolumesFrom[]::new);
createCommand.withVolumesFrom(volumesFromsArray);

Set<Link> allLinks = new HashSet<>();
Set<String> allLinkedContainerNetworks = new HashSet<>();
for (Map.Entry<String, LinkableContainer> linkEntries : linkedContainers.entrySet()) {
Expand Down Expand Up @@ -494,6 +501,19 @@ public SELF withFileSystemBind(String hostPath, String containerPath, BindMode m
return self();
}

/**
* {@inheritDoc}
*/
@Override
public SELF withVolumesFrom(Container container, BindMode mode) {
addVolumesFrom(container, mode);
return self();
}

private void addVolumesFrom(Container container, BindMode mode) {
volumesFroms.add(new VolumesFrom(container.getContainerName(), mode.accessMode));
}

@Override
public void addLink(LinkableContainer otherContainer, String alias) {
this.linkedContainers.put(alias, otherContainer);
Expand Down