.image("05794515afd5724df1cdf0e674ae932455fce7dea3c70a94d77119ad1fa954ba") .workingDir("/home/user") .build(), Config.builder().cmd(ImmutableList.of("/bin/sh", "-c", "echo hello world")) .env(ImmutableList.of( .image("05794515afd5724df1cdf0e674ae932455fce7dea3c70a94d77119ad1fa954ba") .workingDir("/home/user") .build(), "05794515afd5724df1cdf0e674ae932455fce7dea3c70a94d77119ad1fa954ba", new SimpleDateFormatDateService().iso8601DateParse("2014-11-24T11:09:20.310023104Z"),
@BeforeMethod public void setup() { image = org.jclouds.docker.domain.Image.create( "id", // id "author", "comment", Config.builder() .image("imageId") .build(), Config.builder() .image("imageId") .build(), "parent", // parent new Date(), // created "containerId", // container "1.3.1", // dockerVersion "x86_64", // architecture "os", // os 0L, // size 0L, // virtualSize ImmutableList.of("repoTag1:version") // repoTags ); function = new ImageToImage(); }
public void testCreateContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container-creation.json"))); ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); Config containerConfig = Config.builder() .cmd(ImmutableList.of("date")) .attachStdin(false) .attachStderr(true) .attachStdout(true) .tty(false) .image("base") .build(); try { Container container = api.createContainer("test", containerConfig); assertSent(server, "POST", "/containers/create?name=test"); assertNotNull(container); assertThat(container.id()).isEqualTo("c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2"); } finally { server.shutdown(); } }
@Test public void testFromConfig() { Config origConfig = Config.builder() .hostname("6c9932f478bd") .env(ImmutableList.of("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")) .image("57e570db16baba1e8c0d6f3c15868ddb400f64ff76ec948e65c3ca3f15fb3587") .domainname("") .user("") .cmd(ImmutableList.of("-name", "7a:63:a2:39:7b:0f")) .entrypoint(ImmutableList.of("/home/weave/weaver", "-iface", "ethwe", "-wait", "5")) .image("zettio/weave") .workingDir("/home/weave") .exposedPorts(ImmutableMap.of("6783/tcp", ImmutableMap.of(), "6783/udp", ImmutableMap.of())) .build(); Config newConfig = Config.builder().fromConfig(origConfig).build(); assertThat(origConfig).isEqualTo(newConfig); }
/** * This method sets Config.Builder configuration object, which can be used as * a replacement for all the other settings from this class. Some values in * the provided Config.Builder instance (the image name for instance) can be * ignored or their value can be changed. * * @param configBuilder * Config.Builder instance. This instance can be changed in this * method! */ public DockerTemplateOptions configBuilder(Config.Builder configBuilder) { this.configBuilder = configBuilder != null ? Config.builder().fromConfig(configBuilder.image(NO_IMAGE).build()) : null; return this; }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("miscApiTest", containerConfig); assertNotNull(container); api.getContainerApi().startContainer(container.id()); assertTrue(api.getContainerApi().inspectContainer(container.id()).state().running()); }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("jclouds-test-network", containerConfig); api.getContainerApi().startContainer(container.id()); container = api.getContainerApi().inspectContainer(container.id()); }
/** * This method sets Config.Builder configuration object, which can be used as * a replacement for all the other settings from this class. Some values in * the provided Config.Builder instance (the image name for instance) can be * ignored or their value can be changed. * * @param configBuilder * Config.Builder instance. This instance can be changed in this * method! */ public DockerTemplateOptions configBuilder(Config.Builder configBuilder) { this.configBuilder = configBuilder != null ? Config.builder().fromConfig(configBuilder.image(NO_IMAGE).build()) : null; return this; }
@Test public void testNullValuesPropagation() { Config config = Config.builder() .image("zettio/weave") .build(); assertThat(config.cmd()).isNull(); assertThat(config.entrypoint()).isNull(); assertThat(config.env()).isNull(); assertThat(config.hostname()).isNull(); assertThat(config.domainname()).isNull(); assertThat(config.workingDir()).isNull(); assertThat(config.hostConfig()).isNull(); } }
/** * This method sets Config.Builder configuration object, which can be used as * a replacement for all the other settings from this class. Some values in * the provided Config.Builder instance (the image name for instance) can be * ignored or their value can be changed. * * @param configBuilder * Config.Builder instance. This instance can be changed in this * method! */ public DockerTemplateOptions configBuilder(Config.Builder configBuilder) { this.configBuilder = configBuilder != null ? Config.builder().fromConfig(configBuilder.image(NO_IMAGE).build()) : null; return this; }
/** * This method sets Config.Builder configuration object, which can be used as * a replacement for all the other settings from this class. Some values in * the provided Config.Builder instance (the image name for instance) can be * ignored or their value can be changed. * * @param configBuilder * Config.Builder instance. This instance can be changed in this * method! */ public DockerTemplateOptions configBuilder(Config.Builder configBuilder) { this.configBuilder = configBuilder != null ? Config.builder().fromConfig(configBuilder.image(NO_IMAGE).build()) : null; return this; }
@Test public void testConfigBuilder() { Builder builder = Config.builder().memory(1024) .cpuShares(100).cmd(ImmutableList.<String> of("/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0")) .env(ImmutableList.<String> of("JAVA_HOME=/opt/jdk-1.8", "MGMT_USER=admin", "MGMT_PASSWORD=Schroedinger's Cat")); TemplateOptions options = DockerTemplateOptions.Builder.configBuilder(builder); Builder builderInOpts = options.as(DockerTemplateOptions.class).getConfigBuilder(); assertNotNull(builderInOpts); Config configFromOptions = builderInOpts.build(); assertEquals(configFromOptions, builder.build()); assertEquals(configFromOptions.env(), ImmutableList.<String> of("JAVA_HOME=/opt/jdk-1.8", "MGMT_USER=admin", "MGMT_PASSWORD=Schroedinger's Cat")); }
public void testNoImageFoundInMap() { Config config = Config.builder().image("unexisting").build(); Container container = Container.builder().id("id").config(config).build(); assertEquals(customLoginPortFromImage.apply(container), Optional.absent()); }
public void testPortFromEnvironmentVariables() { Config config = Config.builder().image("alpine-ext:3.2").env(ImmutableList.of("FOO=bar", "SSH_PORT=2345")) .build(); Container container = Container.builder().id("id").config(config).build(); assertEquals(customLoginPortFromImage.apply(container).get().intValue(), 2345); }
public void testCreateContainer() throws IOException, InterruptedException { Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api().createContainer("testCreateContainer", containerConfig); assertNotNull(container); assertNotNull(container.id()); }
public void testMostSpecificImageIsPicked() { Config config = Config.builder().image("ubuntu:12.04").build(); Container container = Container.builder().id("id").config(config).build(); assertEquals(customLoginPortFromImage.apply(container).get().intValue(), 8080); }