Skip to content

Commit 48e841b

Browse files
committed
Add a without-download flag to update-stemcell
Allows Kiln to skip downloading a release if the remote source can provide the SHA1 for the release tarball.
1 parent 33af946 commit 48e841b

File tree

6 files changed

+193
-57
lines changed

6 files changed

+193
-57
lines changed

internal/commands/update_release.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ type UpdateRelease struct {
1616
Options struct {
1717
flags.Standard
1818

19-
Name string `short:"n" long:"name" required:"true" description:"name of release to update"`
20-
Version string `short:"v" long:"version" required:"true" description:"desired version of release"`
21-
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
22-
AllowOnlyPublishableReleases bool `long:"allow-only-publishable-releases" description:"include releases that would not be shipped with the tile (development builds)"`
23-
WithoutDownload bool `long:"without-download" description:"updates releases without downloading them"`
19+
Name string `short:"n" long:"name" required:"true" description:"name of release to update"`
20+
Version string `short:"v" long:"version" required:"true" description:"desired version of release"`
21+
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
22+
AllowOnlyPublishableReleases bool ` long:"allow-only-publishable-releases" default:"false" description:"include releases that would not be shipped with the tile (development builds)"`
23+
WithoutDownload bool `short:"wd" long:"without-download" default:"false" description:"updates releases without downloading them"`
2424
}
2525
multiReleaseSourceProvider MultiReleaseSourceProvider
2626
filesystem billy.Filesystem

internal/commands/update_stemcell.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ type UpdateStemcell struct {
1919
Options struct {
2020
flags.Standard
2121

22-
Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
23-
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
24-
UpdateReleases bool `short:"ur" long:"update-releases" description:"finds latest matching releases for new stemcell version"`
22+
Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
23+
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
24+
UpdateReleases bool `short:"ur" long:"update-releases" default:"false" description:"finds latest matching releases for new stemcell version"`
25+
WithoutDownload bool `short:"wd" long:"without-download" default:"false" description:"updates stemcell releases without downloading releases"`
2526
}
2627
FS billy.Filesystem
2728
MultiReleaseSourceProvider MultiReleaseSourceProvider
@@ -75,10 +76,12 @@ func (update UpdateStemcell) Execute(args []string) error {
7576
if err != nil {
7677
return err
7778
}
79+
7880
spec.StemcellOS = kilnfileLock.Stemcell.OS
7981
spec.StemcellVersion = trimmedInputVersion
8082

8183
var remote cargo.BOSHReleaseTarballLock
84+
8285
if update.Options.UpdateReleases {
8386
remote, err = releaseSource.FindReleaseVersion(spec, true)
8487
} else {
@@ -89,25 +92,35 @@ func (update UpdateStemcell) Execute(args []string) error {
8992
if err != nil {
9093
return fmt.Errorf("while finding release %q, encountered error: %w", rel.Name, err)
9194
}
95+
9296
if component.IsErrNotFound(err) {
9397
return fmt.Errorf("couldn't find release %q", rel.Name)
9498
}
9599

96100
if remote.RemotePath == rel.RemotePath && remote.RemoteSource == rel.RemoteSource {
97101
update.Logger.Printf("No change for release %q\n", rel.Name)
98-
continue
102+
103+
if update.Options.WithoutDownload {
104+
continue
105+
}
99106
}
100-
lock := &kilnfileLock.Releases[i]
101107

108+
lock := &kilnfileLock.Releases[i]
102109
lock.RemotePath = remote.RemotePath
103110
lock.RemoteSource = remote.RemoteSource
104111
lock.SHA1 = remote.SHA1
105-
if remote.SHA1 == "" || remote.SHA1 == "not-calculated" {
112+
113+
if update.Options.UpdateReleases {
114+
lock.Version = remote.Version
115+
}
116+
117+
if !update.Options.WithoutDownload || lock.SHA1 == "" || lock.SHA1 == "not-calculated" {
106118
// release source needs to download.
107119
local, err := releaseSource.DownloadRelease(update.Options.ReleasesDir, remote)
108120
if err != nil {
109-
return fmt.Errorf("while downloading release %q, encountered error: %w", rel.Name, err)
121+
return fmt.Errorf("while downloading release %s %s, encountered error: %w", lock.Name, lock.Version, err)
110122
}
123+
111124
lock.SHA1 = local.Lock.SHA1
112125
}
113126
}

0 commit comments

Comments
 (0)