Set a user-agent for registry pushes. (#87)

This commit is contained in:
dlorenc 2018-04-13 14:25:58 -07:00 committed by GitHub
parent b4c8029d60
commit da1eab7251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 4 deletions

View File

@ -18,6 +18,7 @@ VERSION_MINOR ?= 1
VERSION_BUILD ?= 0 VERSION_BUILD ?= 0
VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD) VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD)
VERSION_PACKAGE = $(REPOPATH/pkg/version)
GOOS ?= $(shell go env GOOS) GOOS ?= $(shell go env GOOS)
GOARCH = amd64 GOARCH = amd64
@ -28,7 +29,10 @@ REGISTRY?=gcr.io/kaniko-project
REPOPATH ?= $(ORG)/$(PROJECT) REPOPATH ?= $(ORG)/$(PROJECT)
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*") GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GO_LDFLAGS := '-extldflags "-static"' GO_LDFLAGS := '-extldflags "-static"
GO_LDFLAGS += -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += '
GO_BUILD_TAGS := "containers_image_ostree_stub containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs exclude_graphdriver_overlay" GO_BUILD_TAGS := "containers_image_ostree_stub containers_image_openpgp exclude_graphdriver_devicemapper exclude_graphdriver_btrfs exclude_graphdriver_overlay"
EXECUTOR_PACKAGE = $(REPOPATH)/executor EXECUTOR_PACKAGE = $(REPOPATH)/executor

View File

@ -18,11 +18,12 @@ package commands
import ( import (
"fmt" "fmt"
"strings"
"github.com/GoogleCloudPlatform/kaniko/pkg/util" "github.com/GoogleCloudPlatform/kaniko/pkg/util"
"github.com/containers/image/manifest" "github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions" "github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"strings"
) )
type ExposeCommand struct { type ExposeCommand struct {

View File

@ -17,6 +17,12 @@ limitations under the License.
package image package image
import ( import (
"fmt"
"os"
"github.com/GoogleCloudPlatform/kaniko/pkg/version"
"github.com/containers/image/types"
img "github.com/GoogleCloudPlatform/container-diff/pkg/image" img "github.com/GoogleCloudPlatform/container-diff/pkg/image"
"github.com/GoogleCloudPlatform/kaniko/pkg/constants" "github.com/GoogleCloudPlatform/kaniko/pkg/constants"
"github.com/containers/image/copy" "github.com/containers/image/copy"
@ -24,7 +30,6 @@ import (
"github.com/containers/image/signature" "github.com/containers/image/signature"
"github.com/containers/image/transports/alltransports" "github.com/containers/image/transports/alltransports"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"os"
) )
// sourceImage is the image that will be modified by the executor // sourceImage is the image that will be modified by the executor
@ -57,7 +62,13 @@ func PushImage(ms *img.MutableSource, destImg string) error {
return err return err
} }
logrus.Infof("Pushing image to %s", destImg) logrus.Infof("Pushing image to %s", destImg)
return copy.Image(policyContext, destRef, srcRef, nil)
opts := &copy.Options{
DestinationCtx: &types.SystemContext{
DockerRegistryUserAgent: fmt.Sprintf("kaniko/executor-%s", version.Version()),
},
}
return copy.Image(policyContext, destRef, srcRef, opts)
} }
// SetEnvVariables sets environment variables as specified in the image // SetEnvVariables sets environment variables as specified in the image

24
pkg/version/version.go Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package version
// Set with LDFLAGS
var version = "unset"
func Version() string {
return version
}