@@ -10,16 +10,19 @@ import (
10
10
"os"
11
11
"path/filepath"
12
12
"strconv"
13
+ "time"
13
14
14
15
"github.com/containers/buildah"
15
16
"github.com/containers/buildah/imagebuildah"
17
+ "github.com/containers/buildah/util"
16
18
"github.com/containers/image/v5/types"
17
19
"github.com/containers/podman/v3/libpod"
18
20
"github.com/containers/podman/v3/pkg/api/handlers/utils"
19
21
"github.com/containers/podman/v3/pkg/auth"
20
22
"github.com/containers/podman/v3/pkg/channel"
21
23
"github.com/containers/storage/pkg/archive"
22
24
"github.com/gorilla/schema"
25
+ specs "github.com/opencontainers/runtime-spec/specs-go"
23
26
"github.com/pkg/errors"
24
27
"github.com/sirupsen/logrus"
25
28
)
@@ -65,6 +68,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
65
68
Annotations string `schema:"annotations"`
66
69
BuildArgs string `schema:"buildargs"`
67
70
CacheFrom string `schema:"cachefrom"`
71
+ Compression uint64 `schema:"compression"`
68
72
ConfigureNetwork int64 `schema:"networkmode"`
69
73
CpuPeriod uint64 `schema:"cpuperiod"` // nolint
70
74
CpuQuota int64 `schema:"cpuquota"` // nolint
@@ -73,17 +77,20 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
73
77
Devices string `schema:"devices"`
74
78
Dockerfile string `schema:"dockerfile"`
75
79
DropCapabilities string `schema:"dropcaps"`
80
+ Excludes string `schema:"excludes"`
76
81
ForceRm bool `schema:"forcerm"`
77
82
From string `schema:"from"`
78
83
HTTPProxy bool `schema:"httpproxy"`
79
84
Isolation int64 `schema:"isolation"`
80
- Jobs uint64 `schema:"jobs"` // nolint
85
+ Ignore bool `schema:"ignore"`
86
+ Jobs int `schema:"jobs"` // nolint
81
87
Labels string `schema:"labels"`
82
88
Layers bool `schema:"layers"`
83
89
LogRusage bool `schema:"rusage"`
84
90
Manifest string `schema:"manifest"`
85
91
MemSwap int64 `schema:"memswap"`
86
92
Memory int64 `schema:"memory"`
93
+ NamespaceOptions string `schema:"nsoptions"`
87
94
NoCache bool `schema:"nocache"`
88
95
OutputFormat string `schema:"outputformat"`
89
96
Platform string `schema:"platform"`
@@ -129,6 +136,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
129
136
}
130
137
}
131
138
139
+ compression := archive .Compression (query .Compression )
132
140
// convert label formats
133
141
var dropCaps = []string {}
134
142
if _ , found := r .URL .Query ()["dropcaps" ]; found {
@@ -156,7 +164,15 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
156
164
output = query .Tag [0 ]
157
165
}
158
166
format := buildah .Dockerv2ImageManifest
167
+ registry := query .Registry
168
+ isolation := buildah .IsolationChroot
169
+ /*
170
+ // FIXME, This is very broken. Buildah will only work with chroot
171
+ isolation := buildah.IsolationDefault
172
+ */
159
173
if utils .IsLibpodRequest (r ) {
174
+ // isolation = buildah.Isolation(query.Isolation)
175
+ registry = ""
160
176
format = query .OutputFormat
161
177
}
162
178
var additionalTags []string
@@ -172,6 +188,14 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
172
188
}
173
189
}
174
190
191
+ var excludes = []string {}
192
+ if _ , found := r .URL .Query ()["excludes" ]; found {
193
+ if err := json .Unmarshal ([]byte (query .Excludes ), & excludes ); err != nil {
194
+ utils .BadRequest (w , "excludes" , query .Excludes , err )
195
+ return
196
+ }
197
+ }
198
+
175
199
// convert label formats
176
200
var annotations = []string {}
177
201
if _ , found := r .URL .Query ()["annotations" ]; found {
@@ -181,6 +205,19 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
181
205
}
182
206
}
183
207
208
+ // convert label formats
209
+ nsoptions := buildah.NamespaceOptions {}
210
+ if _ , found := r .URL .Query ()["nsoptions" ]; found {
211
+ if err := json .Unmarshal ([]byte (query .NamespaceOptions ), & nsoptions ); err != nil {
212
+ utils .BadRequest (w , "nsoptions" , query .NamespaceOptions , err )
213
+ return
214
+ }
215
+ } else {
216
+ nsoptions = append (nsoptions , buildah.NamespaceOption {
217
+ Name : string (specs .NetworkNamespace ),
218
+ Host : true ,
219
+ })
220
+ }
184
221
// convert label formats
185
222
var labels = []string {}
186
223
if _ , found := r .URL .Query ()["labels" ]; found {
@@ -189,6 +226,10 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
189
226
return
190
227
}
191
228
}
229
+ jobs := 1
230
+ if _ , found := r .URL .Query ()["jobs" ]; found {
231
+ jobs = query .Jobs
232
+ }
192
233
193
234
pullPolicy := buildah .PullIfMissing
194
235
if _ , found := r .URL .Query ()["pull" ]; found {
@@ -218,6 +259,12 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
218
259
reporter := channel .NewWriter (make (chan []byte , 1 ))
219
260
defer reporter .Close ()
220
261
262
+ runtime := r .Context ().Value ("runtime" ).(* libpod.Runtime )
263
+ rtc , err := runtime .GetConfig ()
264
+ if err != nil {
265
+ utils .Error (w , "Something went wrong." , http .StatusInternalServerError , errors .Wrap (err , "Decode()" ))
266
+ return
267
+ }
221
268
buildOptions := imagebuildah.BuildOptions {
222
269
AddCapabilities : addCaps ,
223
270
AdditionalTags : additionalTags ,
@@ -234,40 +281,43 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
234
281
MemorySwap : query .MemSwap ,
235
282
ShmSize : strconv .Itoa (query .ShmSize ),
236
283
},
237
- Compression : archive .Gzip ,
284
+ CNIConfigDir : rtc .Network .CNIPluginDirs [0 ],
285
+ CNIPluginPath : util .DefaultCNIPluginPath ,
286
+ Compression : compression ,
238
287
ConfigureNetwork : buildah .NetworkConfigurationPolicy (query .ConfigureNetwork ),
239
288
ContextDirectory : contextDirectory ,
240
289
Devices : devices ,
241
290
DropCapabilities : dropCaps ,
242
291
Err : auxout ,
292
+ Excludes : excludes ,
243
293
ForceRmIntermediateCtrs : query .ForceRm ,
244
294
From : query .From ,
245
- IgnoreUnrecognizedInstructions : true ,
246
- // FIXME, This is very broken. Buildah will only work with chroot
247
- // Isolation: buildah.Isolation(query.Isolation),
248
- Isolation : buildah .IsolationChroot ,
249
-
250
- Labels : labels ,
251
- Layers : query .Layers ,
252
- Manifest : query .Manifest ,
253
- NoCache : query .NoCache ,
254
- Out : stdout ,
255
- Output : output ,
256
- OutputFormat : format ,
257
- PullPolicy : pullPolicy ,
258
- Quiet : query .Quiet ,
259
- Registry : query .Registry ,
260
- RemoveIntermediateCtrs : query .Rm ,
261
- ReportWriter : reporter ,
262
- Squash : query .Squash ,
295
+ IgnoreUnrecognizedInstructions : query .Ignore ,
296
+ Isolation : isolation ,
297
+ Jobs : & jobs ,
298
+ Labels : labels ,
299
+ Layers : query .Layers ,
300
+ Manifest : query .Manifest ,
301
+ MaxPullPushRetries : 3 ,
302
+ NamespaceOptions : nsoptions ,
303
+ NoCache : query .NoCache ,
304
+ Out : stdout ,
305
+ Output : output ,
306
+ OutputFormat : format ,
307
+ PullPolicy : pullPolicy ,
308
+ PullPushRetryDelay : time .Duration (2 * time .Second ),
309
+ Quiet : query .Quiet ,
310
+ Registry : registry ,
311
+ RemoveIntermediateCtrs : query .Rm ,
312
+ ReportWriter : reporter ,
313
+ Squash : query .Squash ,
263
314
SystemContext : & types.SystemContext {
264
315
AuthFilePath : authfile ,
265
316
DockerAuthConfig : creds ,
266
317
},
267
318
Target : query .Target ,
268
319
}
269
320
270
- runtime := r .Context ().Value ("runtime" ).(* libpod.Runtime )
271
321
runCtx , cancel := context .WithCancel (context .Background ())
272
322
var imageID string
273
323
go func () {
0 commit comments