Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make where we work with BOSH Release tarballs explicit #405

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func theLockSpecifiesVersionForRelease(ctx context.Context, releaseVersion, rele
if err != nil {
return err
}
releaseLock, err := lock.FindReleaseWithName(releaseName)
releaseLock, err := lock.FindBOSHReleaseWithName(releaseName)
if err != nil {
return err
}
Expand All @@ -70,7 +70,7 @@ func iSetAVersionConstraintForRelease(ctx context.Context, versionConstraint, re
if err != nil {
return err
}
specIndex := slices.IndexFunc(spec.Releases, func(release cargo.ComponentSpec) bool {
specIndex := slices.IndexFunc(spec.Releases, func(release cargo.BOSHReleaseTarballSpecification) bool {
return release.Name == releaseName
})
if specIndex == indexNotFound {
Expand Down Expand Up @@ -225,7 +225,7 @@ func theKilnfileVersionForReleaseIs(ctx context.Context, releaseName, releaseVer
if err != nil {
return err
}
releaseLock, err := kf.ComponentSpec(releaseName)
releaseLock, err := kf.BOSHReleaseTarballSpecification(releaseName)
if err != nil {
return err
}
Expand Down
30 changes: 15 additions & 15 deletions internal/commands/cache_compiled_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type (

ReleaseStorage interface {
component.ReleaseSource
UploadRelease(spec component.Spec, file io.Reader) (component.Lock, error)
UploadRelease(spec cargo.BOSHReleaseTarballSpecification, file io.Reader) (cargo.BOSHReleaseTarballLock, error)
}
)

Expand Down Expand Up @@ -118,11 +118,11 @@ func (cmd *CacheCompiledReleases) Execute(args []string) error {
}

var (
releasesToExport []cargo.ComponentLock
releasesToExport []cargo.BOSHReleaseTarballLock
releasesUpdatedFromCache = false
)
for _, rel := range lock.Releases {
remote, err := releaseStore.GetMatchedRelease(component.Spec{
remote, err := releaseStore.GetMatchedRelease(cargo.BOSHReleaseTarballSpecification{
Name: rel.Name,
Version: rel.Version,
StemcellOS: lock.Stemcell.OS,
Expand All @@ -132,7 +132,7 @@ func (cmd *CacheCompiledReleases) Execute(args []string) error {
if !component.IsErrNotFound(err) {
return fmt.Errorf("failed check for matched release: %w", err)
}
releasesToExport = append(releasesToExport, component.Lock{
releasesToExport = append(releasesToExport, cargo.BOSHReleaseTarballLock{
Name: rel.Name,
Version: rel.Version,
StemcellOS: lock.Stemcell.OS,
Expand Down Expand Up @@ -301,36 +301,36 @@ func (cmd *CacheCompiledReleases) fetchProductDeploymentData() (_ OpsManagerRele
return omAPI, manifest.Name, stagedStemcell.OS, stagedStemcell.Version, nil
}

func (cmd *CacheCompiledReleases) cacheRelease(bosh boshdir.Director, rc ReleaseStorage, deployment boshdir.Deployment, releaseSlug boshdir.ReleaseSlug, stemcellSlug boshdir.OSVersionSlug) (component.Lock, error) {
func (cmd *CacheCompiledReleases) cacheRelease(bosh boshdir.Director, rc ReleaseStorage, deployment boshdir.Deployment, releaseSlug boshdir.ReleaseSlug, stemcellSlug boshdir.OSVersionSlug) (cargo.BOSHReleaseTarballLock, error) {
cmd.Logger.Printf("\texporting %s\n", releaseSlug)
result, err := deployment.ExportRelease(releaseSlug, stemcellSlug, nil)
if err != nil {
return component.Lock{}, err
return cargo.BOSHReleaseTarballLock{}, err
}

cmd.Logger.Printf("\tdownloading %s\n", releaseSlug)
releaseFilePath, _, sha1sum, err := cmd.saveReleaseLocally(bosh, cmd.Options.ReleasesDir, releaseSlug, stemcellSlug, result)
if err != nil {
return component.Lock{}, err
return cargo.BOSHReleaseTarballLock{}, err
}

cmd.Logger.Printf("\tuploading %s\n", releaseSlug)
remoteRelease, err := cmd.uploadLocalRelease(cargo.ComponentSpec{
remoteRelease, err := cmd.uploadLocalRelease(cargo.BOSHReleaseTarballSpecification{
Name: releaseSlug.Name(),
Version: releaseSlug.Version(),
StemcellOS: stemcellSlug.OS(),
StemcellVersion: stemcellSlug.Version(),
}, releaseFilePath, rc)
if err != nil {
return component.Lock{}, err
return cargo.BOSHReleaseTarballLock{}, err
}

remoteRelease.SHA1 = sha1sum

return remoteRelease, nil
}

func updateLock(lock cargo.KilnfileLock, release component.Lock, targetID string) error {
func updateLock(lock cargo.KilnfileLock, release cargo.BOSHReleaseTarballLock, targetID string) error {
for index, releaseLock := range lock.Releases {
if release.Name != releaseLock.Name {
continue
Expand All @@ -341,7 +341,7 @@ func updateLock(lock cargo.KilnfileLock, release component.Lock, targetID string
checksum = releaseLock.SHA1
}

lock.Releases[index] = cargo.ComponentLock{
lock.Releases[index] = cargo.BOSHReleaseTarballLock{
Name: release.Name,
Version: release.Version,
RemoteSource: release.RemoteSource,
Expand All @@ -353,10 +353,10 @@ func updateLock(lock cargo.KilnfileLock, release component.Lock, targetID string
return fmt.Errorf("existing release not found in Kilnfile.lock")
}

func (cmd *CacheCompiledReleases) uploadLocalRelease(spec component.Spec, fp string, uploader ReleaseStorage) (component.Lock, error) {
func (cmd *CacheCompiledReleases) uploadLocalRelease(spec cargo.BOSHReleaseTarballSpecification, fp string, uploader ReleaseStorage) (cargo.BOSHReleaseTarballLock, error) {
f, err := cmd.FS.Open(fp)
if err != nil {
return component.Lock{}, err
return cargo.BOSHReleaseTarballLock{}, err
}
defer closeAndIgnoreError(f)
return uploader.UploadRelease(spec, f)
Expand Down Expand Up @@ -393,7 +393,7 @@ func (cmd *CacheCompiledReleases) saveReleaseLocally(director boshdir.Director,
return filePath, sha256sumString, sha1sumString, nil
}

func (cmd *CacheCompiledReleases) downloadAndComputeSHA(cache component.ReleaseSource, remote cargo.ComponentLock) (string, error) {
func (cmd *CacheCompiledReleases) downloadAndComputeSHA(cache component.ReleaseSource, remote cargo.BOSHReleaseTarballLock) (string, error) {
if remote.SHA1 != "" {
return remote.SHA1, nil
}
Expand All @@ -414,7 +414,7 @@ func (cmd *CacheCompiledReleases) downloadAndComputeSHA(cache component.ReleaseS
return "", fmt.Errorf("failed to download release: %s", err)
}

return comp.SHA1, nil
return comp.Lock.SHA1, nil
}

func (cmd *CacheCompiledReleases) Usage() jhanda.Usage {
Expand Down
44 changes: 22 additions & 22 deletions internal/commands/cache_compiled_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,25 @@ func newCacheCompiledReleasesTestData(t *testing.T, kf cargo.Kilnfile, kl cargo.
logger := log.New(&output, "", 0)

releaseStorage := new(fakes.ReleaseStorage)
releaseStorage.GetMatchedReleaseCalls(func(spec component.Spec) (component.Lock, error) {
releaseStorage.GetMatchedReleaseCalls(func(spec cargo.BOSHReleaseTarballSpecification) (cargo.BOSHReleaseTarballLock, error) {
switch spec.Lock() {
case component.Lock{Name: "orange", Version: "1.0.0", StemcellOS: "alpine", StemcellVersion: "9.0.0"}:
return component.Lock{
case cargo.BOSHReleaseTarballLock{Name: "orange", Version: "1.0.0", StemcellOS: "alpine", StemcellVersion: "9.0.0"}:
return cargo.BOSHReleaseTarballLock{
Name: "orange", Version: "1.0.0",
SHA1: "fake-checksum",
RemoteSource: "cached-compiled-releases",
RemotePath: "orange-1.0.0-alpine-9.0.0",
}, nil
case component.Lock{Name: "banana", Version: "2.0.0", StemcellOS: "alpine", StemcellVersion: "9.0.0"}:
return component.Lock{
case cargo.BOSHReleaseTarballLock{Name: "banana", Version: "2.0.0", StemcellOS: "alpine", StemcellVersion: "9.0.0"}:
return cargo.BOSHReleaseTarballLock{
Name: "banana", Version: "2.0.0",
SHA1: "fake-checksum",
RemoteSource: "cached-compiled-releases",
RemotePath: "banana-2.0.0-alpine-9.0.0",
}, nil
case component.Lock{Name: "lemon", Version: "3.0.0", StemcellOS: "alpine", StemcellVersion: "9.0.0"},
component.Lock{Name: "banana", Version: "2.0.0", StemcellOS: "alpine", StemcellVersion: "8.0.0"}:
return component.Lock{}, component.ErrNotFound
case cargo.BOSHReleaseTarballLock{Name: "lemon", Version: "3.0.0", StemcellOS: "alpine", StemcellVersion: "9.0.0"},
cargo.BOSHReleaseTarballLock{Name: "banana", Version: "2.0.0", StemcellOS: "alpine", StemcellVersion: "8.0.0"}:
return cargo.BOSHReleaseTarballLock{}, component.ErrNotFound
}

panic(fmt.Sprintf("unexpected spec %#v", spec))
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestCacheCompiledReleases_Execute_all_releases_are_already_compiled(t *test
},
},
}, cargo.KilnfileLock{
Releases: []cargo.ComponentLock{
Releases: []cargo.BOSHReleaseTarballLock{
{
Name: "banana",
Version: "2.0.0",
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestCacheCompiledReleases_Execute_all_releases_are_already_cached(t *testin
},
},
}, cargo.KilnfileLock{
Releases: []cargo.ComponentLock{
Releases: []cargo.BOSHReleaseTarballLock{
{
Name: "orange",
Version: "1.0.0",
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestCacheCompiledReleases_Execute_all_releases_are_already_cached(t *testin

var updatedKilnfile cargo.KilnfileLock
please.Expect(fsReadYAML(test.cmd.FS, "Kilnfile.lock", &updatedKilnfile)).NotTo(HaveOccurred())
please.Expect(updatedKilnfile.Releases).To(ContainElement(component.Lock{
please.Expect(updatedKilnfile.Releases).To(ContainElement(cargo.BOSHReleaseTarballLock{
Name: "orange", Version: "1.0.0",
SHA1: "fake-checksum",
RemoteSource: "cached-compiled-releases",
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestCacheCompiledReleases_Execute_when_one_release_is_cached_another_is_alr
},
},
}, cargo.KilnfileLock{
Releases: []cargo.ComponentLock{
Releases: []cargo.BOSHReleaseTarballLock{
{
Name: "orange",
Version: "1.0.0",
Expand Down Expand Up @@ -288,9 +288,9 @@ func TestCacheCompiledReleases_Execute_when_one_release_is_cached_another_is_alr
}

var uploadedRelease bytes.Buffer
test.releaseStorage.UploadReleaseCalls(func(_ component.Spec, reader io.Reader) (component.Lock, error) {
test.releaseStorage.UploadReleaseCalls(func(_ cargo.BOSHReleaseTarballSpecification, reader io.Reader) (cargo.BOSHReleaseTarballLock, error) {
_, _ = io.Copy(&uploadedRelease, reader)
return component.Lock{
return cargo.BOSHReleaseTarballLock{
Name: "lemon", Version: "3.0.0",

RemoteSource: "cached-compiled-releases",
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestCacheCompiledReleases_Execute_when_one_release_is_cached_another_is_alr

var updatedKilnfile cargo.KilnfileLock
please.Expect(fsReadYAML(test.cmd.FS, "Kilnfile.lock", &updatedKilnfile)).NotTo(HaveOccurred())
please.Expect(updatedKilnfile.Releases).To(ContainElement(component.Lock{
please.Expect(updatedKilnfile.Releases).To(ContainElement(cargo.BOSHReleaseTarballLock{
Name: "lemon",
Version: "3.0.0",
SHA1: "012ed191f1d07c14bbcbbc0423d0de1c56757348",
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestCacheCompiledReleases_Execute_when_a_release_is_not_compiled_with_the_c
},
},
}, cargo.KilnfileLock{
Releases: []cargo.ComponentLock{
Releases: []cargo.BOSHReleaseTarballLock{
{
Name: "banana",
Version: "2.0.0",
Expand Down Expand Up @@ -418,7 +418,7 @@ func TestCacheCompiledReleases_Execute_when_a_release_is_not_compiled_with_the_c

var updatedKilnfile cargo.KilnfileLock
please.Expect(fsReadYAML(test.cmd.FS, "Kilnfile.lock", &updatedKilnfile)).NotTo(HaveOccurred())
please.Expect(updatedKilnfile.Releases).To(ContainElement(component.Lock{
please.Expect(updatedKilnfile.Releases).To(ContainElement(cargo.BOSHReleaseTarballLock{
Name: "banana",
Version: "2.0.0",

Expand Down Expand Up @@ -448,13 +448,13 @@ func TestCacheCompiledReleases_Execute_when_a_release_has_no_packages(t *testing
PathTemplate: "{{.Release}}-{{.Version}}.tgz",
},
},
Releases: []cargo.ComponentSpec{
Releases: []cargo.BOSHReleaseTarballSpecification{
{
Name: "banana",
},
},
}, cargo.KilnfileLock{
Releases: []cargo.ComponentLock{
Releases: []cargo.BOSHReleaseTarballLock{
{
Name: "banana",
Version: "2.0.0",
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestCacheCompiledReleases_Execute_when_a_release_has_no_packages(t *testing
}, nil
}
}
test.releaseStorage.UploadReleaseStub = func(spec cargo.ComponentSpec, reader io.Reader) (cargo.ComponentLock, error) {
test.releaseStorage.UploadReleaseStub = func(spec cargo.BOSHReleaseTarballSpecification, reader io.Reader) (cargo.BOSHReleaseTarballLock, error) {
l := spec.Lock()
l.RemotePath = "BANANA.tgz"
l.RemoteSource = "BASKET"
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestCacheCompiledReleases_Execute_when_a_release_has_no_packages(t *testing

var updatedKilnfile cargo.KilnfileLock
please.Expect(fsReadYAML(test.cmd.FS, "Kilnfile.lock", &updatedKilnfile)).NotTo(HaveOccurred())
please.Expect(updatedKilnfile.Releases).To(ContainElement(component.Lock{
please.Expect(updatedKilnfile.Releases).To(ContainElement(cargo.BOSHReleaseTarballLock{
Name: "banana",
Version: "2.0.0",

Expand All @@ -542,7 +542,7 @@ func TestCacheCompiledReleases_Execute_staged_and_lock_stemcells_are_not_the_sam
// setup

initialLock := cargo.KilnfileLock{
Releases: []component.Lock{
Releases: []cargo.BOSHReleaseTarballLock{
{
Name: "orange",
Version: "1.0.0",
Expand Down
Loading