Skip to content

Commit cb01186

Browse files
committed
push also consider build.tags
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent efea084 commit cb01186

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

pkg/compose/push.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"errors"
2424
"fmt"
2525
"io"
26+
"strings"
2627

2728
"github.com/compose-spec/compose-go/types"
2829
"github.com/distribution/reference"
@@ -68,22 +69,30 @@ func (s *composeService) push(ctx context.Context, project *types.Project, optio
6869
continue
6970
}
7071
service := service
71-
eg.Go(func() error {
72-
err := s.pushServiceImage(ctx, service, info, s.configFile(), w, options.Quiet)
73-
if err != nil {
74-
if !options.IgnoreFailures {
75-
return err
72+
tags := []string{service.Image}
73+
if service.Build != nil {
74+
tags = append(tags, service.Build.Tags...)
75+
}
76+
77+
for _, tag := range tags {
78+
tag := tag
79+
eg.Go(func() error {
80+
err := s.pushServiceImage(ctx, tag, info, s.configFile(), w, options.Quiet)
81+
if err != nil {
82+
if !options.IgnoreFailures {
83+
return err
84+
}
85+
w.TailMsgf("Pushing %s: %s", service.Name, err.Error())
7686
}
77-
w.TailMsgf("Pushing %s: %s", service.Name, err.Error())
78-
}
79-
return nil
80-
})
87+
return nil
88+
})
89+
}
8190
}
8291
return eg.Wait()
8392
}
8493

85-
func (s *composeService) pushServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer, quietPush bool) error {
86-
ref, err := reference.ParseNormalizedNamed(service.Image)
94+
func (s *composeService) pushServiceImage(ctx context.Context, tag string, info moby.Info, configFile driver.Auth, w progress.Writer, quietPush bool) error {
95+
ref, err := reference.ParseNormalizedNamed(tag)
8796
if err != nil {
8897
return err
8998
}
@@ -107,7 +116,7 @@ func (s *composeService) pushServiceImage(ctx context.Context, service types.Ser
107116
return err
108117
}
109118

110-
stream, err := s.apiClient().ImagePush(ctx, service.Image, moby.ImagePushOptions{
119+
stream, err := s.apiClient().ImagePush(ctx, tag, moby.ImagePushOptions{
111120
RegistryAuth: base64.URLEncoding.EncodeToString(buf),
112121
})
113122
if err != nil {
@@ -127,9 +136,10 @@ func (s *composeService) pushServiceImage(ctx context.Context, service types.Ser
127136
}
128137

129138
if !quietPush {
130-
toPushProgressEvent(service.Name, jm, w)
139+
toPushProgressEvent(tag, jm, w)
131140
}
132141
}
142+
133143
return nil
134144
}
135145

@@ -145,7 +155,7 @@ func toPushProgressEvent(prefix string, jm jsonmessage.JSONMessage, w progress.W
145155
current int64
146156
percent int
147157
)
148-
if jm.Status == "Pushed" || jm.Status == "Already exists" {
158+
if isDone(jm) {
149159
status = progress.Done
150160
percent = 100
151161
}
@@ -174,3 +184,13 @@ func toPushProgressEvent(prefix string, jm jsonmessage.JSONMessage, w progress.W
174184
StatusText: text,
175185
})
176186
}
187+
188+
func isDone(msg jsonmessage.JSONMessage) bool {
189+
// TODO there should be a better way to detect push is done than such a status message check
190+
switch strings.ToLower(msg.Status) {
191+
case "pushed", "layer already exists":
192+
return true
193+
default:
194+
return false
195+
}
196+
}

0 commit comments

Comments
 (0)