testcontainers / testcontainers/testcontainers-java

How to make sure there's no stray container not removed when using withDockerfileFromBuilder?

Ouverte
#3,558 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Java
Étoiles
8.7k
Forks
1.9k
Merge moyen
2 j 17 h
PR mergées (30 j)
9

Description

Hi guys,

On XWiki, and since the upgrade to TC 1.15.0 (might not be related but didn't notice it before), I've noticed on our CI agents, that there are some TC-created containers that are not always removed on agents. For example:

Screenshot 2020-12-06 at 17 18 06

These containers are created with the following:

                LOGGER.info("(*) Build a dedicated image embedding LibreOffice...");
                // The second argument of the ImageFromDockerfile is here to indicate we won't delete the image
                // at the end of the test container execution.
                container = new XWikiLocalGenericContainer(new ImageFromDockerfile(imageName, false)
                    .withDockerfileFromBuilder(builder -> {
                        builder
                            .from(baseImageName)
                            .user("root")
                            .env("LIBREOFFICE_VERSION", officeVersion)
                            .env("LIBREOFFICE_DOWNLOAD_URL", "https://downloadarchive.documentfoundation.org/"
                                + "libreoffice/old/$LIBREOFFICE_VERSION/deb/x86_64/"
                                + "LibreOffice_${LIBREOFFICE_VERSION}_Linux_x86-64_deb.tar.gz")
                            // Note that we expose libreoffice /usr/local/libreoffice so that it can be found by
                            // JODConverter: https://bit.ly/2w8B82Q
                            .run("apt-get update && "
                                + "apt-get --no-install-recommends -y install curl unzip procps libxinerama1 "
                                    + "libdbus-glib-1-2 libcairo2 libcups2 libsm6 && "
                                + "rm -rf /var/lib/apt/lists/* /var/cache/apt/* && "
                                + "wget --no-verbose -O /tmp/libreoffice.tar.gz $LIBREOFFICE_DOWNLOAD_URL && "
                                + "mkdir /tmp/libreoffice && "
                                + "tar -C /tmp/ -xvf /tmp/libreoffice.tar.gz && "
                                + "cd /tmp/LibreOffice_${LIBREOFFICE_VERSION}_Linux_x86-64_deb/DEBS && "
                                + "dpkg -i *.deb && "
                                + "ln -fs `ls -d /opt/libreoffice*` /opt/libreoffice")
                            // Increment the image version whenever a change is brought to the image so that it can
                            // reconstructed on all machines needing it.
                            .label(OFFICE_IMAGE_VERSION_LABEL, imageVersion);
                        if (this.testConfiguration.getServletEngine() == ServletEngine.JETTY) {
                            // Create the right jetty user directory since it doesn't exist
                            builder.run("mkdir -p /home/jetty && chown jetty:jetty /home/jetty")
                                // Put back the user as jetty since it's a best practice to not execute the container as
                                // root.
                                .user("jetty");
                        }

                        builder.build();
                    }));

See https://github.com/xwiki/xwiki-platform/blob/eaced75f5a08b4131e36504fb5f6c71d6b392fa8/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/internal/junit5/servletengine/ServletContainerExecutor.java#L286 for more details.

Would you have any idea what could be happening and what we could do?

Thanks a lot

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par ServletContainerExecutor.java autour de la ligne 286 et suivez l’utilisation de withDockerfileFromBuilder présentée dans l’issue. Reproduisez le scénario du CI-agent avec le conteneur référencé et examinez le comportement de nettoyage de Testcontainers. La tâche est terminée lorsque vous avez identifié pourquoi les conteneurs créés restent présents et documenté ou implémenté une correction de nettoyage vérifiée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
docker, java
Domaine
devops, testing
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.