Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup some CI build logic and add k8s-ci-builder image #1700

Merged
merged 6 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions cmd/krel/cmd/ci_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ func init() {
"Do not update the latest file",
)

ciBuildCmd.PersistentFlags().BoolVar(
&ciBuildOpts.PrivateBucket,
"private-bucket",
false,
"Do not mark published bits on GCS as publicly readable",
)

// TODO: Configure a default const here
ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.Bucket,
Expand All @@ -116,17 +109,18 @@ func init() {
),
)

// TODO: Switch to "--registry" once CI no longer uses it
ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.DockerRegistry,
"docker-registry",
"",
"If set, push docker images to specified registry/project",
)

ciBuildCmd.PersistentFlags().StringVar(
ciBuildCmd.PersistentFlags().StringSliceVar(
&ciBuildOpts.ExtraVersionMarkers,
"extra-version-markers",
"",
build.DefaultExtraVersionMarkers,
"Comma separated list which can be used to upload additional version files to GCS. The path is relative and is append to a GCS path. (--ci only)",
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/krel/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,18 @@ func init() {
),
)

// TODO: Switch to "--registry" once CI no longer uses it
pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.DockerRegistry,
"docker-registry",
"",
"If set, push docker images to specified registry/project",
)

pushBuildCmd.PersistentFlags().StringVar(
pushBuildCmd.PersistentFlags().StringSliceVar(
&pushBuildOpts.ExtraVersionMarkers,
"extra-version-markers",
"",
build.DefaultExtraVersionMarkers,
"Comma separated list which can be used to upload additional version files to GCS. The path is relative and is append to a GCS path. (--ci only)",
)

Expand Down
37 changes: 37 additions & 0 deletions images/releng/k8s-ci-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2020 The Kubernetes 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.

ARG GO_VERSION
FROM golang:${GO_VERSION} as builder

WORKDIR /go/src/k8s.io/release

COPY ./ ./

RUN ./compile-release-tools

### Production image

FROM gcr.io/k8s-testimages/krte:latest-master

WORKDIR /
COPY --from=builder /go/bin/* ./

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get -q update \
&& apt-get install -qqy \
jq

ENTRYPOINT ["wrapper.sh"]
38 changes: 38 additions & 0 deletions images/releng/k8s-ci-builder/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://cloud.google.com/cloud-build/docs/build-config
timeout: 1200s
options:
substitution_option: ALLOW_LOOSE
steps:
- name: gcr.io/cloud-builders/docker
id: build
dir: images/releng/k8s-ci-builder
args:
- build
- --tag=gcr.io/$PROJECT_ID/k8s-ci-builder:${_GIT_TAG}-${_CONFIG}
- --tag=gcr.io/$PROJECT_ID/k8s-ci-builder:latest-${_CONFIG}
- --tag=gcr.io/$PROJECT_ID/k8s-ci-builder:${_KUBE_CROSS_VERSION}
- --build-arg=GO_VERSION=${_GO_VERSION}
- --build-arg=KUBE_CROSS_VERSION=${_KUBE_CROSS_VERSION}
- -f ./Dockerfile
- ../../../.

substitutions:
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
# can be used as a substitution
_GIT_TAG: '12345'
_PULL_BASE_REF: 'dev'
_CONFIG: 'cross0.0'
_GO_VERSION: '0.0.0'
_KUBE_CROSS_VERSION: 'v0.0.0-0'

images:
- 'gcr.io/$PROJECT_ID/k8s-ci-builder:${_GIT_TAG}-${_CONFIG}'
- 'gcr.io/$PROJECT_ID/k8s-ci-builder:latest-${_CONFIG}'
- 'gcr.io/$PROJECT_ID/k8s-ci-builder:${_KUBE_CROSS_VERSION}'

tags:
- 'k8s-ci-builder'
- ${_GIT_TAG}
- ${_PULL_BASE_REF}
- ${_GO_VERSION}
- ${_KUBE_CROSS_VERSION}
5 changes: 5 additions & 0 deletions images/releng/k8s-ci-builder/variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variants:
cross1.15:
CONFIG: 'cross1.15'
GO_VERSION: '1.15.3'
KUBE_CROSS_VERSION: 'v1.15.3-1'
47 changes: 45 additions & 2 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ limitations under the License.

package build

import (
"path/filepath"

"github.com/sirupsen/logrus"
)

var DefaultExtraVersionMarkers = []string{}

// Instance is the main structure for creating and pushing builds.
type Instance struct {
opts *Options
}

// NewInstance can be used to create a new build `Instance`.
func NewInstance(opts *Options) *Instance {
return &Instance{opts}
instance := &Instance{opts}
instance.setBuildType()

return instance
}

// Options are the main options to pass to `Instance`.
Expand All @@ -35,13 +46,17 @@ type Options struct {
// if not set.
BuildDir string

// Used to make determinations on where to push artifacts
// May be one of: 'devel', 'ci', 'release'
BuildType string

// If set, push docker images to specified registry/project.
DockerRegistry string

// Comma separated list which can be used to upload additional version
// files to GCS. The path is relative and is append to a GCS path. (--ci
// only).
ExtraVersionMarkers string
ExtraVersionMarkers []string

// Specify a suffix to append to the upload destination on GCS.
GCSSuffix string
Expand Down Expand Up @@ -76,3 +91,31 @@ type Options struct {
// `$PATH`.
ValidateRemoteImageDigests bool
}

// TODO: Support "release" buildType
func (bi *Instance) getGCSBuildPath(version string) string {
gcsDest := bi.opts.BuildType

if bi.opts.GCSSuffix != "" {
gcsDest += "-" + bi.opts.GCSSuffix
}

if bi.opts.Fast {
gcsDest = filepath.Join(gcsDest, "fast")
}
gcsDest = filepath.Join(gcsDest, version)
logrus.Infof("GCS destination is %s", gcsDest)

return gcsDest
}

func (bi *Instance) setBuildType() {
buildType := "devel"
if bi.opts.CI {
buildType = "ci"
}

bi.opts.BuildType = buildType

logrus.Infof("Build type is %s", bi.opts.BuildType)
}
18 changes: 3 additions & 15 deletions pkg/build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
func NewCIInstance(opts *Options) *Instance {
instance := NewInstance(opts)
instance.opts.CI = true
instance.setBuildType()

return instance
}
Expand Down Expand Up @@ -127,22 +128,9 @@ func (bi *Instance) checkBuildExists() (bool, error) {
bucket = "kubernetes-release-dev"
}

mode := "ci"
if bi.opts.CI {
mode = "ci"
}

if bi.opts.Fast {
mode += "/fast"
}

if bi.opts.GCSSuffix != "" {
mode += bi.opts.GCSSuffix
}

bi.opts.Bucket = bucket
gcsDest := bi.getGCSBuildPath(version)

gcsBuildRoot := filepath.Join(bucket, mode, version)
gcsBuildRoot := filepath.Join(bucket, gcsDest)
kubernetesTar := filepath.Join(gcsBuildRoot, release.KubernetesTar)
binPath := filepath.Join(gcsBuildRoot, "bin")

Expand Down
16 changes: 3 additions & 13 deletions pkg/build/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,7 @@ func (bi *Instance) Push() error {
return errors.Wrap(err, "push container images")
}

gcsDest := "devel"
if bi.opts.CI {
gcsDest = "ci"
}
gcsDest += bi.opts.GCSSuffix

if bi.opts.Fast {
gcsDest = filepath.Join(gcsDest, "fast")
}
gcsDest = filepath.Join(gcsDest, version)
logrus.Infof("GCS destination is %s", gcsDest)
gcsDest := bi.getGCSBuildPath(version)

if err := bi.PushReleaseArtifacts(
filepath.Join(bi.opts.BuildDir, release.GCSStagePath, version),
Expand All @@ -149,9 +139,9 @@ func (bi *Instance) Push() error {
}

// Publish release to GCS
versionMarkers := strings.Split(bi.opts.ExtraVersionMarkers, ",")
extraVersionMarkers := bi.opts.ExtraVersionMarkers
if err := release.NewPublisher().PublishVersion(
gcsDest, version, bi.opts.BuildDir, bi.opts.Bucket, versionMarkers,
bi.opts.BuildType, version, bi.opts.BuildDir, bi.opts.Bucket, extraVersionMarkers,
bi.opts.PrivateBucket, bi.opts.Fast,
); err != nil {
return errors.Wrap(err, "publish release")
Expand Down
36 changes: 21 additions & 15 deletions pkg/release/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (*defaultPublisher) GetURLResponse(url string) (string, error) {
// was releaselib.sh: release::gcs::publish_version
func (p *Publisher) PublishVersion(
buildType, version, buildDir, bucket string,
versionMarkers []string,
extraVersionMarkers []string,
privateBucket, fast bool,
) error {
logrus.Info("Publishing version")
Expand All @@ -101,50 +101,56 @@ func (p *Publisher) PublishVersion(
releasePath = gcs.GcsPrefix + filepath.Join(releasePath, version)

if err := p.client.GSUtil("ls", releasePath); err != nil {
return errors.Wrapf(err, "release files dont exist at %s", releasePath)
return errors.Wrapf(err, "release files don't exist at %s", releasePath)
}

sv, err := util.TagStringToSemver(version)
if err != nil {
return errors.Errorf("invalid version %s", version)
}

var publishFiles []string
var versionMarkers []string
if fast {
publishFiles = append([]string{
releaseType + "-fast",
}, versionMarkers...)
versionMarkers = append(
versionMarkers,
releaseType+"-fast",
)
} else {
publishFiles = append([]string{
versionMarkers = append(
versionMarkers,
releaseType,
fmt.Sprintf("%s-%d", releaseType, sv.Major),
fmt.Sprintf("%s-%d.%d", releaseType, sv.Major, sv.Minor),
}, versionMarkers...)
)
}

if len(extraVersionMarkers) > 0 {
versionMarkers = append(versionMarkers, extraVersionMarkers...)
}

logrus.Infof("Publish version markers: %v", publishFiles)
logrus.Infof("Publish version markers: %v", versionMarkers)
logrus.Infof("Publish official pointer text files to bucket %s", bucket)

for _, file := range publishFiles {
publishFile := filepath.Join(buildType, file+".txt")
for _, file := range versionMarkers {
versionMarker := filepath.Join(buildType, file+".txt")
needsUpdate, err := p.VerifyLatestUpdate(
publishFile, bucket, version,
versionMarker, bucket, version,
)
if err != nil {
return errors.Wrapf(err, "verify latest update for %s", publishFile)
return errors.Wrapf(err, "verify latest update for %s", versionMarker)
}
// If there's a version that's above the one we're trying to release,
// don't do anything, and just try the next one.
if !needsUpdate {
logrus.Infof(
"Skipping %s for %s because it does not need to be updated",
publishFile, version,
versionMarker, version,
)
continue
}

if err := p.PublishToGcs(
publishFile, buildDir, bucket, version, privateBucket,
versionMarker, buildDir, bucket, version, privateBucket,
); err != nil {
return errors.Wrap(err, "publish release to GCS")
}
Expand Down