testcontainers / testcontainers/testcontainers-java

Testcontainer interacting with a java class that depeneds on the product

Open
#3,517 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

Hi,

I am working on Call Home Client (SSH) for our product.

src/main/java
src/test/java
src/test/resources
  /call-home-ssh-client/Dockerfile
  /netopeer2/Dockerfile

I want to use the excellent testcontainer to test with a server (netopeer2). So I have created a test client ( src/test/java) that depends on our product ( src/main/java).

So I want to start call-home-ssh-client from docker image in a unit test. Then create the netopeer2 server from the other image and trigger call-home from it.

So for the call-home-ssh-client I need to build the src tree of my project and create a jar. Then I would run the specific test client inside the container.
Problem I am facing is that when I call the call-home-ssh-client from unit test with this part:

 
          final ImageFromDockerfile callHomeSshImage = new ImageFromDockerfile(
                "ssh-client", false)
                        .withFileFromClasspath(".", "call-home-ssh-client");
        return new GenericContainer<>(callHomeSshImage)
                .withExposedPorts(new Integer[] { 4334 })
                .withLogConsumer(logConsumer)
                .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Call Home  listening on port [4334]*"));

and using this part of my call-home-ssh-client Dockerfile

FROM maven:3.6.1-jdk-8-alpine AS MAVEN_BUILD
WORKDIR /app
# copy the pom and src code to the container 
COPY ../src ./

RUN mvn clean package 

Could not build image: COPY failed: Forbidden path outside the build context: ../src

Do I need to create my GenericContainer in another way to support this?

The other option I was thinking of would be to create the call-home-ssh-client as a java thread and have it running while
I start my server ( netopeer2 ) also as Docker container. Could they talk to eachother?

I would appreciate if you could tell me what is possible to do with testcontainers since I could not figure it out from documentation.

br,

//mike

Ps. Testcontainers is a really neat feature!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the src/test/java container setup and the call-home-ssh-client/Dockerfile, especially the ImageFromDockerfile and withFileFromClasspath entry points. Reproduce the Forbidden path outside the build context error, then determine whether the supported behavior or documentation should explain how to provide the required source and JAR files. Done means the integration-test setup has a documented or verified way to build and run both containers.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java
Domain
devops, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.