[TASK] Stop dangling containers in bamboo 40/59340/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Sat, 5 Jan 2019 13:51:43 +0000 (14:51 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 5 Jan 2019 14:55:37 +0000 (15:55 +0100)
In rare conditions a bamboo agent does not stop all
created sibling containers at the end of a job. These
dangling containers then make consecutive runs on this
agents fail due to container namespace collisions.
As a self-heal mechanism, all jobs that fiddle with
containers now simply stop any possibly dangling containers
as an early task before starting own ones.

Resolves: #87334
Releases: master, 9.5, 8.7
Change-Id: I80332da8f9b1013dc8d961e7e532faf59b3bd3b8
Reviewed-on: https://review.typo3.org/59340
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Build/bamboo/src/main/java/core/AbstractCoreSpec.java
Build/bamboo/src/main/java/core/NightlySpec.java
Build/bamboo/src/main/java/core/PreMergeSpec.java

index f8ca7d9..4d7be42 100644 (file)
@@ -191,6 +191,7 @@ abstract public class AbstractCoreSpec {
         .tasks(
             this.getTaskGitCloneRepository(),
             this.getTaskGitCherryPick(),
+            this.getTaskStopDanglingContainers(),
             new ScriptTask()
                 .description("composer validate")
                 .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
@@ -219,6 +220,7 @@ abstract public class AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 this.getTaskComposerInstall(requirementIdentifier),
                 this.getTaskPrepareAcceptanceTest(),
                 this.getTaskDockerDependenciesAcceptanceInstallMariadb10(),
@@ -274,6 +276,7 @@ abstract public class AbstractCoreSpec {
         .tasks(
             this.getTaskGitCloneRepository(),
             this.getTaskGitCherryPick(),
+            this.getTaskStopDanglingContainers(),
             this.getTaskComposerInstall(requirementIdentifier),
             this.getTaskPrepareAcceptanceTest(),
             this.getTaskDockerDependenciesAcceptanceInstallPostgres95(),
@@ -333,6 +336,7 @@ abstract public class AbstractCoreSpec {
                 .tasks(
                     this.getTaskGitCloneRepository(),
                     this.getTaskGitCherryPick(),
+                    this.getTaskStopDanglingContainers(),
                     this.getTaskComposerInstall(requirementIdentifier),
                     this.getTaskPrepareAcceptanceTest(),
                     this.getTaskDockerDependenciesAcceptanceBackendMariadb10(),
@@ -414,6 +418,7 @@ abstract public class AbstractCoreSpec {
                 .tasks(
                     this.getTaskGitCloneRepository(),
                     this.getTaskGitCherryPick(),
+                    this.getTaskStopDanglingContainers(),
                     this.getTaskComposerInstall(requirementIdentifier),
                     this.getTaskDockerDependenciesFunctionalMariadb10(),
                     this.getTaskSplitFunctionalJobs(numberOfChunks),
@@ -474,6 +479,7 @@ abstract public class AbstractCoreSpec {
                 .tasks(
                     this.getTaskGitCloneRepository(),
                     this.getTaskGitCherryPick(),
+                    this.getTaskStopDanglingContainers(),
                     this.getTaskComposerInstall(requirementIdentifier),
                     this.getTaskDockerDependenciesFunctionalMssql(),
                     this.getTaskSplitFunctionalJobs(numberOfChunks),
@@ -538,6 +544,7 @@ abstract public class AbstractCoreSpec {
                 .tasks(
                     this.getTaskGitCloneRepository(),
                     this.getTaskGitCherryPick(),
+                    this.getTaskStopDanglingContainers(),
                     this.getTaskComposerInstall(requirementIdentifier),
                     this.getTaskDockerDependenciesFunctionalPostgres95(),
                     this.getTaskSplitFunctionalJobs(numberOfChunks),
@@ -596,6 +603,7 @@ abstract public class AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 this.getTaskComposerInstall(requirementIdentifier),
                 new ScriptTask()
                     .description("Run duplicate exception code check script")
@@ -708,6 +716,7 @@ abstract public class AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 this.getTaskComposerInstall(requirementIdentifier),
                 new ScriptTask()
                     .description("yarn install in Build/ dir")
@@ -777,6 +786,7 @@ abstract public class AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 new ScriptTask()
                     .description("Run php lint")
                     .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
@@ -815,6 +825,7 @@ abstract public class AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 new ScriptTask()
                     .description("yarn install in Build/ dir")
                     .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
@@ -917,6 +928,7 @@ abstract public class AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 this.getTaskComposerInstall(requirementIdentifier),
                 this.getTaskDockerDependenciesUnit(),
                 new ScriptTask()
@@ -968,6 +980,7 @@ abstract public class AbstractCoreSpec {
                 .tasks(
                     this.getTaskGitCloneRepository(),
                     this.getTaskGitCherryPick(),
+                    this.getTaskStopDanglingContainers(),
                     this.getTaskComposerInstall(requirementIdentifier),
                     this.getTaskDockerDependenciesUnit(),
                     new ScriptTask()
@@ -1035,6 +1048,23 @@ abstract public class AbstractCoreSpec {
     }
 
     /**
+     * Safety net task executed before other task that call containers to
+     * stop any dangling containers from a previous run on this agent.
+     */
+    protected Task getTaskStopDanglingContainers() {
+        return new ScriptTask()
+            .description("Stop dangling containers")
+            .interpreter(ScriptTaskProperties.Interpreter.BINSH_OR_CMDEXE)
+            .inlineBody(
+                this.getScriptTaskBashInlineBody() +
+                "cd Build/testing-docker/bamboo\n" +
+                "docker-compose down -v\n" +
+                "docker rm -f ${BAMBOO_COMPOSE_PROJECT_NAME}sib_adhoc\n" +
+                "exit 0\n"
+            );
+    }
+
+    /**
      * Task definition to execute composer install
      *
      * @param String requirementIdentifier
index 867a5ce..aa9565b 100644 (file)
@@ -178,6 +178,7 @@ public class NightlySpec extends AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 this.getTaskComposerInstall(requirementIdentifier),
                 new ScriptTask()
                     .description("Execute cgl check")
index 50548eb..4f50e48 100644 (file)
@@ -169,6 +169,7 @@ public class PreMergeSpec extends AbstractCoreSpec {
             .tasks(
                 this.getTaskGitCloneRepository(),
                 this.getTaskGitCherryPick(),
+                this.getTaskStopDanglingContainers(),
                 this.getTaskComposerInstall(requirementIdentifier),
                 new ScriptTask()
                     .description("Execute cgl check script")