Skip to content

Commit bf965bf

Browse files
committed
running cmrel does not require to be in the release repo folder anymore
The flag --cloudbuild was thus removed. Signed-off-by: Maël Valais <[email protected]>
1 parent 482d375 commit bf965bf

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

cmd/cmrel/cmd/publish.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828

2929
"github.com/cert-manager/release/pkg/gcb"
3030
"github.com/cert-manager/release/pkg/release"
31+
32+
_ "embed"
3133
)
3234

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

56-
// The path to the cloudbuild.yaml file used to perform the cert-manager crossbuild
57-
CloudBuildFile string
58-
5958
// Project to run the GCB job in
6059
Project string
6160

@@ -98,8 +97,6 @@ type publishOptions struct {
9897
func (o *publishOptions) AddFlags(fs *flag.FlagSet, markRequired func(string)) {
9998
fs.StringVar(&o.Bucket, "bucket", release.DefaultBucketName, "The name of the GCS bucket to publish the release to.")
10099
fs.StringVar(&o.ReleaseName, "release-name", "", "Name of the staged release to publish.")
101-
fs.StringVar(&o.CloudBuildFile, "cloudbuild", "./gcb/publish/cloudbuild.yaml", "The path to the cloudbuild.yaml file used to publish the release. "+
102-
"The default value assumes that this tool is run from the root of the release repository.")
103100
fs.StringVar(&o.Project, "project", release.DefaultReleaseProject, "The GCP project to run the GCB build jobs in.")
104101
fs.BoolVar(&o.NoMock, "nomock", false, "Whether to actually publish the release. If false, the command will exit after preparing the release for pushing.")
105102
fs.StringVar(&o.PublishedImageRepository, "published-image-repo", release.DefaultImageRepository, "The docker image repository to push the release images & manifest lists to.")
@@ -114,7 +111,6 @@ func (o *publishOptions) print() {
114111
log.Printf("Publish options:")
115112
log.Printf(" Bucket: %q", o.Bucket)
116113
log.Printf(" ReleaseName: %q", o.ReleaseName)
117-
log.Printf(" CloudBuildFile: %q", o.CloudBuildFile)
118114
log.Printf(" Project: %q", o.Project)
119115
log.Printf(" NoMock: %t", o.NoMock)
120116
log.Printf(" PublishedImageRepo: %q", o.PublishedImageRepository)
@@ -145,7 +141,10 @@ func publishCmd(rootOpts *rootOptions) *cobra.Command {
145141
return cmd
146142
}
147143

148-
func runPublish(rootOpts *rootOptions, o *publishOptions) error {
144+
//go:embed publish_cloudbuild.yaml
145+
var cloudbuildPublish []byte
146+
147+
func runPublish(_ *rootOptions, o *publishOptions) error {
149148
ctx := context.Background()
150149
gcs, err := storage.NewClient(ctx)
151150
if err != nil {
@@ -159,8 +158,7 @@ func runPublish(rootOpts *rootOptions, o *publishOptions) error {
159158
}
160159
log.Printf("Release with version %q (%s) will be published", rel.Metadata().ReleaseVersion, rel.Metadata().GitCommitRef)
161160

162-
log.Printf("DEBUG: Loading cloudbuild.yaml file from %q", o.CloudBuildFile)
163-
build, err := gcb.LoadBuild(o.CloudBuildFile)
161+
build, err := gcb.LoadCloudBuild(cloudbuildPublish)
164162
if err != nil {
165163
return fmt.Errorf("error loading cloudbuild.yaml file: %w", err)
166164
}
File renamed without changes.

cmd/cmrel/cmd/stage.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727

2828
"github.com/cert-manager/release/pkg/gcb"
2929
"github.com/cert-manager/release/pkg/release"
30+
31+
_ "embed"
3032
)
3133

3234
const (
@@ -67,9 +69,6 @@ type stageOptions struct {
6769
// Optional commit ref of cert-manager that should be staged
6870
GitRef string
6971

70-
// The path to the cloudbuild.yaml file used to perform the cert-manager crossbuild
71-
CloudBuildFile string
72-
7372
// Project is the name of the GCP project to run the GCB job in
7473
Project string
7574

@@ -92,8 +91,6 @@ func (o *stageOptions) AddFlags(fs *flag.FlagSet, markRequired func(string)) {
9291
fs.StringVar(&o.Repo, "repo", "cert-manager", "Name of the GitHub repo to fetch cert-manager sources from.")
9392
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.")
9493
fs.StringVar(&o.GitRef, "git-ref", "", "The git commit ref of cert-manager that should be staged.")
95-
fs.StringVar(&o.CloudBuildFile, "cloudbuild", "./gcb/stage/cloudbuild.yaml", "The path to the cloudbuild.yaml file used to perform the cert-manager crossbuild. "+
96-
"The default value assumes that this tool is run from the root of the release repository.")
9794
fs.StringVar(&o.Project, "project", release.DefaultReleaseProject, "The GCP project to run the GCB build jobs in.")
9895
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.")
9996
fs.StringVar(&o.PublishedImageRepository, "published-image-repo", release.DefaultImageRepository, "The docker image repository set when building the release.")
@@ -107,7 +104,6 @@ func (o *stageOptions) print() {
107104
log.Printf(" Repo: %q", o.Repo)
108105
log.Printf(" Branch: %q", o.Branch)
109106
log.Printf(" GitRef: %q", o.GitRef)
110-
log.Printf(" CloudBuildFile: %q", o.CloudBuildFile)
111107
log.Printf(" Project: %q", o.Project)
112108
log.Printf(" ReleaseVersion: %q", o.ReleaseVersion)
113109
log.Printf(" PublishedImageRepo: %q", o.PublishedImageRepository)
@@ -133,7 +129,10 @@ func stageCmd(rootOpts *rootOptions) *cobra.Command {
133129
return cmd
134130
}
135131

136-
func runStage(rootOpts *rootOptions, o *stageOptions) error {
132+
//go:embed stage_cloudbuild.yaml
133+
var cloudbuildStage []byte
134+
135+
func runStage(_ *rootOptions, o *stageOptions) error {
137136
if o.GitRef == "" {
138137
log.Printf("git-ref flag not specified, looking up git commit ref for %s/%s@%s", o.Org, o.Repo, o.Branch)
139138
ref, err := release.LookupBranchRef(o.Org, o.Repo, o.Branch)
@@ -144,8 +143,7 @@ func runStage(rootOpts *rootOptions, o *stageOptions) error {
144143
}
145144
log.Printf("Staging build for %s/%s@%s", o.Org, o.Repo, o.GitRef)
146145

147-
log.Printf("DEBUG: Loading cloudbuild.yaml file from %q", o.CloudBuildFile)
148-
build, err := gcb.LoadBuild(o.CloudBuildFile)
146+
build, err := gcb.LoadCloudBuild(cloudbuildStage)
149147
if err != nil {
150148
return fmt.Errorf("error loading cloudbuild.yaml file: %w", err)
151149
}
File renamed without changes.

pkg/gcb/gcb.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"log"
24-
"os"
2524
"time"
2625

2726
"google.golang.org/api/cloudbuild/v1"
@@ -34,16 +33,11 @@ const (
3433
Failure = "FAILURE"
3534
)
3635

37-
// LoadBuild will decode a cloudbuild.yaml file into a cloudbuild.Build
38-
// structure and return it.
39-
func LoadBuild(filename string) (*cloudbuild.Build, error) {
40-
f, err := os.ReadFile(filename)
41-
if err != nil {
42-
return nil, err
43-
}
44-
36+
// LoadCloudBuild will decode the content of a cloudbuild.yaml file into a
37+
// cloudbuild.Build structure and return it.
38+
func LoadCloudBuild(cloudbuildRaw []byte) (*cloudbuild.Build, error) {
4539
cb := cloudbuild.Build{}
46-
if err := yaml.UnmarshalStrict(f, &cb); err != nil {
40+
if err := yaml.UnmarshalStrict(cloudbuildRaw, &cb); err != nil {
4741
return nil, err
4842
}
4943

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

62-
log.Printf("DEBUG: decoding build operation metadata")
6356
metadata := &cloudbuild.BuildOperationMetadata{}
6457
if err := json.Unmarshal(op.Metadata, metadata); err != nil {
65-
return nil, err
58+
return nil, fmt.Errorf("while decoding build operation metadata: %v", err)
6659
}
6760

6861
return metadata.Build, nil

0 commit comments

Comments
 (0)