Skip to content

Commit

Permalink
running cmrel does not require to be in the release repo folder anymore
Browse files Browse the repository at this point in the history
The flag --cloudbuild was thus removed.

Signed-off-by: Maël Valais <[email protected]>
  • Loading branch information
maelvls committed Aug 25, 2021
1 parent 3d72173 commit 7f6411e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
15 changes: 7 additions & 8 deletions cmd/cmrel/cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (

"github.com/cert-manager/release/pkg/gcb"
"github.com/cert-manager/release/pkg/release"

_ "embed"
)

const (
Expand All @@ -53,9 +55,6 @@ type publishOptions struct {
// Name of the staged release to publish
ReleaseName string

// The path to the cloudbuild.yaml file used to perform the cert-manager crossbuild
CloudBuildFile string

// Project to run the GCB job in
Project string

Expand Down Expand Up @@ -98,8 +97,6 @@ type publishOptions struct {
func (o *publishOptions) AddFlags(fs *flag.FlagSet, markRequired func(string)) {
fs.StringVar(&o.Bucket, "bucket", release.DefaultBucketName, "The name of the GCS bucket to publish the release to.")
fs.StringVar(&o.ReleaseName, "release-name", "", "Name of the staged release to publish.")
fs.StringVar(&o.CloudBuildFile, "cloudbuild", "./gcb/publish/cloudbuild.yaml", "The path to the cloudbuild.yaml file used to publish the release. "+
"The default value assumes that this tool is run from the root of the release repository.")
fs.StringVar(&o.Project, "project", release.DefaultReleaseProject, "The GCP project to run the GCB build jobs in.")
fs.BoolVar(&o.NoMock, "nomock", false, "Whether to actually publish the release. If false, the command will exit after preparing the release for pushing.")
fs.StringVar(&o.PublishedImageRepository, "published-image-repo", release.DefaultImageRepository, "The docker image repository to push the release images & manifest lists to.")
Expand Down Expand Up @@ -145,7 +142,10 @@ func publishCmd(rootOpts *rootOptions) *cobra.Command {
return cmd
}

func runPublish(rootOpts *rootOptions, o *publishOptions) error {
//go:embed publish_cloudbuild.yaml
var cloudbuildPublish []byte

func runPublish(_ *rootOptions, o *publishOptions) error {
ctx := context.Background()
gcs, err := storage.NewClient(ctx)
if err != nil {
Expand All @@ -159,8 +159,7 @@ func runPublish(rootOpts *rootOptions, o *publishOptions) error {
}
log.Printf("Release with version %q (%s) will be published", rel.Metadata().ReleaseVersion, rel.Metadata().GitCommitRef)

log.Printf("DEBUG: Loading cloudbuild.yaml file from %q", o.CloudBuildFile)
build, err := gcb.LoadBuild(o.CloudBuildFile)
build, err := gcb.LoadCloudBuild(cloudbuildPublish)
if err != nil {
return fmt.Errorf("error loading cloudbuild.yaml file: %w", err)
}
Expand Down
File renamed without changes.
16 changes: 7 additions & 9 deletions cmd/cmrel/cmd/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

"github.com/cert-manager/release/pkg/gcb"
"github.com/cert-manager/release/pkg/release"

_ "embed"
)

const (
Expand Down Expand Up @@ -67,9 +69,6 @@ type stageOptions struct {
// Optional commit ref of cert-manager that should be staged
GitRef string

// The path to the cloudbuild.yaml file used to perform the cert-manager crossbuild
CloudBuildFile string

// Project is the name of the GCP project to run the GCB job in
Project string

Expand All @@ -92,8 +91,6 @@ func (o *stageOptions) AddFlags(fs *flag.FlagSet, markRequired func(string)) {
fs.StringVar(&o.Repo, "repo", "cert-manager", "Name of the GitHub repo to fetch cert-manager sources from.")
fs.StringVar(&o.Branch, "branch", "master", "The git branch to build the release from. If --git-ref is not specified, the HEAD of this branch will be looked up on GitHub.")
fs.StringVar(&o.GitRef, "git-ref", "", "The git commit ref of cert-manager that should be staged.")
fs.StringVar(&o.CloudBuildFile, "cloudbuild", "./gcb/stage/cloudbuild.yaml", "The path to the cloudbuild.yaml file used to perform the cert-manager crossbuild. "+
"The default value assumes that this tool is run from the root of the release repository.")
fs.StringVar(&o.Project, "project", release.DefaultReleaseProject, "The GCP project to run the GCB build jobs in.")
fs.StringVar(&o.ReleaseVersion, "release-version", "", "Optional release version override used to force the version strings used during the release to a specific value. If not set, build is treated as development build and artifacts staged to 'devel' path.")
fs.StringVar(&o.PublishedImageRepository, "published-image-repo", release.DefaultImageRepository, "The docker image repository set when building the release.")
Expand All @@ -107,7 +104,6 @@ func (o *stageOptions) print() {
log.Printf(" Repo: %q", o.Repo)
log.Printf(" Branch: %q", o.Branch)
log.Printf(" GitRef: %q", o.GitRef)
log.Printf(" CloudBuildFile: %q", o.CloudBuildFile)
log.Printf(" Project: %q", o.Project)
log.Printf(" ReleaseVersion: %q", o.ReleaseVersion)
log.Printf(" PublishedImageRepo: %q", o.PublishedImageRepository)
Expand All @@ -133,7 +129,10 @@ func stageCmd(rootOpts *rootOptions) *cobra.Command {
return cmd
}

func runStage(rootOpts *rootOptions, o *stageOptions) error {
//go:embed stage_cloudbuild.yaml
var cloudbuildStage []byte

func runStage(_ *rootOptions, o *stageOptions) error {
if o.GitRef == "" {
log.Printf("git-ref flag not specified, looking up git commit ref for %s/%s@%s", o.Org, o.Repo, o.Branch)
ref, err := release.LookupBranchRef(o.Org, o.Repo, o.Branch)
Expand All @@ -144,8 +143,7 @@ func runStage(rootOpts *rootOptions, o *stageOptions) error {
}
log.Printf("Staging build for %s/%s@%s", o.Org, o.Repo, o.GitRef)

log.Printf("DEBUG: Loading cloudbuild.yaml file from %q", o.CloudBuildFile)
build, err := gcb.LoadBuild(o.CloudBuildFile)
build, err := gcb.LoadCloudBuild(cloudbuildStage)
if err != nil {
return fmt.Errorf("error loading cloudbuild.yaml file: %w", err)
}
Expand Down
File renamed without changes.
17 changes: 5 additions & 12 deletions pkg/gcb/gcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"log"
"os"
"time"

"google.golang.org/api/cloudbuild/v1"
Expand All @@ -34,16 +33,11 @@ const (
Failure = "FAILURE"
)

// LoadBuild will decode a cloudbuild.yaml file into a cloudbuild.Build
// structure and return it.
func LoadBuild(filename string) (*cloudbuild.Build, error) {
f, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

// LoadCloudBuild will decode the content of a cloudbuild.yaml file into a
// cloudbuild.Build structure and return it.
func LoadCloudBuild(cloudbuildRaw []byte) (*cloudbuild.Build, error) {
cb := cloudbuild.Build{}
if err := yaml.UnmarshalStrict(f, &cb); err != nil {
if err := yaml.UnmarshalStrict(cloudbuildRaw, &cb); err != nil {
return nil, err
}

Expand All @@ -59,10 +53,9 @@ func SubmitBuild(svc *cloudbuild.Service, projectID string, build *cloudbuild.Bu
return nil, err
}

log.Printf("DEBUG: decoding build operation metadata")
metadata := &cloudbuild.BuildOperationMetadata{}
if err := json.Unmarshal(op.Metadata, metadata); err != nil {
return nil, err
return nil, fmt.Errorf("while decoding build operation metadata: %v", err)
}

return metadata.Build, nil
Expand Down

0 comments on commit 7f6411e

Please sign in to comment.