GenericContainer не забирает файлы для обработки - PullRequest
1 голос
/ 12 июня 2019

GenericContainer не обрабатывает файлы во время работы вне Testcontainer, работает нормально

Похоже, что контейнер каким-то образом ограничен, недостаточно ресурсов или каким-либо образом заблокирован, или просмотр файлов ведет себя неправильно с bind.

public class SimpleIntegrationTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleIntegrationTest.class);

    @Rule
    public GenericContainer container = new GenericContainer<>(
            new ImageFromDockerfile()
                    .withDockerfileFromBuilder(builder ->
                            builder
                                    .from("ourproduct:latest")
                                    .workDir("/opt/ourproduct")
                                    .entryPoint("./Scripts/start.sh")
                                    .build()))
            .withExposedPorts(8080)
            .withFileSystemBind("/home/greg/share", "/share", BindMode.READ_WRITE)
            .withCreateContainerCmdModifier(cmd -> cmd.withHostName("somehost.com"))
            .waitingFor(Wait.forLogMessage(".*Ourproduct is Up.*\\n", 1).withStartupTimeout(Duration.ofSeconds(60)));

    @Test
    public void simpleExchangeTest() throws IOException, InterruptedException {

        LOGGER.info("Starting simple exchange test...");

        // copy input file
        InputStream request = ClassLoader.getSystemResourceAsStream("message.txt");
        File target = new File("/home/greg/share/input/message.txt");
        FileUtils.copyToFile(request, target);
        FileUtils.touch(target);

        // watch for response
        Path path = Paths.get("/home/greg/share/output");
        WatchService watchService = path.getFileSystem().newWatchService();
        path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);

        LOGGER.info("Waiting up to [{}] seconds for response file...", 30);
        WatchKey watchKey = watchService.poll(30, TimeUnit.SECONDS);

        if (watchKey != null) {
            watchKey.pollEvents().stream().forEach(event -> LOGGER.info(event.context().toString()));
        }

        LOGGER.info("Container logs...");
        LOGGER.info(container.getLogs());

    }
}

Очевидно, я ожидаю ответа в /home/greg/share/output, но он никогда не приходит.

Хорошо работает, когда я делаю:

  1. docker run -itd --name cont --hostname somehost.com -p 8080:8080 --mount type=bind,source=/home/greg/share,target=/share ourproduct:latest
  2. docker exec -it cont bash

В контейнере

  1. cd /opt/ourproduct
  2. ./Scripts/start.sh

Внешний контейнер на хосте

  1. cp message.txt /home/greg/share/input/

Через несколько секунд я получаю ответ в home/greg/share/output Не относится к TestContainers ...

РЕДАКТИРОВАТЬ: Когда я добавляю в тесте:

Container.ExecResult execResult = container.execInContainer("./Scripts/status.sh");

Я получаю:

com.github.dockerjava.api.exception.ConflictException: {"message":"Container aac697315e3e22ccee4cdf805e6b1b325663bae054ab1104021c4da724cb4a5a is not running"}

Есть идеи, что не так и почему не работает?

1 Ответ

0 голосов
/ 12 июня 2019

добавление хвоста решило проблему

.entryPoint("./Scripts/start.sh && tail -f /dev/null")
...