Set a kaniko user agent. (#262)
This commit is contained in:
parent
cac00b9cb2
commit
e43968f02f
|
|
@ -42,6 +42,7 @@ import (
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
|
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/snapshot"
|
"github.com/GoogleContainerTools/kaniko/pkg/snapshot"
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
"github.com/GoogleContainerTools/kaniko/pkg/util"
|
||||||
|
"github.com/GoogleContainerTools/kaniko/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KanikoBuildArgs contains all the args required to build the image
|
// KanikoBuildArgs contains all the args required to build the image
|
||||||
|
|
@ -181,7 +182,17 @@ func DoBuild(k KanikoBuildArgs) (v1.Image, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type withUserAgent struct {
|
||||||
|
t http.RoundTripper
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
|
r.Header.Set("User-Agent", fmt.Sprintf("kaniko/%s", version.Version()))
|
||||||
|
return w.t.RoundTrip(r)
|
||||||
|
}
|
||||||
|
|
||||||
func DoPush(image v1.Image, destinations []string, tarPath string) error {
|
func DoPush(image v1.Image, destinations []string, tarPath string) error {
|
||||||
|
|
||||||
// continue pushing unless an error occurs
|
// continue pushing unless an error occurs
|
||||||
for _, destination := range destinations {
|
for _, destination := range destinations {
|
||||||
// Push the image
|
// Push the image
|
||||||
|
|
@ -204,7 +215,10 @@ func DoPush(image v1.Image, destinations []string, tarPath string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := remote.Write(destRef, image, pushAuth, http.DefaultTransport, remote.WriteOptions{}); err != nil {
|
// Create a transport to set our user-agent.
|
||||||
|
rt := &withUserAgent{t: http.DefaultTransport}
|
||||||
|
|
||||||
|
if err := remote.Write(destRef, image, pushAuth, rt, remote.WriteOptions{}); err != nil {
|
||||||
logrus.Error(fmt.Errorf("Failed to push to destination %s", destination))
|
logrus.Error(fmt.Errorf("Failed to push to destination %s", destination))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue