Skip to content

Commit 34dbaf0

Browse files
committed
pkg/build: Consolidate build type / directory setting logic
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 8dba283 commit 34dbaf0

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

pkg/build/build.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@ limitations under the License.
1616

1717
package build
1818

19+
import (
20+
"path/filepath"
21+
22+
"github.com/sirupsen/logrus"
23+
)
24+
1925
// Instance is the main structure for creating and pushing builds.
2026
type Instance struct {
2127
opts *Options
2228
}
2329

2430
// NewInstance can be used to create a new build `Instance`.
2531
func NewInstance(opts *Options) *Instance {
26-
return &Instance{opts}
32+
instance := &Instance{opts}
33+
instance.setBuildType()
34+
35+
return instance
2736
}
2837

2938
// Options are the main options to pass to `Instance`.
@@ -35,6 +44,10 @@ type Options struct {
3544
// if not set.
3645
BuildDir string
3746

47+
// Used to make determinations on where to push artifacts
48+
// May be one of: 'devel', 'ci', 'release'
49+
BuildType string
50+
3851
// If set, push docker images to specified registry/project.
3952
DockerRegistry string
4053

@@ -76,3 +89,31 @@ type Options struct {
7689
// `$PATH`.
7790
ValidateRemoteImageDigests bool
7891
}
92+
93+
// TODO: Support "release" buildType
94+
func (bi *Instance) getGCSBuildPath(version string) string {
95+
gcsDest := bi.opts.BuildType
96+
97+
if bi.opts.GCSSuffix != "" {
98+
gcsDest += "-" + bi.opts.GCSSuffix
99+
}
100+
101+
if bi.opts.Fast {
102+
gcsDest = filepath.Join(gcsDest, "fast")
103+
}
104+
gcsDest = filepath.Join(gcsDest, version)
105+
logrus.Infof("GCS destination is %s", gcsDest)
106+
107+
return gcsDest
108+
}
109+
110+
func (bi *Instance) setBuildType() {
111+
buildType := "devel"
112+
if bi.opts.CI {
113+
buildType = "ci"
114+
}
115+
116+
bi.opts.BuildType = buildType
117+
118+
logrus.Infof("Build type is %s", bi.opts.BuildType)
119+
}

pkg/build/ci.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
func NewCIInstance(opts *Options) *Instance {
3535
instance := NewInstance(opts)
3636
instance.opts.CI = true
37+
instance.setBuildType()
3738

3839
return instance
3940
}
@@ -127,20 +128,9 @@ func (bi *Instance) checkBuildExists() (bool, error) {
127128
bucket = "kubernetes-release-dev"
128129
}
129130

130-
mode := "ci"
131-
if bi.opts.CI {
132-
mode = "ci"
133-
}
134-
135-
if bi.opts.Fast {
136-
mode += "/fast"
137-
}
138-
139-
if bi.opts.GCSSuffix != "" {
140-
mode += bi.opts.GCSSuffix
141-
}
131+
gcsDest := bi.getGCSBuildPath(version)
142132

143-
gcsBuildRoot := filepath.Join(bucket, mode, version)
133+
gcsBuildRoot := filepath.Join(bucket, gcsDest, version)
144134
kubernetesTar := filepath.Join(gcsBuildRoot, release.KubernetesTar)
145135
binPath := filepath.Join(gcsBuildRoot, "bin")
146136

pkg/build/push.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,7 @@ func (bi *Instance) Push() error {
119119
return errors.Wrap(err, "push container images")
120120
}
121121

122-
gcsDest := "devel"
123-
if bi.opts.CI {
124-
gcsDest = "ci"
125-
}
126-
gcsDest += bi.opts.GCSSuffix
127-
128-
if bi.opts.Fast {
129-
gcsDest = filepath.Join(gcsDest, "fast")
130-
}
131-
gcsDest = filepath.Join(gcsDest, version)
132-
logrus.Infof("GCS destination is %s", gcsDest)
122+
gcsDest := bi.getGCSBuildPath(version)
133123

134124
if err := bi.PushReleaseArtifacts(
135125
filepath.Join(bi.opts.BuildDir, release.GCSStagePath, version),
@@ -151,7 +141,7 @@ func (bi *Instance) Push() error {
151141
// Publish release to GCS
152142
versionMarkers := strings.Split(bi.opts.ExtraVersionMarkers, ",")
153143
if err := release.NewPublisher().PublishVersion(
154-
gcsDest, version, bi.opts.BuildDir, bi.opts.Bucket, versionMarkers,
144+
bi.opts.BuildType, version, bi.opts.BuildDir, bi.opts.Bucket, versionMarkers,
155145
bi.opts.PrivateBucket, bi.opts.Fast,
156146
); err != nil {
157147
return errors.Wrap(err, "publish release")

pkg/release/publish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (p *Publisher) PublishVersion(
101101
releasePath = gcs.GcsPrefix + filepath.Join(releasePath, version)
102102

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

107107
sv, err := util.TagStringToSemver(version)

0 commit comments

Comments
 (0)