Skip to content

Commit

Permalink
Use docker stop instead of docker kill
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Apr 13, 2023
1 parent f3d72f2 commit 8176602
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ class DockerBuilder extends ContainerBuilder<DockerBuilder> {
}

if( kill ) {
killCommand = 'docker kill '
killCommand = 'docker stop '
// if `kill` is a string it is interpreted as a the kill signal
if( kill instanceof String ) killCommand += "-s $kill "
if( kill instanceof String ) killCommand = "docker kill -s $kill "
killCommand += name
// prefix with sudo if required
if( sudo ) killCommand = 'sudo ' + killCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ class PodmanBuilder extends ContainerBuilder<PodmanBuilder> {
}

if( kill ) {
killCommand = 'podman kill '
killCommand = 'podman stop '
// if `kill` is a string it is interpreted as a the kill signal
if( kill instanceof String ) killCommand += "-s $kill "
if( kill instanceof String ) killCommand = "podman kill -s $kill "
killCommand += name
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,22 @@ class DockerBuilderTest extends Specification {
then:
docker.runCommand == 'docker run -i -v "$PWD":"$PWD" -w "$PWD" --name c1 busybox'
docker.removeCommand == 'docker rm c1'
docker.killCommand == 'docker kill c1'
docker.killCommand == 'docker stop c1'

when:
docker = new DockerBuilder('busybox').setName('c2').params(sudo: true, remove: true).build()
then:
docker.runCommand == 'sudo docker run -i -v "$PWD":"$PWD" -w "$PWD" --name c2 busybox'
docker.removeCommand == 'sudo docker rm c2'
docker.killCommand == 'sudo docker kill c2'
docker.killCommand == 'sudo docker stop c2'


when:
docker = new DockerBuilder('busybox').setName('c3').params(remove: true).build()
then:
docker.runCommand == 'docker run -i -v "$PWD":"$PWD" -w "$PWD" --name c3 busybox'
docker.removeCommand == 'docker rm c3'
docker.killCommand == 'docker kill c3'
docker.killCommand == 'docker stop c3'

when:
docker = new DockerBuilder('busybox').setName('c4').params(kill: 'SIGKILL').build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ class PodmanBuilderTest extends Specification {
then:
podman.runCommand == 'podman run -i -v "$PWD":"$PWD" -w "$PWD" --name c1 busybox'
podman.removeCommand == 'podman rm c1'
podman.killCommand == 'podman kill c1'
podman.killCommand == 'podman stop c1'

when:
podman = new PodmanBuilder('busybox').setName('c3').params(remove: true).build()
then:
podman.runCommand == 'podman run -i -v "$PWD":"$PWD" -w "$PWD" --name c3 busybox'
podman.removeCommand == 'podman rm c3'
podman.killCommand == 'podman kill c3'
podman.killCommand == 'podman stop c3'

when:
podman = new PodmanBuilder('busybox').setName('c4').params(kill: 'SIGKILL').build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'docker run -i -v $(nxf_mktemp):/tmp -v /work/dir:/work/dir -w "$PWD" --name $NXF_BOXID busybox /bin/bash -ue /work/dir/.command.sh'
binding.cleanup_cmd == 'docker rm $NXF_BOXID &>/dev/null || true\n'
binding.kill_cmd == 'docker kill $NXF_BOXID'
binding.kill_cmd == 'docker stop $NXF_BOXID'
}

def 'should create wrapper with docker and environment' () {
Expand All @@ -693,7 +693,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'docker run -i -v $(nxf_mktemp):/tmp -v /work/dir:/work/dir -w "$PWD" --name $NXF_BOXID busybox /bin/bash -c "eval $(nxf_container_env); /bin/bash -ue /work/dir/.command.sh"'
binding.cleanup_cmd == 'docker rm $NXF_BOXID &>/dev/null || true\n'
binding.kill_cmd == 'docker kill $NXF_BOXID'
binding.kill_cmd == 'docker stop $NXF_BOXID'
and:
binding.container_env == '''\
nxf_container_env() {
Expand All @@ -714,7 +714,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'docker run -i -v $(nxf_mktemp):/tmp -v /work/dir:/work/dir -w "$PWD" --name $NXF_BOXID busybox /bin/bash -ue /work/dir/.command.sh'
binding.cleanup_cmd == 'docker rm $NXF_BOXID &>/dev/null || true\n'
binding.kill_cmd == 'docker kill $NXF_BOXID'
binding.kill_cmd == 'docker stop $NXF_BOXID'
}

def 'should create wrapper with docker and legacy entrypoint false and env' () {
Expand All @@ -728,7 +728,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'docker run -i -v $(nxf_mktemp):/tmp -v /work/dir:/work/dir -w "$PWD" --name $NXF_BOXID busybox /bin/bash -c "eval $(nxf_container_env); /bin/bash -ue /work/dir/.command.sh"'
binding.cleanup_cmd == 'docker rm $NXF_BOXID &>/dev/null || true\n'
binding.kill_cmd == 'docker kill $NXF_BOXID'
binding.kill_cmd == 'docker stop $NXF_BOXID'
and:
binding.container_env == '''\
nxf_container_env() {
Expand All @@ -749,7 +749,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'sudo docker run -i -v /work/dir:/work/dir -w "$PWD" --name $NXF_BOXID busybox /bin/bash -ue /work/dir/.command.sh'
binding.cleanup_cmd == 'sudo docker rm $NXF_BOXID &>/dev/null || true\n'
binding.kill_cmd == 'sudo docker kill $NXF_BOXID'
binding.kill_cmd == 'sudo docker stop $NXF_BOXID'
}

def 'should create wrapper with docker no kill' () {
Expand All @@ -776,7 +776,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'docker run -i -v /work/dir:/work/dir -w "$PWD" --name $NXF_BOXID ubuntu /bin/bash -ue /work/dir/.command.sh'
binding.cleanup_cmd == ""
binding.kill_cmd == 'docker kill -s SIGXXX $NXF_BOXID'
binding.kill_cmd == 'docker stop -s SIGXXX $NXF_BOXID'
binding.containsKey('kill_cmd')
}

Expand All @@ -791,7 +791,7 @@ class BashWrapperBuilderTest extends Specification {
then:
binding.launch_cmd == 'docker run -i -v /folder\\ with\\ blanks:/folder\\ with\\ blanks -v /work/dir:/work/dir -w "\$PWD" --name \$NXF_BOXID busybox /bin/bash -ue /work/dir/.command.sh'
binding.cleanup_cmd == 'docker rm $NXF_BOXID &>/dev/null || true\n'
binding.kill_cmd == 'docker kill $NXF_BOXID'
binding.kill_cmd == 'docker stop $NXF_BOXID'
}

def 'should create wrapper with docker with scratch' () {
Expand All @@ -805,7 +805,7 @@ class BashWrapperBuilderTest extends Specification {

then:
binding.launch_cmd == 'sudo docker run -i -v /work/dir:/work/dir -v "$PWD":"$PWD" -w "$PWD" --name $NXF_BOXID busybox /bin/bash -ue /work/dir/.command.sh'
binding.kill_cmd == 'sudo docker kill $NXF_BOXID'
binding.kill_cmd == 'sudo docker stop $NXF_BOXID'
binding.cleanup_cmd == '''\
(sudo -n true && sudo rm -rf "$NXF_SCRATCH" || rm -rf "$NXF_SCRATCH")&>/dev/null || true
sudo docker rm $NXF_BOXID &>/dev/null || true
Expand All @@ -822,7 +822,7 @@ class BashWrapperBuilderTest extends Specification {

then:
binding.launch_cmd == 'docker run -i -v /work/dir:/work/dir -w "$PWD" -v /foo:/bar --name $NXF_BOXID busybox /bin/bash -ue /work/dir/.command.sh'
binding.kill_cmd == 'docker kill $NXF_BOXID'
binding.kill_cmd == 'docker stop $NXF_BOXID'
binding.cleanup_cmd == 'docker rm $NXF_BOXID &>/dev/null || true\n'
}

Expand Down

0 comments on commit 8176602

Please sign in to comment.