@@ -31,17 +31,20 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch
31
31
return nil , logger .Err (ctx , err )
32
32
}
33
33
log .Infof (ctx , "[BuildImage] Building image at pod %s node %s" , node .Podname , node .Name )
34
- // get refs
35
- refs := node .Engine .BuildRefs (ctx , toBuildRefOptions (opts ))
36
34
37
- var resp io.ReadCloser
35
+ var (
36
+ refs []string
37
+ resp io.ReadCloser
38
+ )
38
39
switch opts .BuildMethod {
39
40
case types .BuildFromSCM :
41
+ refs = node .Engine .BuildRefs (ctx , toBuildRefOptions (opts ))
40
42
resp , err = c .buildFromSCM (ctx , node , refs , opts )
41
43
case types .BuildFromRaw :
44
+ refs = node .Engine .BuildRefs (ctx , toBuildRefOptions (opts ))
42
45
resp , err = c .buildFromContent (ctx , node , refs , opts .Tar )
43
46
case types .BuildFromExist :
44
- node , resp , err = c .buildFromExist (ctx , refs , opts . ExistID , opts . User )
47
+ refs , node , resp , err = c .buildFromExist (ctx , opts )
45
48
default :
46
49
return nil , logger .Err (ctx , errors .WithStack (errors .New ("unknown build type" )))
47
50
}
@@ -91,22 +94,24 @@ func (c *Calcium) buildFromContent(ctx context.Context, node *types.Node, refs [
91
94
return resp , errors .WithStack (err )
92
95
}
93
96
94
- func (c * Calcium ) buildFromExist (ctx context.Context , refs []string , existID , user string ) ( node * types.Node , resp io.ReadCloser , err error ) {
95
- if node , err = c .getWorkloadNode (ctx , existID ); err != nil {
96
- return nil , nil , err
97
+ func (c * Calcium ) buildFromExist (ctx context.Context , opts * types. BuildOptions ) ( refs []string , node * types.Node , resp io.ReadCloser , err error ) {
98
+ if node , err = c .getWorkloadNode (ctx , opts . ExistID ); err != nil {
99
+ return nil , nil , nil , err
97
100
}
98
101
99
- imgID , err := node .Engine .ImageBuildFromExist (ctx , existID , refs , user )
102
+ refs = node .Engine .BuildRefs (ctx , toBuildRefOptions (opts ))
103
+
104
+ imgID , err := node .Engine .ImageBuildFromExist (ctx , opts .ExistID , refs , opts .User )
100
105
if err != nil {
101
- return nil , nil , errors .WithStack (err )
106
+ return nil , nil , nil , errors .WithStack (err )
102
107
}
103
108
104
109
buildMsg , err := json .Marshal (types.BuildImageMessage {ID : imgID })
105
110
if err != nil {
106
- return nil , nil , errors .WithStack (err )
111
+ return nil , nil , nil , errors .WithStack (err )
107
112
}
108
113
109
- return node , io .NopCloser (bytes .NewReader (buildMsg )), nil
114
+ return refs , node , io .NopCloser (bytes .NewReader (buildMsg )), nil
110
115
}
111
116
112
117
func (c * Calcium ) pushImageAndClean (ctx context.Context , resp io.ReadCloser , node * types.Node , tags []string ) (chan * types.BuildImageMessage , error ) { // nolint:unparam
0 commit comments