Skip to content

Converting SshAgentContainer & XvncSlaveContainer to Testcontainers#2582

Merged
jtnord merged 4 commits into
jenkinsci:masterfrom
jglick:testcontainers
Jan 15, 2026
Merged

Converting SshAgentContainer & XvncSlaveContainer to Testcontainers#2582
jtnord merged 4 commits into
jenkinsci:masterfrom
jglick:testcontainers

Conversation

@jglick
Copy link
Copy Markdown
Member

@jglick jglick commented Jan 13, 2026

Beginning of #857 (not converting other fixtures yet). Needed to make agents run on Java 21 (#2576 (comment)). Avoids the need for a new docker-fixtures release (jenkinsci/docker-fixtures#138 (comment) jenkinsci/docker-fixtures#122 (comment)) and so supersedes #2581. Cannot just use jenkins/ssh-agent like in jenkinsci/ssh-agents-plugin#984 since some of these tests rely on password authentication, whereas the official image only supports SSH private key authentication. For now I just inlined the original Dockerfile contents; could be cleaned up in various ways later.

@jglick jglick requested a review from a team as a code owner January 13, 2026 19:55
Comment thread pom.xml
@jglick
Copy link
Copy Markdown
Member Author

jglick commented Jan 14, 2026

SshSlavesPluginTest.newAgent failure in CI I cannot reproduce locally (using Java 25 and 2.544). Screenshot shows some JS error?

Got type array but no lister class found for type class com.cloudbees.plugins.credentials.CredentialsScope

Maybe a flake? Just suspicious it would have appeared in this PR. Note that this test case does not use Docker and so should not have been affected by the fixture changes.

@timja
Copy link
Copy Markdown
Member

timja commented Jan 14, 2026

Maybe a flake? Just suspicious it would have appeared in this PR. Note that this test case does not use Docker and so should not have been affected by the fixture changes.

see #2568 known issue, theory is timing related in JavaScript.

Can be reproduced locally if you run it enough. @jtnord saw it 1/10 times. Sometimes I have seen it multiple times in a row.

@jglick jglick requested a review from jtnord January 14, 2026 16:51
return resource("ed25519.priv").asText();
public SshAgentContainer() {
super(new ImageFromDockerfile("localhost/testcontainers/ath-ssh-agent", false)
.withFileFromClasspath(".", SshAgentContainer.class.getName().replace('.', '/')));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: generally you should only add the things that are needed - otherwise all of them can be sent to the testcontainer server for building (and it takes longer). (the build is currently only a local(ish) docker compliant server so currently this does not add too much overhead)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally you should only add the things that are needed

WDYM? This is sending https://github.com/jenkinsci/acceptance-test-harness/tree/5f032d5666d5e8e8fe0ccdf635d6a0866654c851/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/SshAgentContainer which is exactly what is needed by the Docker daemon.

Copy link
Copy Markdown
Member

@jtnord jtnord Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally you should only add the things that are needed

WDYM? This is sending https://github.com/jenkinsci/acceptance-test-harness/tree/5f032d5666d5e8e8fe0ccdf635d6a0866654c851/src/main/resources/org/jenkinsci/test/acceptance/docker/fixtures/SshAgentContainer which is exactly what is needed by the Docker daemon.

it only needs some of the files in that directory (the Dockerfile and the .pubs and the .pub is questionable) .

e.g.

   // ...
   .withFileFromClasspath("Dockerfile", SshAgentContainer.class.getName().replace('.', '/'))
   .withFileFromClasspath("ed25519.pub", SshAgentContainer.class.getName().replace('.', '/') + "/ed25519.pub")
   .withFileFromClasspath("unsafe_enc_key.pub", SshAgentContainer.class.getName().replace('.', '/') + "/unsafe_enc_key.pub")
   //...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK we could .dockerignore the private keys for example, but these are tiny files. We just do not want to be streaming megabytes of unused binaries, and we are not.

Copy link
Copy Markdown
Member

@jtnord jtnord Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hence was a NIT, not blocking anything on this

public String getEncryptedEd25519PrivateKey() {
return resource("ed25519.priv").asText();
public SshAgentContainer() {
super(new ImageFromDockerfile("localhost/testcontainers/ath-ssh-agent", false)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought not deleting the image would causes issues with stale images when the Dockerfile or other input was changed, but apparently there is something in testcontainers here that handles this. (could not find docs on it though)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK specifying true (or not specifying it, e.g., just use the no-arg ctor) just means that it will do something like docker rmi after the test completes, throwing away your cache. Whereas passing false is the equivalent of just docker build.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: edits to Dockerfile are honored when you next mvn test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: edits to Dockerfile are honored when you next mvn test.

sorry I was unclear - I had already tested this happened did not mean for you to test it, and this was a comment for anyone else who may see this in the future.

Comment on lines +19 to +20
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzpxmTW9mH87DMkMSqBrSecoSHVCkKbW5IOO+4unak8M8cyn+b0iX07xkBn4hUJRfKA7ezUG8EX9ru5VinteqMOJOPknCuzmUS2Xj/WJdcq3BukBxuyiIRoUOXsCZzilR/DOyNqpjjI3iNb4los5//4aoKPCmLInFnQ3Y42VaimH1298ckEr4tRxsoipsEAANPXZ3p48gGwOf1hp56bTFImvATNwxMViPpqyKcyVaA7tXCBnEk/GEwb6MiroyHbS0VvBz9cZOpJv+8yQnyLndGdibk+hPbGp5iVAIsm28FEF+4FvlYlpBwq9OYuhOCREJvH9CxDMhbOXgwKPno9GyN kohsuke@atlas' > /home/test/.ssh/authorized_keys && \
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDagNSCDst/8z5oH9S5QWr+QNdx+haImY0FD3IQvKdD+eWI9zUbBgtoo/yYEbLvpTWiKsgT3Hw1F8mZ+/bd2Uv3lPyoG+TSzrHL4gSal6d1RWVjCOzSosciXVm4gRUvJjKXzaz8dOg+ii9yIrbeONNK0nlDUCAKy5YXSEl0avcPdUDyR3cStL6870SyanxAzktDw0n8xMq4F/alF3PZ002bcZJrmDeNVAwkP+uO2Tf8pN37SU+nApotZmlmZR32xYHnx+/OiQ7gOAVYmgNRMg0Kwh6Q73FcY3ZWCeNHwLnr95LoEAdj3On8Qr62VhGThuQNVCqBc6SeYjArfjijpcW9 jenkins-ci@localhost' >> /home/test/.ssh/authorized_keys && \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do this as well as the following below (those public keys are identical are they not, and if not would it not be better to just manage them all in the same way to avoid confusion)?

COPY *.pub /tmp/
RUN cat /tmp/*.pub >> /home/test/.ssh/authorized_keys

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To try to keep this PR straightforward to review,

For now I just inlined the original Dockerfile contents; could be cleaned up in various ways later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOW, this is making the minimum changes:

  • changing Java 17 to 21
  • switch from docker-fixtures to exact equivalent Dockerfile layers

@jglick jglick requested a review from jtnord January 15, 2026 15:13
@jtnord jtnord enabled auto-merge January 15, 2026 15:14
@jglick
Copy link
Copy Markdown
Member Author

jglick commented Jan 15, 2026

@jtnord jtnord merged commit ab406f4 into jenkinsci:master Jan 15, 2026
34 checks passed
@jtnord
Copy link
Copy Markdown
Member

jtnord commented Jan 16, 2026

@jglick jglick deleted the testcontainers branch January 16, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants