Skip to content

Commit

Permalink
Set Pipeline Version during build
Browse files Browse the repository at this point in the history
Fixes tektoncd#1543
Introduces variable for storing the pipeline version
  • Loading branch information
waveywaves committed Dec 3, 2019
1 parent de4fe10 commit ea063f8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
20 changes: 20 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright © 2019 The Tekton Authors.
//
// 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

// NOTE: use go build -ldflags "-X github.com/tektoncd/pipeline/pkg/cmd/version.PipelineVersion=$(git describe)"
const devVersion = "dev"

var PipelineVersion = devVersion
50 changes: 29 additions & 21 deletions tekton/publish-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,6 @@ spec:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /secret/release.json

- name: create-ko-yaml
image: busybox
command:
- /bin/sh
args:
- -ce
- |
set -e
set -x
cat <<EOF > /workspace/go/src/github.com/tektoncd/pipeline/.ko.yaml
# By default ko will build images on top of distroless
baseImageOverrides:
# Use the images we just built as base images
${inputs.params.pathToProject}/${outputs.resources.builtCredsInitImage.url}: ${inputs.params.imageRegistry}/${inputs.params.pathToProject}/build-base:latest
${inputs.params.pathToProject}/${outputs.resources.builtGitInitImage.url}: ${inputs.params.imageRegistry}/${inputs.params.pathToProject}/build-base:latest
${inputs.params.pathToProject}/${outputs.resources.builtEntrypointImage.url}: busybox # image should have shell in $PATH
EOF
cat /workspace/go/src/github.com/tektoncd/pipeline/.ko.yaml
- name: ensure-release-dirs-exist
image: busybox
command: ["mkdir"]
Expand Down Expand Up @@ -107,6 +86,35 @@ spec:
echo $VERSION_TAG > "/builder/home/version"
- name: create-ko-yaml
image: busybox
command:
- /bin/sh
args:
- -ce
- |
set -e
set -x
cat <<EOF > /workspace/go/src/github.com/tektoncd/pipeline/.ko.yaml
# By default ko will build images on top of distroless
baseImageOverrides:
# Use the images we just built as base images
${inputs.params.pathToProject}/${outputs.resources.builtCredsInitImage.url}: ${inputs.params.imageRegistry}/${inputs.params.pathToProject}/build-base:latest
${inputs.params.pathToProject}/${outputs.resources.builtGitInitImage.url}: ${inputs.params.imageRegistry}/${inputs.params.pathToProject}/build-base:latest
${inputs.params.pathToProject}/${outputs.resources.builtEntrypointImage.url}: busybox # image should have shell in $PATH
baseBuildOverrides:
$(input.params.pathToProject)/$(outputs.resources.builtControllerImage.url):
env:
- name: CGO_ENABLED
value: 1
flags:
- name: ldflags
value: "-X $(inputs.params.pathToProject)/pkg/version.PipelineVersion=$(cat /builder/home/version)"
EOF
cat /workspace/go/src/github.com/tektoncd/pipeline/.ko.yaml
- name: run-ko
# TODO(#639) we should be able to use the image built by an upstream Task here instead of hardcoding
image: gcr.io/tekton-nightly/ko-ci
Expand Down
8 changes: 8 additions & 0 deletions tekton/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ spec:
$(inputs.params.pathToProject)/$(outputs.resources.builtCredsInitImage.url): $(inputs.params.imageRegistry)/$(inputs.params.pathToProject)/build-base:latest
$(inputs.params.pathToProject)/$(outputs.resources.builtGitInitImage.url): $(inputs.params.imageRegistry)/$(inputs.params.pathToProject)/build-base:latest
$(inputs.params.pathToProject)/$(outputs.resources.builtEntrypointImage.url): busybox # image should have shell in $PATH
baseBuildOverrides:
$(input.params.pathToProject)/$(outputs.resources.builtControllerImage.url):
env:
- name: CGO_ENABLED
value: 1
flags:
- name: ldflags
value: "-X $(inputs.params.pathToProject)/pkg/version.PipelineVersion=$(inputs.params.versionTag)"
EOF
cat /workspace/go/src/github.com/tektoncd/pipeline/.ko.yaml
Expand Down
2 changes: 2 additions & 0 deletions tekton/release-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ spec:
params:
- name: package
value: $(params.package)
- name: flags
value: -ldflags "-X github.com/tektoncd/pipeline/pkg/version.PipelineVersion=$(params.versionTag)"
resources:
inputs:
- name: source
Expand Down

0 comments on commit ea063f8

Please sign in to comment.