Skip to content

Commit

Permalink
do not download release for update stemcell unless required
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Linsley <daniel.linsley@broadcom.com>
  • Loading branch information
dlinsley committed Dec 5, 2024
1 parent 8273461 commit bc50af4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
17 changes: 10 additions & 7 deletions internal/commands/update_stemcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,19 @@ func (update UpdateStemcell) Execute(args []string) error {
update.Logger.Printf("No change for release %q\n", rel.Name)
continue
}

local, err := releaseSource.DownloadRelease(update.Options.ReleasesDir, remote)
if err != nil {
return fmt.Errorf("while downloading release %q, encountered error: %w", rel.Name, err)
}

lock := &kilnfileLock.Releases[i]
lock.SHA1 = local.Lock.SHA1

lock.RemotePath = remote.RemotePath
lock.RemoteSource = remote.RemoteSource
lock.SHA1 = remote.SHA1
if remote.SHA1 == "" || remote.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)
}
lock.SHA1 = local.Lock.SHA1
}
}

kilnfileLock.Stemcell.Version = trimmedInputVersion
Expand Down
13 changes: 10 additions & 3 deletions internal/component/artifactory_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,20 @@ func (ars *ArtifactoryReleaseSource) GetMatchedRelease(spec cargo.BOSHReleaseTar
default:
return cargo.BOSHReleaseTarballLock{}, fmt.Errorf("unexpected http status: %s", http.StatusText(response.StatusCode))
}

return cargo.BOSHReleaseTarballLock{
matchedRelease := cargo.BOSHReleaseTarballLock{
Name: spec.Name,
Version: spec.Version,
RemotePath: remotePath,
RemoteSource: ars.ID,
}, nil
}

matchedRelease.SHA1, err = ars.getFileSHA1(matchedRelease)
if err != nil {
return cargo.BOSHReleaseTarballLock{}, err
}

return matchedRelease, nil
}

// FindReleaseVersion may use any of the fields on Requirement to return the best matching
Expand Down
1 change: 1 addition & 0 deletions internal/component/artifactory_release_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var _ = Describe("interacting with BOSH releases on Artifactory", func() {
// StemcellVersion: "9.9",
RemotePath: "bosh-releases/smoothie/9.9/mango/mango-2.3.4-smoothie-9.9.tgz",
RemoteSource: "some-mango-tree",
SHA1: "some-sha",
}))
})

Expand Down
15 changes: 8 additions & 7 deletions internal/component/bosh_io_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ func (src BOSHIOReleaseSource) GetMatchedRelease(requirement cargo.BOSHReleaseTa
for _, repo := range repos {
for _, suf := range suffixes {
fullName := repo + "/" + requirement.Name + suf
exists, err := src.releaseExistOnBoshio(fullName, requirement.Version)
exists, remoteSha, err := src.releaseExistOnBoshio(fullName, requirement.Version)
if err != nil {
return cargo.BOSHReleaseTarballLock{}, err
}

if exists {
builtRelease := src.createReleaseRemote(requirement, fullName)
builtRelease.SHA1 = remoteSha
return builtRelease, nil
}
}
Expand Down Expand Up @@ -135,7 +136,7 @@ func (src BOSHIOReleaseSource) FindReleaseVersion(spec cargo.BOSHReleaseTarballS
}
spec.Version = validReleases[0].Version
lock := src.createReleaseRemote(spec, fullName)
lock.SHA1 = validReleases[0].SHA
lock.SHA1 = validReleases[0].SHA1
return lock, nil
}
}
Expand Down Expand Up @@ -232,18 +233,18 @@ func (src BOSHIOReleaseSource) getReleases(name string) ([]releaseResponse, erro

type releaseResponse struct {
Version string `json:"version"`
SHA string `json:"sha1"`
SHA1 string `json:"sha1"`
}

func (src BOSHIOReleaseSource) releaseExistOnBoshio(name, version string) (bool, error) {
func (src BOSHIOReleaseSource) releaseExistOnBoshio(name, version string) (bool, string, error) {
releaseResponses, err := src.getReleases(name)
if err != nil {
return false, err
return false, "", err
}
for _, rel := range releaseResponses {
if rel.Version == version {
return true, nil
return true, rel.SHA1, nil
}
}
return false, nil
return false, "", nil
}
5 changes: 3 additions & 2 deletions internal/component/bosh_io_release_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("BOSHIOReleaseSource", func() {
testServer.RouteToHandler("GET", path, ghttp.RespondWith(http.StatusOK, `null`))

path, _ = regexp.Compile(`/api/v1/releases/github.com/\S+/uaa.*`)
testServer.RouteToHandler("GET", path, ghttp.RespondWith(http.StatusOK, `[{"version": "73.3.0"}]`))
testServer.RouteToHandler("GET", path, ghttp.RespondWith(http.StatusOK, `[{"version": "73.3.0", "sha1":"b6e8a9cbc8724edcecb8658fa9459ee6c8fc259e"}]`))

path, _ = regexp.Compile(`/api/v1/releases/github.com/\S+/metrics.*`)
testServer.RouteToHandler("GET", path, ghttp.RespondWith(http.StatusOK, `[{"version": "2.3.0"}]`))
Expand All @@ -74,6 +74,7 @@ var _ = Describe("BOSHIOReleaseSource", func() {
Version: "73.3.0",
RemotePath: uaaURL,
RemoteSource: component.ReleaseSourceTypeBOSHIO,
SHA1: "b6e8a9cbc8724edcecb8658fa9459ee6c8fc259e",
}))

foundRelease, err = releaseSource.GetMatchedRelease(rabbitmqRequirement)
Expand Down Expand Up @@ -299,7 +300,7 @@ var _ = Describe("BOSHIOReleaseSource", func() {
testServer = ghttp.NewServer()

path, _ := regexp.Compile(`/api/v1/releases/github.com/\S+/cf-rabbitmq.*`)
testServer.RouteToHandler("GET", path, ghttp.RespondWith(http.StatusOK, `[{"name":"github.com/cloudfoundry/cf-rabbitmq-release","version":"309.0.5","url":"https://bosh.io/d/github.com/cloudfoundry/cf-rabbitmq-release?v=309.0.0","sha1":"5df538657c2cc830bda679420a9b162682018ded"},{"name":"github.com/cloudfoundry/cf-rabbitmq-release","version":"308.0.0","url":"https://bosh.io/d/github.com/cloudfoundry/cf-rabbitmq-release?v=308.0.0","sha1":"56202c9a466a8394683ae432ee2dea21ef6ef865"}]`))
testServer.RouteToHandler("GET", path, ghttp.RespondWith(http.StatusOK, `[{"name":"github.com/cloudfoundry/cf-rabbitmq-release","version":"309.0.5","url":"https://bosh.io/d/github.com/cloudfoundry/cf-rabbitmq-release?v=309.0.0","sha1":"5df538657c2cc830bda679420a9b162682018ded","sha256": "49cad4a9758026cbae7a26f77921300595459dfa6bc0ca5332fc6ba52bd336b8"},{"name":"github.com/cloudfoundry/cf-rabbitmq-release","version":"308.0.0","url":"https://bosh.io/d/github.com/cloudfoundry/cf-rabbitmq-release?v=308.0.0","sha1":"56202c9a466a8394683ae432ee2dea21ef6ef865","sha256":"5970d4211d236896d9366b150a66e38cbbd757fed31895962e499bb5458e0937"}]`))

releaseSource = component.NewBOSHIOReleaseSource(cargo.ReleaseSourceConfig{ID: ID, Publishable: false}, testServer.URL(), logger)
})
Expand Down

0 comments on commit bc50af4

Please sign in to comment.