-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker
90 lines (90 loc) · 3.73 KB
/
docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
PATH="$PATH:/usr/local/bin"
MACHINE="$1"
MACHINES=$(docker-machine ls -q | grep "$MACHINE")
MACHINE_STATUS=$(docker-machine status "$MACHINE" 2> /dev/null)
VALID_MACHINE=$?
echo "<?xml version='1.0'?><items>"
if [ "$VALID_MACHINE" = "0" ]
then
if [ "$MACHINE_STATUS" = "Running" ]
then
echo "<item arg=\"machine stop '$MACHINE'\" uid=\"$MACHINE\">"
echo " <title>Shut Down Machine $MACHINE</title>"
echo " <subtitle>Will shut down all containers on $MACHINE</subtitle>"
echo "</item>"
echo "<item arg=\"machine ip '$MACHINE'\" uid=\"$MACHINE-ip\">"
echo " <title>Copy Machine IP $MACHINE</title>"
echo " <subtitle>Copy '$(docker-machine ip $MACHINE)' to clipboard</subtitle>"
echo "</item>"
echo "<item arg=\"container remove '$MACHINE'\" uid=\"$MACHINE-ip\">"
echo " <title>Remove all containers only $MACHINE</title>"
echo " <subtitle>Will remove all containers on $MACHINE</subtitle>"
echo "</item>"
echo "<item arg=\"container prune '$MACHINE'\" uid=\"$MACHINE-ip\">"
echo " <title>Remove all Images, Containers, Volumes $MACHINE</title>"
echo " <subtitle>Remove all Images, Containers, Volumes $MACHINE</subtitle>"
echo "</item>"
ENV=$(docker-machine env --shell sh "$MACHINE")
eval "$ENV"
IMAGES="$(docker images --format "{{.Repository}} {{.Tag}} |{{.ID}} ")"
if [ "$IMAGES" != "" ]
then
while read -r IMAGE
do
IMAGE_ID=$(echo "$IMAGE" | sed 's/.*|//')
IMAGE_NAME=$(echo "$IMAGE" | sed 's/|.*//')
echo "<item arg=\"docker image '$MACHINE'\" uid=\"$MACHINE-ip\">"
echo " <title>Docker image $IMAGE_NAME</title>"
echo "</item>"
done <<< "$IMAGES"
fi
ENV=$(docker-machine env --shell sh "$MACHINE")
eval "$ENV"
RUNNING_CONTAINERS="$(docker ps --format "{{.Names}} ({{.Image}})|Running for: {{.RunningFor}}|{{.ID}}")"
if [ "$RUNNING_CONTAINERS" != "" ]
then
while read -r CONTAINER
do
CONTAINER_ID=$(echo "$CONTAINER" | sed 's/.*|//')
CONTAINER_NAME=$(echo "$CONTAINER" | sed 's/|.*//')
CONTAINER_SUBTITLE=$(echo "$CONTAINER" | sed 's/.*|\(.*\)|.*/\1/')
echo "<item arg=\"container stop '$MACHINE' '$CONTAINER_ID'\">"
echo " <title>Shut down $CONTAINER_NAME</title>"
echo " <subtitle>$CONTAINER_SUBTITLE</subtitle>"
echo "</item>"
done <<< "$RUNNING_CONTAINERS"
fi
EXITED_CONTAINERS="$(docker ps -a --filter "status=exited" --format "{{.Names}} ({{.Image}})|{{.ID}}")"
if [ "$EXITED_CONTAINERS" != "" ]
then
while read -r CONTAINER
do
CONTAINER_ID=$(echo "$CONTAINER" | sed 's/.*|//')
CONTAINER_NAME=$(echo "$CONTAINER" | sed 's/|.*//')
CONTAINER_SUBTITLE=$(echo "$CONTAINER" | sed 's/.*|\(.*\)|.*/\1/')
echo "<item arg=\"container start '$MACHINE' '$CONTAINER_ID'\">"
echo " <title>Start $CONTAINER_NAME</title>"
echo " <subtitle>$CONTAINER_SUBTITLE</subtitle>"
echo "</item>"
done <<< "$EXITED_CONTAINERS"
fi
else
echo "<item arg=\"machine start '$MACHINE'\" uid=\"$MACHINE\">"
echo " <title>Boot Docker Machine $MACHINE</title>"
echo "</item>"
fi
else
while read -r MACHINE
do
MACHINE_VERSION=$(docker-machine version $MACHINE)
MACHINE_STATUS=$(docker-machine status $MACHINE)
MACHINE_IP=$(docker-machine ip $MACHINE)
MACHINE_DRIVER=$(docker-machine inspect $MACHINE | sed -n 's/.*"DriverName": "\(.*\)",/\1/p')
echo "<item arg=\"$MACHINE\" uid=\"$MACHINE\" valid=\"no\" autocomplete=\"$MACHINE\">"
echo " <title>$MACHINE</title>"
echo " <subtitle>$MACHINE_STATUS (Docker $MACHINE_VERSION on $MACHINE_DRIVER), $MACHINE_IP</subtitle>"
echo "</item>"
done <<< "$MACHINES"
fi
echo "</items>"