Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from rewe-digital-incubator/fix-frostComposeKil…
Browse files Browse the repository at this point in the history
…l-with-projectnames

Fix issues with killing/removing of containers when projectName is sp…
  • Loading branch information
stefanneuhaus authored Jan 2, 2019
2 parents 4d07306 + b9680b8 commit fca53bc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
}

group = 'org.rewedigital'
version = '0.5'
version = '0.5.1'

gradlePlugin {
plugins {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.rewedigital.frost.tasks


import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.TaskAction
import org.rewedigital.frost.util.Util

import static org.rewedigital.frost.FrostPluginExtension.EXTENSION_NAME

abstract class DockerComposeTask extends DefaultTask {

static final EXECUTABLE = "docker-compose"
Expand All @@ -24,4 +25,25 @@ abstract class DockerComposeTask extends DefaultTask {

@TaskAction
def abstract action()


List<String> dockerComposeCommand(String command) {
def envString = environment().inject([]) { result, entry -> result << "${entry.key}=${entry.value}" }.join(" ")

def cmd = ["/bin/sh"]
cmd << "-c"
cmd << "export ${envString} && ${EXECUTABLE} -f ${getComposeFile()} -f ${getComposeOverrideFile()} ${command}"
cmd
}

Map<String, String> environment() {
def env = [
TAG: project.extensions[EXTENSION_NAME].sutTag
]

if (project.extensions[EXTENSION_NAME].projectName) {
env << [COMPOSE_PROJECT_NAME: project.extensions[EXTENSION_NAME].projectName]
}
env
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,10 @@ class FrostComposeKillTask extends DockerComposeTask {
@Override
def action() {
try {
def cmd = [EXECUTABLE]
cmd << "-f"
cmd << getComposeFile()
cmd << "-f"
cmd << getComposeOverrideFile()
cmd << "kill"
def cmd = dockerComposeCommand("kill")
Util.executeSynchronously(cmd, "docker_compose_kill", getReportDirectory())

cmd = [EXECUTABLE]
cmd << "-f"
cmd << getComposeFile()
cmd << "-f"
cmd << getComposeOverrideFile()
cmd << "rm"
cmd << "-f"
cmd << "-v"
cmd = dockerComposeCommand("rm -f -v")
Util.executeSynchronously(cmd, "docker_compose_rm", getReportDirectory())
} finally {
getComposeOverrideFile().delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.rewedigital.frost.util.Util

import static org.rewedigital.frost.FrostPluginExtension.EXTENSION_NAME

class FrostComposePullTask extends DockerComposeTask {

@OutputDirectory
Expand All @@ -16,10 +14,7 @@ class FrostComposePullTask extends DockerComposeTask {
@TaskAction
@Override
def action() {
def cmd = ["/bin/sh"]
cmd << "-c"
cmd << "export TAG=${project.extensions[EXTENSION_NAME].sutTag} && ${EXECUTABLE} -f ${getComposeFile()} -f ${getComposeOverrideFile()} pull --ignore-pull-failures"

def cmd = dockerComposeCommand("pull --ignore-pull-failures")
Util.executeSynchronously(cmd, "docker_compose_pull", getReportDirectory())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.rewedigital.frost.util.Util

import static org.rewedigital.frost.FrostPluginExtension.EXTENSION_NAME

class FrostComposeUpTask extends DockerComposeTask {

@OutputDirectory
Expand All @@ -16,20 +14,7 @@ class FrostComposeUpTask extends DockerComposeTask {
@TaskAction
@Override
def action() {
def env = [
TAG: project.extensions[EXTENSION_NAME].sutTag
]

if (project.extensions[EXTENSION_NAME].projectName) {
env << [COMPOSE_PROJECT_NAME: project.extensions[EXTENSION_NAME].projectName]
}

def envString = env.inject([]) { result, entry -> result << "${entry.key}=${entry.value}" }.join(" ")

def cmd = ["/bin/sh"]
cmd << "-c"
cmd << "export ${envString} && ${EXECUTABLE} -f ${getComposeFile()} -f ${getComposeOverrideFile()} up"

def cmd = dockerComposeCommand("up")
Util.executeAsynchronously(cmd, "docker_compose_up", getReportDirectory())
}
}

0 comments on commit fca53bc

Please sign in to comment.