[Tizen] Add BuildTools 2.1.0-rc1-02804-05
[platform/upstream/coreclr.git] / packages / microsoft.dotnet.buildtools / 2.1.0-rc1-02804-05 / lib / scripts / docker / cleanup-docker.sh
1 #!/usr/bin/perl
2
3 #
4 # ./cleanup-docker.sh
5 #
6
7 printf "Cleaning up containers\n";
8 printf "----------------------\n";
9 my $psList = `docker ps -a`;
10 my @psItems = split /\n/, $psList;
11 foreach(@psItems) {
12   # match 'docker ps' output to capture the container name
13   if($_ =~ /.*\s+([^\s]+)$/ig) {
14     my $containerName = $1;
15     if($containerName !~ /NAME/ig) {
16       printf "delete $containerName\n";
17       my $deleteOutput = `docker rm -f $1`;
18       print "$deleteOutput\n";
19     }
20   }
21 }
22
23 printf "Cleaning up volumes\n";
24 printf "-------------------\n";
25 my $volumeList = `docker volume ls`;
26 @volumeItems = split /\n/, $volumeList;
27 foreach(@volumeItems) {
28   # match 'docker volume ls' output to capture the volume name
29   if($_ =~ /([^\s]+)\s+([^\s]+)$/ig) {
30     my $volumeName = $2;
31     if($volumeName !~ /NAME/ig) {
32       printf "delete $volumeName\n";
33       my $deleteVolumeOutput = `docker volume rm -f $volumeName`;
34       printf "$deleteVolumeOutput\n";
35     }
36   }
37 }
38
39 printf "Cleaning up images\n";
40 printf "------------------\n";
41 my $imageList = `docker images`;
42 @imageItems = split /\n/, $imageList;
43 foreach(@imageItems) {
44   # match 'docker images' output to capture the image id
45   if($_ =~ /([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+.*/ig) {
46     my $imageId = $3;
47     if($imageId !~ /IMAGE/ig) {
48       my $imageRepo = $1;
49       my $imageTag = $2;
50       printf "delete $imageId ($imageRepo:$imageTag)\n";
51       my $deleteImageOutput = `docker rmi -f $imageId`;
52       printf "$deleteImageOutput\n";
53     }
54   }
55 }