@@ -38,8 +38,36 @@ func (e invalidIsolationError) Error() string {
3838func (e invalidIsolationError ) InvalidParameter () {}
3939
4040func newImageBuildOptions (ctx context.Context , r * http.Request ) (* types.ImageBuildOptions , error ) {
41+ options := & types.ImageBuildOptions {
42+ Version : types .BuilderV1 , // Builder V1 is the default, but can be overridden
43+ Dockerfile : r .FormValue ("dockerfile" ),
44+ SuppressOutput : httputils .BoolValue (r , "q" ),
45+ NoCache : httputils .BoolValue (r , "nocache" ),
46+ ForceRemove : httputils .BoolValue (r , "forcerm" ),
47+ MemorySwap : httputils .Int64ValueOrZero (r , "memswap" ),
48+ Memory : httputils .Int64ValueOrZero (r , "memory" ),
49+ CPUShares : httputils .Int64ValueOrZero (r , "cpushares" ),
50+ CPUPeriod : httputils .Int64ValueOrZero (r , "cpuperiod" ),
51+ CPUQuota : httputils .Int64ValueOrZero (r , "cpuquota" ),
52+ CPUSetCPUs : r .FormValue ("cpusetcpus" ),
53+ CPUSetMems : r .FormValue ("cpusetmems" ),
54+ CgroupParent : r .FormValue ("cgroupparent" ),
55+ NetworkMode : r .FormValue ("networkmode" ),
56+ Tags : r .Form ["t" ],
57+ ExtraHosts : r .Form ["extrahosts" ],
58+ SecurityOpt : r .Form ["securityopt" ],
59+ Squash : httputils .BoolValue (r , "squash" ),
60+ Target : r .FormValue ("target" ),
61+ RemoteContext : r .FormValue ("remote" ),
62+ SessionID : r .FormValue ("session" ),
63+ BuildID : r .FormValue ("buildid" ),
64+ }
65+
66+ if runtime .GOOS != "windows" && options .SecurityOpt != nil {
67+ return nil , errdefs .InvalidParameter (errors .New ("The daemon on this platform does not support setting security options on build" ))
68+ }
69+
4170 version := httputils .VersionFromContext (ctx )
42- options := & types.ImageBuildOptions {}
4371 if httputils .BoolValue (r , "forcerm" ) && versions .GreaterThanOrEqualTo (version , "1.12" ) {
4472 options .Remove = true
4573 } else if r .FormValue ("rm" ) == "" && versions .GreaterThanOrEqualTo (version , "1.12" ) {
@@ -50,30 +78,19 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
5078 if httputils .BoolValue (r , "pull" ) && versions .GreaterThanOrEqualTo (version , "1.16" ) {
5179 options .PullParent = true
5280 }
53-
54- options .Version = types .BuilderV1 // Builder V1 is the default, but can be overridden
55- options .Dockerfile = r .FormValue ("dockerfile" )
56- options .SuppressOutput = httputils .BoolValue (r , "q" )
57- options .NoCache = httputils .BoolValue (r , "nocache" )
58- options .ForceRemove = httputils .BoolValue (r , "forcerm" )
59- options .MemorySwap = httputils .Int64ValueOrZero (r , "memswap" )
60- options .Memory = httputils .Int64ValueOrZero (r , "memory" )
61- options .CPUShares = httputils .Int64ValueOrZero (r , "cpushares" )
62- options .CPUPeriod = httputils .Int64ValueOrZero (r , "cpuperiod" )
63- options .CPUQuota = httputils .Int64ValueOrZero (r , "cpuquota" )
64- options .CPUSetCPUs = r .FormValue ("cpusetcpus" )
65- options .CPUSetMems = r .FormValue ("cpusetmems" )
66- options .CgroupParent = r .FormValue ("cgroupparent" )
67- options .NetworkMode = r .FormValue ("networkmode" )
68- options .Tags = r .Form ["t" ]
69- options .ExtraHosts = r .Form ["extrahosts" ]
70- options .SecurityOpt = r .Form ["securityopt" ]
71- options .Squash = httputils .BoolValue (r , "squash" )
72- options .Target = r .FormValue ("target" )
73- options .RemoteContext = r .FormValue ("remote" )
7481 if versions .GreaterThanOrEqualTo (version , "1.32" ) {
7582 options .Platform = r .FormValue ("platform" )
7683 }
84+ if versions .GreaterThanOrEqualTo (version , "1.40" ) {
85+ outputsJSON := r .FormValue ("outputs" )
86+ if outputsJSON != "" {
87+ var outputs []types.ImageBuildOutput
88+ if err := json .Unmarshal ([]byte (outputsJSON ), & outputs ); err != nil {
89+ return nil , err
90+ }
91+ options .Outputs = outputs
92+ }
93+ }
7794
7895 if s := r .Form .Get ("shmsize" ); s != "" {
7996 shmSize , err := strconv .ParseInt (s , 10 , 64 )
@@ -90,10 +107,6 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
90107 }
91108 }
92109
93- if runtime .GOOS != "windows" && options .SecurityOpt != nil {
94- return nil , errdefs .InvalidParameter (errors .New ("The daemon on this platform does not support setting security options on build" ))
95- }
96-
97110 if ulimitsJSON := r .FormValue ("ulimits" ); ulimitsJSON != "" {
98111 var buildUlimits = []* units.Ulimit {}
99112 if err := json .Unmarshal ([]byte (ulimitsJSON ), & buildUlimits ); err != nil {
@@ -137,8 +150,6 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
137150 }
138151 options .CacheFrom = cacheFrom
139152 }
140- options .SessionID = r .FormValue ("session" )
141- options .BuildID = r .FormValue ("buildid" )
142153
143154 if bv := r .FormValue ("version" ); bv != "" {
144155 v , err := parseVersion (bv )
@@ -148,31 +159,17 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
148159 options .Version = v
149160 }
150161
151- if versions .GreaterThanOrEqualTo (version , "1.40" ) {
152- outputsJSON := r .FormValue ("outputs" )
153- if outputsJSON != "" {
154- var outputs []types.ImageBuildOutput
155- if err := json .Unmarshal ([]byte (outputsJSON ), & outputs ); err != nil {
156- return nil , err
157- }
158- options .Outputs = outputs
159- }
160- }
161-
162162 return options , nil
163163}
164164
165165func parseVersion (s string ) (types.BuilderVersion , error ) {
166- if s == "" {
167- return types .BuilderV1 , nil
168- }
169166 switch types .BuilderVersion (s ) {
170167 case types .BuilderV1 :
171168 return types .BuilderV1 , nil
172169 case types .BuilderBuildKit :
173170 return types .BuilderBuildKit , nil
174171 default :
175- return "" , errors .Errorf ("invalid version %s " , s )
172+ return "" , errors .Errorf ("invalid version %q " , s )
176173 }
177174}
178175
0 commit comments