Skip to content

Commit c1af674

Browse files
committed
Merge branch 'release/2.3.1'
2 parents 0121c7e + 5e627bc commit c1af674

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ CliTools Changelog
44
next - UPCOMING
55
------------------
66

7+
2.3.1 - 2016-02-14
8+
------------------
9+
- Switched to official docker volume cleanup
10+
- SLOC: 7,034
711

812
2.3.0 - 2016-01-26
913
------------------

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CliTools for Docker, PHP und MySQL development
22

3-
[![latest v2.3.0](https://img.shields.io/badge/latest-v2.3.0-green.svg?style=flat)](https://github.com/webdevops/clitools/releases/tag/2.3.0)
3+
[![latest v2.3.1](https://img.shields.io/badge/latest-v2.3.1-green.svg?style=flat)](https://github.com/webdevops/clitools/releases/tag/2.3.1)
44
[![License GPL3](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat)](/LICENSE)
55
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/webdevops/clitools.svg)](http://isitmaintained.com/project/webdevops/clitools "Average time to resolve an issue")
66
[![Percentage of issues still open](http://isitmaintained.com/badge/open/webdevops/clitools.svg)](http://isitmaintained.com/project/webdevops/clitools "Percentage of issues still open")

src/app/CliTools/Console/Command/Docker/CleanupCommand.php

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use CliTools\Shell\CommandBuilder\CommandBuilder;
2525
use Symfony\Component\Console\Input\InputInterface;
2626
use Symfony\Component\Console\Output\OutputInterface;
27+
use Symfony\Component\Console\Input\InputOption;
2728

2829
class CleanupCommand extends AbstractCommand
2930
{
@@ -34,7 +35,13 @@ class CleanupCommand extends AbstractCommand
3435
protected function configure()
3536
{
3637
$this->setName('docker:cleanup')
37-
->setDescription('Cleanup docker environment');
38+
->setDescription('Cleanup docker environment')
39+
->addOption(
40+
'force',
41+
'f',
42+
InputOption::VALUE_NONE,
43+
'Force deletion'
44+
);
3845
}
3946

4047
/**
@@ -59,8 +66,23 @@ protected function cleanDockerImages()
5966
{
6067
$this->output->writeln('<h2>Cleanup orphaned docker images</h2>');
6168
try {
62-
$command = new CommandBuilder('docker', 'rmi $(docker images -qf "dangling=true")');
63-
$command->executeInteractive();
69+
$command = new CommandBuilder('docker', 'images -qf "dangling=true"');
70+
$imageList = $command->execute()->getOutput();
71+
72+
if (!empty($volumeList)) {
73+
$this->output->writeln('<p>Found ' . number_format(count($imageList)) . ' images for cleanup</p>');
74+
75+
while (!empty($imageList)) {
76+
$command = new CommandBuilder('docker', 'rmi');
77+
if ($this->input->getOption('force')) {
78+
$command->addArgument('--force');
79+
}
80+
$command->addArgumentList(array_splice($imageList, 0, 50));
81+
$command->executeInteractive();
82+
}
83+
} else {
84+
$this->output->writeln('<p>No images for cleanup found</p>');
85+
}
6486

6587
} catch (\Exception $e) {
6688
$this->output->writeln('<comment>Some images could not be removed (this is normal)</comment>');
@@ -75,14 +97,28 @@ protected function cleanDockerImages()
7597
protected function cleanDockerVolumes()
7698
{
7799
$this->output->writeln('<h2>Cleanup orphaned docker volumes</h2>');
78-
$this->output->writeln('<info>Updating docker image "martin/docker-cleanup-volumes"</info>');
79100

80-
$command = new CommandBuilder('docker', 'pull martin/docker-cleanup-volumes');
81-
$command->executeInteractive();
101+
try {
102+
$command = new CommandBuilder('docker', 'volume ls -qf "dangling=true"');
103+
$volumeList = $command->execute()->getOutput();
104+
105+
if (!empty($volumeList)) {
106+
$this->output->writeln('<p>Found ' . number_format(count($volumeList)) . ' volumes for cleanup</p>');
82107

83-
$this->output->writeln('<info>Run docker image "martin/docker-cleanup-volumes"</info>');
84-
$command = new CommandBuilder('docker', 'run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes');
85-
$command->executeInteractive();
108+
while (!empty($volumeList)) {
109+
$command = new CommandBuilder('docker', 'volume rm');
110+
if ($this->input->getOption('force')) {
111+
$command->addArgument('--force');
112+
}
113+
$command->addArgumentList(array_splice($volumeList, 0, 50));
114+
$command->executeInteractive();
115+
}
116+
} else {
117+
$this->output->writeln('<p>No volumes for cleanup found</p>');
118+
}
119+
} catch (\Exception $e) {
120+
$this->output->writeln('<comment>Some volumes could not be removed (this is normal)</comment>');
121+
}
86122

87123
$this->output->writeln('');
88124
}

src/command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
error_reporting(E_ALL);
24-
define('CLITOOLS_COMMAND_VERSION', '2.3.0');
24+
define('CLITOOLS_COMMAND_VERSION', '2.3.1');
2525
define('CLITOOLS_ROOT_FS', __DIR__);
2626

2727
require __DIR__ . '/vendor/autoload.php';

0 commit comments

Comments
 (0)