Skip to content

[krel] Initial commit krel ci-build command #1698

New issue

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

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

Already on GitHub? # to your account

Merged
merged 8 commits into from
Nov 9, 2020
34 changes: 18 additions & 16 deletions cmd/krel/cmd/anago/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"

"k8s.io/release/pkg/build"
"k8s.io/release/pkg/release"
)

Expand All @@ -42,7 +44,7 @@ removed in future releases again when anago goes end of life.
}

var (
pushOpts = &release.PushBuildOptions{}
pushOpts = &build.Options{}
runStage bool
runRelease bool
buildVersion string
Expand Down Expand Up @@ -104,65 +106,65 @@ func init() {
AnagoCmd.AddCommand(pushCmd)
}

func runPush(opts *release.PushBuildOptions) error {
pushBuild := release.NewPushBuild(opts)
if err := pushBuild.CheckReleaseBucket(); err != nil {
func runPush(opts *build.Options) error {
buildInstance := build.NewInstance(opts)
if err := buildInstance.CheckReleaseBucket(); err != nil {
return errors.Wrap(err, "check release bucket access")
}

if runStage {
return runPushStage(pushBuild, opts)
return runPushStage(buildInstance, opts)
} else if runRelease {
return runPushRelease(pushBuild, opts)
return runPushRelease(buildInstance, opts)
}

return errors.New("neither --stage nor --release provided")
}

func runPushStage(
pushBuild *release.PushBuild,
opts *release.PushBuildOptions,
buildInstance *build.Instance,
opts *build.Options,
) error {
// Stage the local source tree
if err := pushBuild.StageLocalSourceTree(buildVersion); err != nil {
if err := buildInstance.StageLocalSourceTree(buildVersion); err != nil {
return errors.Wrap(err, "staging local source tree")
}

// Stage local artifacts and write checksums
if err := pushBuild.StageLocalArtifacts(); err != nil {
if err := buildInstance.StageLocalArtifacts(); err != nil {
return errors.Wrap(err, "staging local artifacts")
}
gcsPath := filepath.Join("stage", buildVersion, opts.Version)

// Push gcs-stage to GCS
if err := pushBuild.PushReleaseArtifacts(
if err := buildInstance.PushReleaseArtifacts(
filepath.Join(opts.BuildDir, release.GCSStagePath, opts.Version),
filepath.Join(gcsPath, release.GCSStagePath, opts.Version),
); err != nil {
return errors.Wrap(err, "pushing release artifacts")
}

// Push container release-images to GCS
if err := pushBuild.PushReleaseArtifacts(
if err := buildInstance.PushReleaseArtifacts(
filepath.Join(opts.BuildDir, release.ImagesPath),
filepath.Join(gcsPath, release.ImagesPath),
); err != nil {
return errors.Wrap(err, "pushing release artifacts")
}

// Push container images into registry
if err := pushBuild.PushContainerImages(); err != nil {
if err := buildInstance.PushContainerImages(); err != nil {
return errors.Wrap(err, "pushing container images")
}

return nil
}

func runPushRelease(
pushBuild *release.PushBuild,
opts *release.PushBuildOptions,
buildInstance *build.Instance,
opts *build.Options,
) error {
if err := pushBuild.CopyStagedFromGCS(opts.Bucket, buildVersion); err != nil {
if err := buildInstance.CopyStagedFromGCS(opts.Bucket, buildVersion); err != nil {
return errors.Wrap(err, "copy staged from GCS")
}

Expand Down
159 changes: 159 additions & 0 deletions cmd/krel/cmd/ci_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
Copyright 2019 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.
*/

package cmd

import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"k8s.io/release/pkg/build"
"k8s.io/release/pkg/release"
)

const ciBuildCmdDescription = `
Used for pushing developer builds and Jenkins' continuous builds.

Developer pushes simply run as they do pushing to devel/ on GCS.`

const ciBuildExample = `
ci-build [--noupdatelatest] [--ci] [--bucket=<GCS bucket>] [--private-bucket]

Scenarios:

krel push - Do a developer push
krel push --ci - Do a CI push
krel push --bucket=kubernetes-release-$USER - Do a developer push to kubernetes-release-$USER`

var ciBuildOpts = &build.Options{}

var ciBuildCmd = &cobra.Command{
Use: "ci-build",
Short: "Push Kubernetes release artifacts to Google Cloud Storage (GCS)",
Long: ciBuildCmdDescription,
Example: ciBuildExample,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if err := runCIBuild(ciBuildOpts); err != nil {
return errors.Wrap(err, "Failed to run:")
}

return nil
},
}

func init() {
// Build options

ciBuildCmd.PersistentFlags().BoolVar(
&ciBuildOpts.Fast,
"fast",
false,
"Specifies a fast build (linux/amd64 only)",
)

ciBuildCmd.PersistentFlags().BoolVar(
&ciBuildOpts.ConfigureDocker,
"configure-docker",
false,
"Configure docker client for gcr.io authentication to allow communication with non-public registries",
)

// Push options

ciBuildCmd.PersistentFlags().BoolVar(
&ciBuildOpts.AllowDup,
"allow-dup",
false,
"Do not exit error if the build already exists on the gcs path",
)

ciBuildCmd.PersistentFlags().BoolVar(
&ciBuildOpts.NoUpdateLatest,
"noupdatelatest",
false,
"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,
"bucket",
"",
"Specify an alternate bucket for pushes (normally 'devel' or 'ci')",
)

ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.BuildDir,
"buildDir",
release.BuildDir,
fmt.Sprintf(
"Specify an alternate build directory (defaults to '%s')",
release.BuildDir,
),
)

ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.DockerRegistry,
"docker-registry",
"",
"If set, push docker images to specified registry/project",
)

ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.ExtraVersionMarkers,
"extra-version-markers",
"",
"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)",
)

ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.GCSSuffix,
"gcs-suffix",
"",
"Specify a suffix to append to the upload destination on GCS",
)

ciBuildCmd.PersistentFlags().StringVar(
&ciBuildOpts.VersionSuffix,
"version-suffix",
"",
"Append suffix to version name if set",
)

ciBuildCmd.PersistentFlags().BoolVar(
&ciBuildOpts.ValidateRemoteImageDigests,
"validate-images",
false,
"Validate that the remove image digests exists, needs `skopeo` in `$PATH`",
)

rootCmd.AddCommand(ciBuildCmd)
}

func runCIBuild(opts *build.Options) error {
return build.NewCIInstance(opts).Build()
}
35 changes: 27 additions & 8 deletions cmd/krel/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,32 @@ import (

"github.com/pkg/errors"
"github.com/spf13/cobra"

"k8s.io/release/pkg/build"
"k8s.io/release/pkg/release"
)

const description = `
const pushCmdDescription = `
Used for pushing developer builds and Jenkins' continuous builds.

Developer pushes simply run as they do pushing to devel/ on GCS.
Developer pushes simply run as they do pushing to devel/ on GCS.`

const pushCmdExample = `
krel push [--noupdatelatest] [--ci] [--bucket=<GCS bucket>] [--private-bucket]

Scenarios:

krel push - Do a developer push
krel push --ci - Do a CI push
krel push --bucket=kubernetes-release-$USER - Do a developer push to kubernetes-release-$USER`

var pushBuildOpts = &release.PushBuildOptions{}
var pushBuildOpts = &build.Options{}

var pushBuildCmd = &cobra.Command{
Use: "push [--noupdatelatest] [--ci] [--bucket=<GS bucket>] [--private-bucket]",
Use: "push",
Short: "Push Kubernetes release artifacts to Google Cloud Storage (GCS)",
Example: description,
Long: pushCmdDescription,
Example: pushCmdExample,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -57,30 +65,35 @@ func init() {
false,
"Do not exit error if the build already exists on the gcs path",
)

pushBuildCmd.PersistentFlags().BoolVar(
&pushBuildOpts.CI,
"ci",
false,
"Used when called from Jenkins (for ci runs)",
)

pushBuildCmd.PersistentFlags().BoolVar(
&pushBuildOpts.NoUpdateLatest,
"noupdatelatest",
false,
"Do not update the latest file",
)

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

pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.Bucket,
"bucket",
"devel",
"Specify an alternate bucket for pushes (normally 'devel' or 'ci')",
)

pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.BuildDir,
"buildDir",
Expand All @@ -90,36 +103,42 @@ func init() {
release.BuildDir,
),
)

pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.DockerRegistry,
"docker-registry",
"",
"If set, push docker images to specified registry/project",
)

pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.ExtraVersionMarkers,
"extra-version-markers",
"",
"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)",
)

pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.GCSSuffix,
"gcs-suffix",
"",
"Specify a suffix to append to the upload destination on GCS",
)

pushBuildCmd.PersistentFlags().StringVar(
&pushBuildOpts.VersionSuffix,
"version-suffix",
"",
"Append suffix to version name if set",
)

pushBuildCmd.PersistentFlags().BoolVar(
&pushBuildOpts.Fast,
"fast",
false,
"Specifies a fast build (linux amd64 only)",
"Specifies a fast build (linux/amd64 only)",
)

pushBuildCmd.PersistentFlags().BoolVar(
&pushBuildOpts.ValidateRemoteImageDigests,
"validate-images",
Expand All @@ -130,6 +149,6 @@ func init() {
rootCmd.AddCommand(pushBuildCmd)
}

func runPushBuild(opts *release.PushBuildOptions) error {
return release.NewPushBuild(opts).Push()
func runPushBuild(opts *build.Options) error {
return build.NewInstance(opts).Push()
}
Loading