Exemple #1
0
 /**
  * Sets up a PfShell in which Rultor can function.
  *
  * @return PfShell loaded with credentials for new Rultor runner container
  * @throws IOException on failure
  */
 public PfShell shell() throws IOException {
   final ExposedPort ssh = ExposedPort.tcp(22);
   final Ports ports = new Ports();
   ports.bind(ssh, Ports.Binding(null));
   final CreateContainerResponse container =
       this.client
           .createContainerCmd(this.build())
           .withExposedPorts(ssh)
           .withPortBindings(ports)
           .exec();
   this.containers.add(container);
   this.client.startContainerCmd(container.getId()).exec();
   return new PfShell(
       this.profile,
       this.client.infoCmd().exec().getName(),
       this.client
           .inspectContainerCmd(container.getId())
           .exec()
           .getNetworkSettings()
           .getPorts()
           .getBindings()
           .values()
           .iterator()
           .next()[0]
           .getHostPort(),
       "root",
       this.key(container));
 }
  public StellarDocker() {
    dockerClient = DockerClientBuilder.getInstance("unix:///var/run/docker.sock").build();
    cleanup.addStep(dockerClient::close);

    dockerClient
        .pullImageCmd(STELLAR_DOCKER_IMAGE)
        .exec(new PullImageResultCallback())
        .awaitSuccess();

    try {
      final CreateContainerResponse container =
          dockerClient
              .createContainerCmd(STELLAR_DOCKER_IMAGE)
              .withAttachStderr(false)
              .withAttachStdin(false)
              .withAttachStdout(false)
              .withPortBindings(new PortBinding(new Ports.Binding(), ExposedPort.tcp(HORIZON_PORT)))
              .withName(STELLAR_CONTAINER_NAME)
              .exec();
      cleanup.addStep(
          () -> {
            try {
              dockerClient.removeContainerCmd(container.getId()).exec();
            } catch (final DockerException e) {
              /* Do nothing.  Don't inhibit further cleanup.*/
            }
          });
    } catch (final ConflictException e) {
      // the container is already created.
    }

    try {
      dockerClient.startContainerCmd(STELLAR_CONTAINER_NAME).exec();

      cleanup.addStep(
          () -> {
            try {
              dockerClient.stopContainerCmd(STELLAR_CONTAINER_NAME).exec();
            } catch (final DockerException e) {
              /* Do nothing.  Don't inhibit further cleanup.*/
            }
          });
    } catch (final NotModifiedException e) {
      // the container is already running.
    }
  }
  @Test
  public void commitContainerHeaderTest() {

    String containerId = "9c09acd48a25";
    String env = "FOO=bar";
    boolean attachStdErr = true;
    boolean attachStdOut = true;
    boolean attachStdIn = false;
    boolean disableNetwork = false;
    boolean openStdIn = false;
    String portSpecs = "80";
    boolean stdInOnce = false;
    String tag = "1.0";
    String repository = "docker/empty";
    String cmd = "whoami";
    String author = "cameluser";
    String message = "Camel Docker Container Commit";
    boolean pause = false;
    ExposedPorts exposedPorts = new ExposedPorts(ExposedPort.tcp(22));
    Integer memory = 2048;
    Integer swapMemory = 512;
    String workingDir = "/opt";
    String user = "******";
    Volumes volumes = new Volumes(new Volume("/example"));
    boolean tty = true;
    String hostname = "dockerhostname";

    Map<String, Object> headers = getDefaultParameters();
    headers.put(DockerConstants.DOCKER_CONTAINER_ID, containerId);
    headers.put(DockerConstants.DOCKER_ENV, env);
    headers.put(DockerConstants.DOCKER_ATTACH_STD_IN, attachStdIn);
    headers.put(DockerConstants.DOCKER_ATTACH_STD_ERR, attachStdErr);
    headers.put(DockerConstants.DOCKER_ATTACH_STD_OUT, attachStdOut);
    headers.put(DockerConstants.DOCKER_DISABLE_NETWORK, disableNetwork);
    headers.put(DockerConstants.DOCKER_TAG, tag);
    headers.put(DockerConstants.DOCKER_REPOSITORY, repository);
    headers.put(DockerConstants.DOCKER_CMD, cmd);
    headers.put(DockerConstants.DOCKER_AUTHOR, author);
    headers.put(DockerConstants.DOCKER_MESSAGE, message);
    headers.put(DockerConstants.DOCKER_PAUSE, pause);
    headers.put(DockerConstants.DOCKER_EXPOSED_PORTS, exposedPorts);
    headers.put(DockerConstants.DOCKER_MEMORY, memory);
    headers.put(DockerConstants.DOCKER_MEMORY_SWAP, swapMemory);
    headers.put(DockerConstants.DOCKER_WORKING_DIR, workingDir);
    headers.put(DockerConstants.DOCKER_USER, user);
    headers.put(DockerConstants.DOCKER_VOLUMES, volumes);
    headers.put(DockerConstants.DOCKER_TTY, tty);
    headers.put(DockerConstants.DOCKER_HOSTNAME, hostname);
    headers.put(DockerConstants.DOCKER_OPEN_STD_IN, openStdIn);
    headers.put(DockerConstants.DOCKER_STD_IN_ONCE, stdInOnce);
    headers.put(DockerConstants.DOCKER_PORT_SPECS, portSpecs);

    template.sendBodyAndHeaders("direct:in", "", headers);

    Mockito.verify(dockerClient, Mockito.times(1)).commitCmd(containerId);
    Mockito.verify(mockObject, Mockito.times(1)).withEnv(env);
    Mockito.verify(mockObject, Mockito.times(1)).withAttachStderr(attachStdErr);
    Mockito.verify(mockObject, Mockito.times(1)).withAttachStdin(attachStdIn);
    Mockito.verify(mockObject, Mockito.times(1)).withAttachStdout(attachStdOut);
    Mockito.verify(mockObject, Mockito.times(1)).withDisableNetwork(disableNetwork);
    Mockito.verify(mockObject, Mockito.times(1)).withTag(tag);
    Mockito.verify(mockObject, Mockito.times(1)).withRepository(repository);
    Mockito.verify(mockObject, Mockito.times(1)).withCmd(cmd);
    Mockito.verify(mockObject, Mockito.times(1)).withAuthor(author);
    Mockito.verify(mockObject, Mockito.times(1)).withMessage(message);
    Mockito.verify(mockObject, Mockito.times(1)).withPause(pause);
    Mockito.verify(mockObject, Mockito.times(1)).withExposedPorts(exposedPorts);
    Mockito.verify(mockObject, Mockito.times(1)).withMemory(memory);
    Mockito.verify(mockObject, Mockito.times(1)).withMemorySwap(swapMemory);
    Mockito.verify(mockObject, Mockito.times(1)).withWorkingDir(workingDir);
    Mockito.verify(mockObject, Mockito.times(1)).withUser(user);
    Mockito.verify(mockObject, Mockito.times(1)).withVolumes(volumes);
    Mockito.verify(mockObject, Mockito.times(1)).withTty(tty);
    Mockito.verify(mockObject, Mockito.times(1)).withHostname(hostname);
    Mockito.verify(mockObject, Mockito.times(1)).withOpenStdin(openStdIn);
    Mockito.verify(mockObject, Mockito.times(1)).withStdinOnce(stdInOnce);
    Mockito.verify(mockObject, Mockito.times(1)).withPortSpecs(portSpecs);
  }