Browse code

Suppressing digest for docker service ls/ps

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
(cherry picked from commit e7d83fdb9a17c384397e81d7b5a83245b4216f79)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Nishant Totla authored on 2016/11/17 15:21:18
Showing 2 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"io"
6 6
 	"text/tabwriter"
7 7
 
8
+	distreference "github.com/docker/distribution/reference"
8 9
 	"github.com/docker/docker/api/types"
9 10
 	"github.com/docker/docker/api/types/filters"
10 11
 	"github.com/docker/docker/api/types/swarm"
... ...
@@ -127,6 +128,16 @@ func printTable(out io.Writer, services []swarm.Service, running, tasksNoShutdow
127 127
 			mode = "global"
128 128
 			replicas = fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID])
129 129
 		}
130
+		image := service.Spec.TaskTemplate.ContainerSpec.Image
131
+		ref, err := distreference.ParseNamed(image)
132
+		if err == nil {
133
+			// update image string for display
134
+			namedTagged, ok := ref.(distreference.NamedTagged)
135
+			if ok {
136
+				image = namedTagged.Name() + ":" + namedTagged.Tag()
137
+			}
138
+		}
139
+
130 140
 		fmt.Fprintf(
131 141
 			writer,
132 142
 			listItemFmt,
... ...
@@ -134,7 +145,7 @@ func printTable(out io.Writer, services []swarm.Service, running, tasksNoShutdow
134 134
 			service.Spec.Name,
135 135
 			mode,
136 136
 			replicas,
137
-			service.Spec.TaskTemplate.ContainerSpec.Image)
137
+			image)
138 138
 	}
139 139
 }
140 140
 
... ...
@@ -10,6 +10,7 @@ import (
10 10
 
11 11
 	"golang.org/x/net/context"
12 12
 
13
+	distreference "github.com/docker/distribution/reference"
13 14
 	"github.com/docker/docker/api/types/swarm"
14 15
 	"github.com/docker/docker/cli/command"
15 16
 	"github.com/docker/docker/cli/command/idresolver"
... ...
@@ -118,11 +119,23 @@ func print(out io.Writer, ctx context.Context, tasks []swarm.Task, resolver *idr
118 118
 			taskErr = fmt.Sprintf("\"%s\"", taskErr)
119 119
 		}
120 120
 
121
+		image := task.Spec.ContainerSpec.Image
122
+		if !noTrunc {
123
+			ref, err := distreference.ParseNamed(image)
124
+			if err == nil {
125
+				// update image string for display
126
+				namedTagged, ok := ref.(distreference.NamedTagged)
127
+				if ok {
128
+					image = namedTagged.Name() + ":" + namedTagged.Tag()
129
+				}
130
+			}
131
+		}
132
+
121 133
 		fmt.Fprintf(
122 134
 			out,
123 135
 			psTaskItemFmt,
124 136
 			indentedName,
125
-			task.Spec.ContainerSpec.Image,
137
+			image,
126 138
 			nodeValue,
127 139
 			command.PrettyPrint(task.DesiredState),
128 140
 			command.PrettyPrint(task.Status.State),