Skip to content

Commit

Permalink
Add a without-download flag to update-stemcell
Browse files Browse the repository at this point in the history
Allows Kiln to skip downloading a release if the remote source can
provide the SHA1 for the release tarball.
  • Loading branch information
davewalter committed Jan 17, 2025
1 parent 100ead3 commit c300bad
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 60 deletions.
10 changes: 5 additions & 5 deletions internal/commands/update_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ type UpdateRelease struct {
Options struct {
flags.Standard

Name string `short:"n" long:"name" required:"true" description:"name of release to update"`
Version string `short:"v" long:"version" required:"true" description:"desired version of release"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
AllowOnlyPublishableReleases bool `long:"allow-only-publishable-releases" description:"include releases that would not be shipped with the tile (development builds)"`
WithoutDownload bool `long:"without-download" description:"updates releases without downloading them"`
Name string `short:"n" long:"name" required:"true" description:"name of release to update"`
Version string `short:"v" long:"version" required:"true" description:"desired version of release"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
AllowOnlyPublishableReleases bool ` long:"allow-only-publishable-releases" default:"false" description:"include releases that would not be shipped with the tile (development builds)"`
WithoutDownload bool `short:"wd" long:"without-download" default:"false" description:"updates releases without downloading them"`
}
multiReleaseSourceProvider MultiReleaseSourceProvider
filesystem billy.Filesystem
Expand Down
25 changes: 15 additions & 10 deletions internal/commands/update_stemcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type UpdateStemcell struct {
Options struct {
flags.Standard

Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
UpdateReleases bool `short:"ur" long:"update-releases" description:"finds latest matching releases for new stemcell version"`
Version string `short:"v" long:"version" required:"true" description:"desired version of stemcell"`
ReleasesDir string `short:"rd" long:"releases-directory" default:"releases" description:"path to a directory to download releases into"`
UpdateReleases bool `short:"ur" long:"update-releases" default:"false" description:"finds latest matching releases for new stemcell version"`
WithoutDownload bool `short:"wd" long:"without-download" default:"false" description:"updates stemcell releases without downloading releases"`
}
FS billy.Filesystem
MultiReleaseSourceProvider MultiReleaseSourceProvider
Expand Down Expand Up @@ -75,10 +76,12 @@ func (update UpdateStemcell) Execute(args []string) error {
if err != nil {
return err
}

spec.StemcellOS = kilnfileLock.Stemcell.OS
spec.StemcellVersion = trimmedInputVersion

var remote cargo.BOSHReleaseTarballLock

if update.Options.UpdateReleases {
remote, err = releaseSource.FindReleaseVersion(spec, true)
} else {
Expand All @@ -89,25 +92,27 @@ func (update UpdateStemcell) Execute(args []string) error {
if err != nil {
return fmt.Errorf("while finding release %q, encountered error: %w", rel.Name, err)
}

if component.IsErrNotFound(err) {
return fmt.Errorf("couldn't find release %q", rel.Name)
}

if remote.RemotePath == rel.RemotePath && remote.RemoteSource == rel.RemoteSource {
update.Logger.Printf("No change for release %q\n", rel.Name)
continue
}
lock := &kilnfileLock.Releases[i]

lock.RemotePath = remote.RemotePath
lock.RemoteSource = remote.RemoteSource
lock.SHA1 = remote.SHA1
if remote.SHA1 == "" || remote.SHA1 == "not-calculated" {

if update.Options.UpdateReleases {
lock.Version = remote.Version
}

if !update.Options.WithoutDownload || lock.SHA1 == "" || lock.SHA1 == "not-calculated" {
// release source needs to download.
local, err := releaseSource.DownloadRelease(update.Options.ReleasesDir, remote)
if err != nil {
return fmt.Errorf("while downloading release %q, encountered error: %w", rel.Name, err)
return fmt.Errorf("while downloading release %s %s, encountered error: %w", lock.Name, lock.Version, err)
}

lock.SHA1 = local.Lock.SHA1
}
}
Expand Down
Loading

0 comments on commit c300bad

Please sign in to comment.