@@ -57,11 +57,11 @@ RUN {{$value}}
57
57
{{end}}
58
58
`
59
59
60
- // Entry is used to format templates
61
- type entry struct {
60
+ // richSpecs is used to format templates
61
+ type richSpecs struct {
62
+ types.Specs
62
63
Command string
63
64
Appdir string
64
- Appname string
65
65
UID string
66
66
}
67
67
@@ -154,10 +154,11 @@ func (c *calcium) BuildImage(repository, version, uid, artifact string) (chan *t
154
154
}
155
155
156
156
// create launcher scripts and dockerfile
157
- if err := createLauncher (c .config .AppDir , buildDir , uid , specs ); err != nil {
157
+ rs := richSpecs {specs , "" , strings .TrimRight (c .config .AppDir , "/" ), uid }
158
+ if err := createLauncher (buildDir , rs ); err != nil {
158
159
return ch , err
159
160
}
160
- if err := createDockerfile (buildDir , uid , reponame , specs ); err != nil {
161
+ if err := createDockerfile (buildDir , reponame , rs ); err != nil {
161
162
return ch , err
162
163
}
163
164
@@ -255,19 +256,19 @@ func createTarStream(path string) (io.ReadCloser, error) {
255
256
}
256
257
257
258
// launcher scripts
258
- func createLauncher (appDir , buildDir , uid string , specs types. Specs ) error {
259
+ func createLauncher (buildDir string , rs richSpecs ) error {
259
260
launcherScriptTemplate , _ := template .New ("launcher script" ).Parse (launcherScript )
260
261
261
- entryCommand := fmt .Sprintf ("exec sudo -E -u %s $@" , specs .Appname )
262
+ entryCommand := fmt .Sprintf ("exec sudo -E -u %s $@" , rs .Appname )
262
263
entryRootCommand := "exec $@"
263
264
264
265
f , err := os .Create (filepath .Join (buildDir , "launcher" ))
265
266
if err != nil {
266
267
return err
267
268
}
268
269
defer f .Close ()
269
- appDir = strings . TrimRight ( appDir , "/" )
270
- launcherScriptTemplate .Execute (f , entry { Command : entryCommand , Appdir : appDir , Appname : specs . Appname , UID : uid } )
270
+ rs . Command = entryCommand
271
+ launcherScriptTemplate .Execute (f , rs )
271
272
if err := f .Sync (); err != nil {
272
273
return err
273
274
}
@@ -280,7 +281,8 @@ func createLauncher(appDir, buildDir, uid string, specs types.Specs) error {
280
281
return err
281
282
}
282
283
defer fr .Close ()
283
- launcherScriptTemplate .Execute (fr , entry {Command : entryRootCommand , Appdir : appDir , Appname : specs .Appname , UID : uid })
284
+ rs .Command = entryRootCommand
285
+ launcherScriptTemplate .Execute (fr , rs )
284
286
if err := fr .Sync (); err != nil {
285
287
return err
286
288
}
@@ -292,20 +294,20 @@ func createLauncher(appDir, buildDir, uid string, specs types.Specs) error {
292
294
}
293
295
294
296
// Dockerfile
295
- func createDockerfile (buildDir , uid , reponame string , specs types. Specs ) error {
297
+ func createDockerfile (buildDir , reponame string , rs richSpecs ) error {
296
298
f , err := os .Create (filepath .Join (buildDir , "Dockerfile" ))
297
299
if err != nil {
298
300
return err
299
301
}
300
302
defer f .Close ()
301
303
302
- dockerFileFormatted := fmt .Sprintf (dockerFile , reponame , uid , uid )
304
+ dockerFileFormatted := fmt .Sprintf (dockerFile , reponame , rs . UID , rs . UID )
303
305
t := template .New ("docker file template" )
304
306
parsedTemplate , err := t .Parse (dockerFileFormatted )
305
307
if err != nil {
306
308
return err
307
309
}
308
- err = parsedTemplate .Execute (f , specs )
310
+ err = parsedTemplate .Execute (f , rs )
309
311
if err != nil {
310
312
return err
311
313
}
0 commit comments