Skip to content

Commit

Permalink
Merge branch 'EngineerBetter-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
drich10 committed Aug 26, 2018
2 parents 4a53934 + 6b373f9 commit 42699c4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 34 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BOSH Deployment Resource

A resource that will deploy releases and stemcells using the [BOSH CLI v2](https://bosh.io/docs/cli-v2.html).
A resource that will deploy releases and stemcells using the [BOSH CLI v2](https://bosh.io/docs/cli-v2.html).

## Differences from original BOSH Deployment Resource

Expand All @@ -16,7 +16,7 @@ uses the Ruby CLI and does not support newer BOSH features.

To use the BOSH Deployment Resource, you must declare it in your pipeline as a resource type:

```
```yaml
resource_types:
- name: bosh-deployment
type: docker-image
Expand All @@ -41,7 +41,7 @@ resource_types:
* `vars_store`: *Optional.* Configuration for a persisted variables store. Currently only the Google Cloud Storage (GCS)
provider is supported. `json_key` must be the the JSON key for your service account. Example:

```
```yaml
provider: gcs
config:
bucket: my-bucket
Expand Down Expand Up @@ -81,15 +81,15 @@ _Notes_:

#### Example

```
```yaml
- put: staging
params:
source_file: path/to/sourcefile
```

Sample source file:

```
```json
{
"target": "dynamic-director.example.com",
"client_secret": "generated-secret",
Expand All @@ -114,14 +114,17 @@ _Note_: Only the most recent version is fetchable

#### Parameters

* `compiled_releases`: *Optional.* List of compiled releases to download. Deployment can only have one stemcell.
* `compiled_releases`: *Optional.* List of compiled releases to download and optionally specified jobs. Deployment can only have one stemcell.

``` yaml
- get: staging
params:
compiled_releases:
- name: release-one
- name: release-two
jobs:
- job-one
- job-two
```

### `out`: Deploy or Delete a BOSH deployment (defaults to deploy)
Expand All @@ -139,8 +142,8 @@ deployment manifest and then deploy.
stemcell versions.

* `releases`: *Optional.* An array of globs that should point to where the
releases used in the deployment can be found. Release entries in the
manifest with version 'latest' will be updated to the actual provided
releases used in the deployment can be found. Release entries in the
manifest with version 'latest' will be updated to the actual provided
release versions.

* `vars`: *Optional.* A collection of variables to be set in the deployment manifest.
Expand Down
14 changes: 7 additions & 7 deletions bosh/boshfakes/fake_director.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions bosh/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ type InterpolateParams struct {
VarsStore string
}

type ReleaseSpec struct {
Name string
Jobs []string
}

//go:generate counterfeiter . Director
type Director interface {
Delete(force bool) error
Deploy(manifestBytes []byte, deployParams DeployParams) error
Interpolate(manifestBytes []byte, interpolateParams InterpolateParams) ([]byte, error)
DownloadManifest() ([]byte, error)
ExportReleases(targetDirectory string, releases []string) error
ExportReleases(targetDirectory string, releases []ReleaseSpec) error
UploadRelease(releaseURL string) error
UploadStemcell(stemcellURL string) error
WaitForDeployLock() error
Expand Down Expand Up @@ -215,7 +220,7 @@ func (d BoshDirector) deploymentIsLocked() (bool, error) {
return false, nil
}

func (d BoshDirector) ExportReleases(targetDirectory string, releases []string) error {
func (d BoshDirector) ExportReleases(targetDirectory string, releases []ReleaseSpec) error {
deploymentReleases, stemcell, err := d.releasesAndStemcell()
if err != nil {
return fmt.Errorf("could not export releases: %s", err)
Expand All @@ -226,18 +231,18 @@ func (d BoshDirector) ExportReleases(targetDirectory string, releases []string)
for _, release := range releases {
foundRelease := false
for _, deploymentRelease := range deploymentReleases {
if deploymentRelease.Name() == release {
if deploymentRelease.Name() == release.Name {
releasesToDownload = append(releasesToDownload, deploymentRelease)
foundRelease = true
}
}

if !foundRelease {
return fmt.Errorf("could not find release %s in deployment", release)
return fmt.Errorf("could not find release %s in deployment", release.Name)
}
}

for _, deploymentRelease := range releasesToDownload {
for i, deploymentRelease := range releasesToDownload {
releaseSlug := boshdir.NewReleaseSlug(deploymentRelease.Name(), deploymentRelease.Version().AsString())
osVersionSlug := boshdir.NewOSVersionSlug(stemcell.OSName(), stemcell.Version().AsString())

Expand All @@ -253,6 +258,7 @@ func (d BoshDirector) ExportReleases(targetDirectory string, releases []string)
}
err = d.commandRunner.ExecuteWithDefaultOverride(&boshcmd.ExportReleaseOpts{
Args: boshcmd.ExportReleaseArgs{ReleaseSlug: releaseSlug, OSVersionSlug: osVersionSlug},
Jobs: releases[i].Jobs,
Directory: directory,
}, directoryFixFunction, nil)
if err != nil {
Expand Down
47 changes: 38 additions & 9 deletions bosh/director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,16 @@ var _ = Describe("BoshDirector", func() {
})

It("downloads the given releases", func() {
err := director.ExportReleases("/tmp/foo", []string{"cool-release", "awesome-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
{
Name: "awesome-release",
Jobs: []string{
"nice-job",
"well-done",
},
},
})
Expect(err).ToNot(HaveOccurred())

Expect(fakeBoshDirector.FindDeploymentCallCount()).To(Equal(1))
Expand All @@ -415,11 +424,19 @@ var _ = Describe("BoshDirector", func() {
Expect(string(exportReleaseOpts.Args.ReleaseSlug.Version())).To(Equal("987.65"))
Expect(string(exportReleaseOpts.Args.OSVersionSlug.OS())).To(Equal("minix"))
Expect(string(exportReleaseOpts.Args.OSVersionSlug.Version())).To(Equal("3.4.0"))
Expect(exportReleaseOpts.Jobs).To(Equal([]string{
"nice-job",
"well-done",
}))
})

Context("when requesting a release not in the manifest", func() {
It("errors before downloading any releases", func() {
err := director.ExportReleases("/tmp/foo", []string{"cool-release", "awesome-release", "missing-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
{Name: "awesome-release"},
{Name: "missing-release"},
})
Expect(err).To(MatchError(ContainSubstring("could not find release missing-release")))

Expect(commandRunner.ExecuteCallCount()).To(Equal(0))
Expand All @@ -429,8 +446,10 @@ var _ = Describe("BoshDirector", func() {
Context("when there is more than one stemcell in the manifest", func() {
It("errors before downloading any releases", func() {
fakeDeployment.StemcellsReturns([]boshdir.Stemcell{fakeDeploymentStemcell, fakeDeploymentStemcell}, nil)

err := director.ExportReleases("/tmp/foo", []string{"cool-release", "awesome-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
{Name: "awesome-release"},
})
Expect(err).To(MatchError(ContainSubstring("exporting releases from a deployment with multiple stemcells is unsupported")))

Expect(commandRunner.ExecuteCallCount()).To(Equal(0))
Expand All @@ -441,7 +460,9 @@ var _ = Describe("BoshDirector", func() {
It("returns an error", func() {
fakeBoshDirector.FindDeploymentReturns(fakeDeployment, errors.New("foo"))

err := director.ExportReleases("/tmp/foo", []string{"cool-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
})
Expect(err).To(MatchError(ContainSubstring("could not export releases: could not fetch deployment cool-deployment: foo")))
})
})
Expand All @@ -450,7 +471,9 @@ var _ = Describe("BoshDirector", func() {
It("returns an error", func() {
commandRunner.ExecuteWithDefaultOverrideReturns(errors.New("failed communicating with director"))

err := director.ExportReleases("/tmp/foo", []string{"cool-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
})
Expect(err).To(MatchError(ContainSubstring("could not export release cool-release: failed communicating with director")))
})
})
Expand All @@ -459,7 +482,9 @@ var _ = Describe("BoshDirector", func() {
It("returns an error", func() {
fakeDeployment.ReleasesReturns([]boshdir.Release{}, errors.New("foo"))

err := director.ExportReleases("/tmp/foo", []string{"cool-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
})
Expect(err).To(MatchError(ContainSubstring("could not export releases: could not fetch releases: foo")))
})
})
Expand All @@ -469,7 +494,9 @@ var _ = Describe("BoshDirector", func() {
It("returns an error", func() {
fakeDeployment.StemcellsReturns([]boshdir.Stemcell{}, errors.New("foo"))

err := director.ExportReleases("/tmp/foo", []string{"cool-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
})
Expect(err).To(MatchError(ContainSubstring("could not export releases: could not fetch stemcells: foo")))
})
})
Expand All @@ -478,7 +505,9 @@ var _ = Describe("BoshDirector", func() {
It("returns an error", func() {
fakeBoshDirector.StemcellsReturns([]boshdir.Stemcell{}, errors.New("foo"))

err := director.ExportReleases("/tmp/foo", []string{"cool-release"})
err := director.ExportReleases("/tmp/foo", []bosh.ReleaseSpec{
{Name: "cool-release"},
})
Expect(err).To(MatchError(ContainSubstring("could not export releases: could not fetch stemcells: foo")))
})
})
Expand Down
3 changes: 2 additions & 1 deletion concourse/in_params.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package concourse

type CompiledRelease struct {
Name string `json:"name"`
Name string `json:"name"`
Jobs []string `json:"jobs"`
}

type InParams struct {
Expand Down
7 changes: 5 additions & 2 deletions in/in_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ func (c InCommand) Run(inRequest concourse.InRequest, targetDir string) (InRespo
}

if len(inRequest.Params.CompiledReleases) > 0 {
releases := []string{}
var releases []bosh.ReleaseSpec
for _, compiledRelease := range inRequest.Params.CompiledReleases {
releases = append(releases, compiledRelease.Name)
releases = append(releases, bosh.ReleaseSpec{
Name: compiledRelease.Name,
Jobs: compiledRelease.Jobs,
})
}
if err := c.director.ExportReleases(targetDir, releases); err != nil {
return InResponse{}, err
Expand Down
14 changes: 12 additions & 2 deletions in/in_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"path/filepath"

"github.com/cloudfoundry/bosh-deployment-resource/bosh"
"github.com/cloudfoundry/bosh-deployment-resource/bosh/boshfakes"
"github.com/cloudfoundry/bosh-deployment-resource/concourse"
"github.com/cloudfoundry/bosh-deployment-resource/in"
Expand Down Expand Up @@ -138,7 +139,10 @@ var _ = Describe("InCommand", func() {
inRequest.Version.ManifestSha1 = fmt.Sprintf("%x", sha1.Sum(manifest))
inRequest.Params.CompiledReleases = []concourse.CompiledRelease{
{Name: "real-one"},
{Name: "real-two"},
{
Name: "real-two",
Jobs: []string{"nice-job"},
},
}
})

Expand All @@ -150,7 +154,13 @@ var _ = Describe("InCommand", func() {

targetDir, releases := director.ExportReleasesArgsForCall(0)
Expect(targetDir).To(Equal(targetDir))
Expect(releases).To(Equal([]string{"real-one", "real-two"}))
Expect(releases).To(Equal([]bosh.ReleaseSpec{
{Name: "real-one"},
{
Name: "real-two",
Jobs: []string{"nice-job"},
},
}))
})

Context("when exporting releases fails", func() {
Expand Down

0 comments on commit 42699c4

Please sign in to comment.