Skip to content

Commit

Permalink
Merge pull request #88 from pivotal-sydney/master
Browse files Browse the repository at this point in the history
Docker compose up individual containers
  • Loading branch information
iamdanfox authored Aug 25, 2016
2 parents 89c4ec5 + 614438b commit 623d430
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public State state() throws IOException, InterruptedException {
return dockerComposeProcess.state(containerName);
}

public void up() throws IOException, InterruptedException {
dockerComposeProcess.up(this);
}

private Ports getDockerPorts() {
try {
return dockerComposeProcess.ports(containerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public void rm() throws IOException, InterruptedException {
command.execute(Command.throwingOnError(), "rm", "--force", "-v");
}

@Override
public void up(Container container) throws IOException, InterruptedException {
command.execute(Command.throwingOnError(), "up", "-d", container.getContainerName());
}

@Override
public void start(Container container) throws IOException, InterruptedException {
command.execute(Command.throwingOnError(), "start", container.getContainerName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void rm() throws IOException, InterruptedException {
dockerCompose.rm();
}

@Override
public void up(Container container) throws IOException, InterruptedException {
dockerCompose.up(container);
}

@Override
public void start(Container container) throws IOException, InterruptedException {
dockerCompose.start(container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface DockerCompose {
void down() throws IOException, InterruptedException;
void kill() throws IOException, InterruptedException;
void rm() throws IOException, InterruptedException;
void up(Container container) throws IOException, InterruptedException;
void start(Container container) throws IOException, InterruptedException;
void stop(Container container) throws IOException, InterruptedException;
String exec(DockerComposeExecOption dockerComposeExecOption, String containerName, DockerComposeExecArgument dockerComposeExecArgument) throws IOException, InterruptedException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.palantir.docker.compose;

import static com.palantir.docker.compose.connection.waiting.ClusterHealthCheck.serviceHealthCheck;
import static com.palantir.docker.compose.connection.waiting.HealthChecks.toHaveAllPortsOpen;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

import com.palantir.docker.compose.connection.Container;
import com.palantir.docker.compose.connection.State;
import com.palantir.docker.compose.connection.waiting.ClusterWait;
import java.io.IOException;
import org.joda.time.Duration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class DockerComposeRuleUpContainerIntegrationTest {

private static final String DOCKER_COMPOSE_YAML_PATH = "src/test/resources/docker-compose.yaml";

private DockerComposeRule dockerComposeRule;

@Before
public void setUp() throws Exception {
dockerComposeRule = DockerComposeRule.builder().file(DOCKER_COMPOSE_YAML_PATH).build();
}

@After
public void tearDown() throws Exception {
dockerComposeRule.after();
}

@Test
public void test_docker_compose_rule_up_container() throws IOException, InterruptedException {
Container container = dockerComposeRule.containers().container("db");

container.up();

assertThat(container.state(), is(State.Up));
}

@Test
public void test_docker_compose_rule_up_container_with_healthcheck() throws IOException, InterruptedException {
Container container = dockerComposeRule.containers().container("db");

container.up();

// to prove that we can use healthcheck manually after starting a single container
new ClusterWait(serviceHealthCheck("db", toHaveAllPortsOpen()), Duration.standardSeconds(5))
.waitUntilReady(dockerComposeRule.containers());

assertThat(container.state(), is(State.Up));
}
}

0 comments on commit 623d430

Please sign in to comment.