Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Add --release-build flag to filter out "dev-only" roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Utinski committed Apr 10, 2019
1 parent 588d41a commit 4c4c56f
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 20 deletions.
16 changes: 8 additions & 8 deletions app/fissile.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (f *Fissile) collectProperties() map[string]map[string]map[string]interface
}

// Compile will compile a list of dev BOSH releases
func (f *Fissile) Compile(repository, targetPath, roleManifestPath, metricsPath string, workerCount int) error {
func (f *Fissile) Compile(repository, targetPath, roleManifestPath, metricsPath string, workerCount int, skipDev bool) error {
if len(f.releases) == 0 {
return fmt.Errorf("Releases not loaded")
}
Expand All @@ -312,7 +312,7 @@ func (f *Fissile) Compile(repository, targetPath, roleManifestPath, metricsPath
return fmt.Errorf("Error connecting to docker: %s", err.Error())
}

roleManifest, err := model.LoadRoleManifest(roleManifestPath, f.releases)
roleManifest, err := model.LoadRoleManifest(roleManifestPath, f.releases, skipDev)
if err != nil {
return fmt.Errorf("Error loading roles manifest: %s", err.Error())
}
Expand Down Expand Up @@ -444,7 +444,7 @@ func (f *Fissile) GeneratePackagesRoleImage(repository string, roleManifest *mod
}

// GenerateRoleImages generates all role images using dev releases
func (f *Fissile) GenerateRoleImages(targetPath, repository, metricsPath string, noBuild, force bool, workerCount int, rolesManifestPath, compiledPackagesPath, lightManifestPath, darkManifestPath string) error {
func (f *Fissile) GenerateRoleImages(targetPath, repository, metricsPath string, noBuild, force bool, workerCount int, rolesManifestPath, compiledPackagesPath, lightManifestPath, darkManifestPath string, skipDev bool) error {
if len(f.releases) == 0 {
return fmt.Errorf("Releases not loaded")
}
Expand All @@ -454,7 +454,7 @@ func (f *Fissile) GenerateRoleImages(targetPath, repository, metricsPath string,
defer stampy.Stamp(metricsPath, "fissile", "create-role-images", "done")
}

roleManifest, err := model.LoadRoleManifest(rolesManifestPath, f.releases)
roleManifest, err := model.LoadRoleManifest(rolesManifestPath, f.releases, skipDev)
if err != nil {
return fmt.Errorf("Error loading roles manifest: %s", err.Error())
}
Expand Down Expand Up @@ -500,7 +500,7 @@ func (f *Fissile) GenerateRoleImages(targetPath, repository, metricsPath string,
}

// ListRoleImages lists all dev role images
func (f *Fissile) ListRoleImages(repository string, rolesManifestPath string, existingOnDocker, withVirtualSize bool) error {
func (f *Fissile) ListRoleImages(repository string, rolesManifestPath string, existingOnDocker, withVirtualSize bool, skipDev bool) error {
if withVirtualSize && !existingOnDocker {
return fmt.Errorf("Cannot list image virtual sizes if not matching image names with docker")
}
Expand All @@ -519,7 +519,7 @@ func (f *Fissile) ListRoleImages(repository string, rolesManifestPath string, ex
}
}

rolesManifest, err := model.LoadRoleManifest(rolesManifestPath, f.releases)
rolesManifest, err := model.LoadRoleManifest(rolesManifestPath, f.releases, skipDev)
if err != nil {
return fmt.Errorf("Error loading roles manifest: %s", err.Error())
}
Expand Down Expand Up @@ -718,9 +718,9 @@ func compareHashes(v1Hash, v2Hash keyHash) *HashDiffs {

// GenerateKube will create a set of configuration files suitable for deployment
// on Kubernetes
func (f *Fissile) GenerateKube(rolesManifestPath, outputDir, repository, registry, organization string, defaultFiles []string, useMemoryLimits bool) error {
func (f *Fissile) GenerateKube(rolesManifestPath, outputDir, repository, registry, organization string, defaultFiles []string, useMemoryLimits bool, skipDev bool) error {

rolesManifest, err := model.LoadRoleManifest(rolesManifestPath, f.releases)
rolesManifest, err := model.LoadRoleManifest(rolesManifestPath, f.releases, skipDev)
if err != nil {
return fmt.Errorf("Error loading roles manifest: %s", err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions cmd/build-images.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ from other specs. At most one is allowed. Its syntax is --patch-properties-rel
workPathCompilationDir,
flagLightOpinions,
flagDarkOpinions,
flagReleaseBuild,
)
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/build-kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var buildKubeCmd = &cobra.Command{
flagBuildKubeDockerOrganization,
flagBuildKubeDefaultEnvFiles,
flagBuildKubeUseMemoryLimits,
flagReleaseBuild,
)

},
Expand Down
1 change: 1 addition & 0 deletions cmd/build-packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ compiled once.
flagRoleManifest,
flagMetrics,
flagWorkers,
flagReleaseBuild,
)
},
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
flagDarkOpinions string
flagOutputFormat string
flagMetrics string
flagReleaseBuild bool

// workPath* variables contain paths derived from flagWorkDir
workPathCompilationDir string
Expand Down Expand Up @@ -165,6 +166,13 @@ func init() {
"Choose output format, one of human, json, or yaml (currently only for 'show properties')",
)

buildImagesCmd.PersistentFlags().BoolP(
"release-build",
"R",
false,
"Indicates final release build (all roles tagged as \"dev-only\" will be omitted)",
)

viper.BindPFlags(RootCmd.PersistentFlags())
}

Expand Down Expand Up @@ -230,6 +238,7 @@ func validateBasicFlags() error {
flagDarkOpinions = viper.GetString("dark-opinions")
flagOutputFormat = viper.GetString("output")
flagMetrics = viper.GetString("metrics")
flagReleaseBuild = viper.GetBool("release-build")

extendPathsFromWorkDirectory()

Expand Down
1 change: 1 addition & 0 deletions cmd/show-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This command is useful in conjunction with docker (e.g. ` + "`docker rmi $(fissi
flagRoleManifest,
flagShowImageDockerOnly,
flagShowImageWithSizes,
flagReleaseBuild,
)
},
}
Expand Down
2 changes: 1 addition & 1 deletion model/mustache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRoleVariables(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/tor-good.yml")
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release})
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release}, false)
assert.NoError(err)
assert.NotNil(rolesManifest)

Expand Down
17 changes: 13 additions & 4 deletions model/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (roles Roles) Swap(i, j int) {
}

// LoadRoleManifest loads a yaml manifest that details how jobs get grouped into roles
func LoadRoleManifest(manifestFilePath string, releases []*Release) (*RoleManifest, error) {
func LoadRoleManifest(manifestFilePath string, releases []*Release, skipDev bool) (*RoleManifest, error) {
manifestContents, err := ioutil.ReadFile(manifestFilePath)
if err != nil {
return nil, err
Expand Down Expand Up @@ -208,12 +208,21 @@ func LoadRoleManifest(manifestFilePath string, releases []*Release) (*RoleManife
}

// Remove all roles that are not of the "bosh" or "bosh-task" type
// or have "dev-only" tag and skipDev is true
// Default type is considered to be "bosh"
switch role.Type {
case "":
if role.Type == "" {
role.Type = RoleTypeBosh
}

switch role.Type {
case RoleTypeBosh, RoleTypeBoshTask:
continue
if skipDev {
for _, tag := range role.Tags {
if strings.EqualFold(tag, "dev-only") {
rolesManifest.Roles = append(rolesManifest.Roles[:i], rolesManifest.Roles[i+1:]...)
}
}
}
case RoleTypeDocker:
rolesManifest.Roles = append(rolesManifest.Roles[:i], rolesManifest.Roles[i+1:]...)
default:
Expand Down
34 changes: 27 additions & 7 deletions model/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestLoadRoleManifestOK(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/tor-good.yml")
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release})
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release}, false)
assert.NoError(err)
assert.NotNil(rolesManifest)

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestGetScriptPaths(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/tor-good.yml")
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release})
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release}, false)
assert.NoError(err)
assert.NotNil(rolesManifest)

Expand All @@ -76,7 +76,7 @@ func TestLoadRoleManifestNotOKBadJobName(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/tor-bad.yml")
_, err = LoadRoleManifest(roleManifestPath, []*Release{release})
_, err = LoadRoleManifest(roleManifestPath, []*Release{release}, false)
assert.NotNil(err)
assert.Contains(err.Error(), "Cannot find job foo in release")
}
Expand All @@ -93,7 +93,7 @@ func TestLoadDuplicateReleases(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/tor-good.yml")
_, err = LoadRoleManifest(roleManifestPath, []*Release{release, release})
_, err = LoadRoleManifest(roleManifestPath, []*Release{release, release}, false)

assert.NotNil(err)
assert.Contains(err.Error(), "release tor has been loaded more than once")
Expand All @@ -116,7 +116,7 @@ func TestLoadRoleManifestMultipleReleasesOK(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/multiple-good.yml")
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{ntpRelease, torRelease})
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{ntpRelease, torRelease}, false)
assert.NoError(err)
assert.NotNil(rolesManifest)

Expand Down Expand Up @@ -151,7 +151,7 @@ func TestLoadRoleManifestMultipleReleasesNotOk(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/multiple-bad.yml")
_, err = LoadRoleManifest(roleManifestPath, []*Release{ntpRelease, torRelease})
_, err = LoadRoleManifest(roleManifestPath, []*Release{ntpRelease, torRelease}, false)

assert.NotNil(err)
assert.Contains(err.Error(), "release foo has not been loaded and is referenced by job ntpd in role foorole")
Expand All @@ -169,7 +169,27 @@ func TestNonBoshRolesAreIgnoredOK(t *testing.T) {
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/non-bosh-roles.yml")
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release})
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release}, false)
assert.NoError(err)
assert.NotNil(rolesManifest)

assert.Equal(roleManifestPath, rolesManifest.manifestFilePath)
assert.Len(rolesManifest.Roles, 2)
}

func TestDevOnlyRolesAreIgnoredOK(t *testing.T) {
assert := assert.New(t)

workDir, err := os.Getwd()
assert.NoError(err)

torReleasePath := filepath.Join(workDir, "../test-assets/tor-boshrelease")
torReleasePathBoshCache := filepath.Join(torReleasePath, "bosh-cache")
release, err := NewDevRelease(torReleasePath, "", "", torReleasePathBoshCache)
assert.NoError(err)

roleManifestPath := filepath.Join(workDir, "../test-assets/role-manifests/dev-only-roles.yml")
rolesManifest, err := LoadRoleManifest(roleManifestPath, []*Release{release}, true)
assert.NoError(err)
assert.NotNil(rolesManifest)

Expand Down
28 changes: 28 additions & 0 deletions test-assets/role-manifests/dev-only-roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
roles:
- name: myrole
scripts: ["myrole.sh"]
jobs:
- name: new_hostname
release_name: tor
- name: tor
release_name: tor
- name: foorole
type: bosh-task
jobs:
- name: tor
release_name: tor
- name: devrole1
tags: ["dev-only"]
scripts: ["myrole.sh"]
jobs:
- name: new_hostname
release_name: tor
- name: tor
release_name: tor
- name: devrole2
type: bosh-task
tags: ["dev-only"]
jobs:
- name: tor
release_name: tor

0 comments on commit 4c4c56f

Please sign in to comment.