Skip to content

Commit 498ccb3

Browse files
authored
Merge pull request #78 from cloud66-oss/feature/3517-bundle-flag
Changed folder name and added field to BTR object
2 parents 4db43cc + 67c5964 commit 498ccb3

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

bundle/bundle-writer.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type BundleConfiguration struct {
3636
}
3737

3838
type BundleBaseTemplates struct {
39+
Name string `json:"name"`
3940
Repo string `json:"repo"`
4041
Branch string `json:"branch"`
4142
Stencils []*BundleStencil `json:"stencils"`
@@ -118,9 +119,9 @@ func CreateSkycapFiles(outputDir string,
118119
}
119120
//Create .bundle directory structure if it doesn't exist
120121
tempFolder := os.TempDir()
121-
skycapFolder := filepath.Join(tempFolder, "skycap")
122-
defer os.RemoveAll(skycapFolder)
123-
err := createBundleFolderStructure(skycapFolder)
122+
bundleFolder := filepath.Join(tempFolder, "bundle")
123+
defer os.RemoveAll(bundleFolder)
124+
err := createBundleFolderStructure(bundleFolder)
124125
if err != nil {
125126
return err
126127
}
@@ -130,7 +131,7 @@ func CreateSkycapFiles(outputDir string,
130131
return err
131132
}
132133

133-
manifestFile, err = saveEnvVars(packName, getEnvVars(services, databases), manifestFile, skycapFolder)
134+
manifestFile, err = saveEnvVars(packName, getEnvVars(services, databases), manifestFile, bundleFolder)
134135
if err != nil {
135136
return err
136137
}
@@ -142,7 +143,7 @@ func CreateSkycapFiles(outputDir string,
142143
branch,
143144
outputDir,
144145
services,
145-
skycapFolder,
146+
bundleFolder,
146147
manifestFile,
147148
githubURL)
148149

@@ -156,18 +157,18 @@ func CreateSkycapFiles(outputDir string,
156157
return err
157158
}
158159

159-
err = saveManifest(skycapFolder, manifestFile)
160+
err = saveManifest(bundleFolder, manifestFile)
160161
if err != nil {
161162
return err
162163
}
163164

164165
// tarball
165-
err = os.RemoveAll(filepath.Join(skycapFolder, "temp"))
166+
err = os.RemoveAll(filepath.Join(bundleFolder, "temp"))
166167
if err != nil {
167168
common.PrintError(err.Error())
168169
}
169170

170-
err = common.Tar(skycapFolder, filepath.Join(outputDir, "starter.bundle"))
171+
err = common.Tar(bundleFolder, filepath.Join(outputDir, "starter.bundle"))
171172
if err != nil {
172173
common.PrintError(err.Error())
173174
}
@@ -214,7 +215,7 @@ func getRequiredStencils(templateRepository string,
214215
branch string,
215216
outputDir string,
216217
services []*common.Service,
217-
skycapFolder string,
218+
bundleFolder string,
218219
manifestFile *ManifestBundle,
219220
githubURL string) (*ManifestBundle, error) {
220221

@@ -256,7 +257,7 @@ func getRequiredStencils(templateRepository string,
256257
service.Name,
257258
stencil,
258259
manifestFile,
259-
skycapFolder,
260+
bundleFolder,
260261
templateRepository,
261262
branch,
262263
manifestStencils)
@@ -268,14 +269,15 @@ func getRequiredStencils(templateRepository string,
268269
"",
269270
stencil,
270271
manifestFile,
271-
skycapFolder,
272+
bundleFolder,
272273
templateRepository,
273274
branch,
274275
manifestStencils)
275276
}
276277
}
277278
}
278279
var newTemplate BundleBaseTemplates
280+
newTemplate.Name = templJSON.Name
279281
newTemplate.Repo = githubURL
280282
newTemplate.Branch = branch
281283
newTemplate.Stencils = manifestStencils
@@ -301,18 +303,18 @@ func loadManifest() (*ManifestBundle, error) {
301303
return manifest, nil
302304
}
303305

304-
func saveManifest(skycapFolder string, content *ManifestBundle) error {
306+
func saveManifest(bundleFolder string, content *ManifestBundle) error {
305307
out, err := json.MarshalIndent(content, "", " ")
306308
if err != nil {
307309
return err
308310
}
309-
manifestPath := filepath.Join(skycapFolder, "manifest.json")
311+
manifestPath := filepath.Join(bundleFolder, "manifest.json")
310312
return ioutil.WriteFile(manifestPath, out, 0600)
311313
}
312314

313-
func saveEnvVars(prefix string, envVars map[string]string, manifestFile *ManifestBundle, skycapFolder string) (*ManifestBundle, error) {
315+
func saveEnvVars(prefix string, envVars map[string]string, manifestFile *ManifestBundle, bundleFolder string) (*ManifestBundle, error) {
314316
filename := prefix + "-config"
315-
varsPath := filepath.Join(filepath.Join(skycapFolder, "configurations"), prefix+"-config")
317+
varsPath := filepath.Join(filepath.Join(bundleFolder, "configurations"), prefix+"-config")
316318
var fileOut string
317319
for key, value := range envVars {
318320
fileOut = fileOut + key + "=" + value + "\n"
@@ -329,7 +331,7 @@ func saveEnvVars(prefix string, envVars map[string]string, manifestFile *Manifes
329331
func downloadAndAddStencil(context string,
330332
stencil *StencilTemplate,
331333
manifestFile *ManifestBundle,
332-
skycapFolder string,
334+
bundleFolder string,
333335
templateRepository string,
334336
branch string,
335337
manifestStencils []*BundleStencil) (*ManifestBundle, []*BundleStencil, error) {
@@ -341,7 +343,7 @@ func downloadAndAddStencil(context string,
341343

342344
//download the stencil file
343345
stencilPath := templateRepository + "stencils/" + stencil.Filename // don't need to use filepath since it's a URL
344-
stencilsFolder := filepath.Join(skycapFolder, "stencils")
346+
stencilsFolder := filepath.Join(bundleFolder, "stencils")
345347
downErr := common.DownloadSingleFile(stencilsFolder, common.DownloadFile{URL: stencilPath, Name: filename}, branch)
346348
if downErr != nil {
347349
return nil, nil, downErr

0 commit comments

Comments
 (0)