diff --git a/Makefile b/Makefile index a44551147..193dffeeb 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ VERSION_MINOR ?= 1 VERSION_BUILD ?= 0 VERSION ?= v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_BUILD) +VERSION_PACKAGE = $(REPOPATH/pkg/version) GOOS ?= $(shell go env GOOS) GOARCH = amd64 @@ -28,7 +29,10 @@ REGISTRY?=gcr.io/kaniko-project REPOPATH ?= $(ORG)/$(PROJECT) 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" EXECUTOR_PACKAGE = $(REPOPATH)/executor diff --git a/pkg/commands/expose.go b/pkg/commands/expose.go index 1778e6cc8..2caecb44c 100644 --- a/pkg/commands/expose.go +++ b/pkg/commands/expose.go @@ -18,11 +18,12 @@ package commands import ( "fmt" + "strings" + "github.com/GoogleCloudPlatform/kaniko/pkg/util" "github.com/containers/image/manifest" "github.com/docker/docker/builder/dockerfile/instructions" "github.com/sirupsen/logrus" - "strings" ) type ExposeCommand struct { diff --git a/pkg/image/image.go b/pkg/image/image.go index 672cc802c..68b81c878 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -17,6 +17,12 @@ limitations under the License. package image import ( + "fmt" + "os" + + "github.com/GoogleCloudPlatform/kaniko/pkg/version" + "github.com/containers/image/types" + img "github.com/GoogleCloudPlatform/container-diff/pkg/image" "github.com/GoogleCloudPlatform/kaniko/pkg/constants" "github.com/containers/image/copy" @@ -24,7 +30,6 @@ import ( "github.com/containers/image/signature" "github.com/containers/image/transports/alltransports" "github.com/sirupsen/logrus" - "os" ) // 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 } logrus.Infof("Pushing image to %s", destImg) - return copy.Image(policyContext, destRef, srcRef, nil) + + opts := ©.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 diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 000000000..8d388d5b8 --- /dev/null +++ b/pkg/version/version.go @@ -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 +}