1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Docker\API\Resource; |
4
|
|
|
|
5
|
|
|
use Joli\Jane\Swagger\Client\QueryParam; |
6
|
|
|
use Joli\Jane\Swagger\Client\Resource; |
7
|
|
|
|
8
|
|
|
class ImageResource extends Resource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* List Images. |
12
|
|
|
* |
13
|
|
|
* @param array $parameters List of parameters |
14
|
|
|
* |
15
|
|
|
* (bool)all: Show all images. Only images from a final layer (no children) are shown by default. |
16
|
|
|
* (string)filters: A JSON encoded value of the filters (a map[string][]string) to process on the containers list |
17
|
|
|
* (string)filter: Only return images with the specified name. |
18
|
|
|
* (bool)digests: Show digest information, default to false |
19
|
|
|
* @param string $fetch Fetch mode (object or response) |
20
|
|
|
* |
21
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\ImageItem[] |
22
|
|
|
*/ |
23
|
|
|
public function findAll($parameters = [], $fetch = self::FETCH_OBJECT) |
24
|
|
|
{ |
25
|
|
|
$queryParam = new QueryParam(); |
26
|
|
|
$queryParam->setDefault('all', false); |
27
|
|
|
$queryParam->setDefault('filters', null); |
28
|
|
|
$queryParam->setDefault('filter', null); |
29
|
|
|
$queryParam->setDefault('digests', null); |
30
|
|
|
$url = '/v1.21/images/json'; |
31
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
32
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
33
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
34
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $headers, $body); |
35
|
|
|
$response = $this->httpClient->sendRequest($request); |
36
|
|
|
if (self::FETCH_OBJECT == $fetch) { |
37
|
|
|
if ('200' == $response->getStatusCode()) { |
38
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ImageItem[]', 'json'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $response; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Build an image from Dockerfile via stdin. |
47
|
|
|
* |
48
|
|
|
* @param string $inputStream The input stream must be a tar archive compressed with one of the following algorithms: identity (no compression), gzip, bzip2, xz. |
49
|
|
|
* @param array $parameters List of parameters |
50
|
|
|
* |
51
|
|
|
* (string)dockerfile: Path within the build context to the Dockerfile. This is ignored if remote is specified and points to an individual filename. |
52
|
|
|
* (string)t: A repository name (and optionally a tag) to apply to the resulting image in case of success. |
53
|
|
|
* (string)remote: A Git repository URI or HTTP/HTTPS URI build source. If the URI specifies a filename, the file’s contents are placed into a file called Dockerfile. |
54
|
|
|
* (bool)q: Suppress verbose build output. |
55
|
|
|
* (bool)nocache: Do not use the cache when building the image. |
56
|
|
|
* (string)pull: Attempt to pull the image even if an older image exists locally |
57
|
|
|
* (bool)rm: Remove intermediate containers after a successful build (default behavior). |
58
|
|
|
* (bool)forcerm: always remove intermediate containers (includes rm)Request Headers: |
59
|
|
|
* (string)Content-type: Set to 'application/tar'. |
60
|
|
|
* (string)X-Registry-Config: A base64-url-safe-encoded Registry Auth Config JSON object |
61
|
|
|
* @param string $fetch Fetch mode (object or response) |
62
|
|
|
* |
63
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
64
|
|
|
*/ |
65
|
|
|
public function build(string $inputStream, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$queryParam = new QueryParam(); |
68
|
|
|
$queryParam->setDefault('dockerfile', null); |
69
|
|
|
$queryParam->setDefault('t', null); |
70
|
|
|
$queryParam->setDefault('remote', null); |
71
|
|
|
$queryParam->setDefault('q', false); |
72
|
|
|
$queryParam->setDefault('nocache', false); |
73
|
|
|
$queryParam->setDefault('pull', null); |
74
|
|
|
$queryParam->setDefault('rm', true); |
75
|
|
|
$queryParam->setDefault('forcerm', false); |
76
|
|
|
$queryParam->setDefault('Content-type', 'application/tar'); |
77
|
|
|
$queryParam->setDefault('X-Registry-Config', null); |
78
|
|
|
$url = '/v1.21/build'; |
79
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
80
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
81
|
|
|
$body = $inputStream; |
82
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body); |
83
|
|
|
$response = $this->httpClient->sendRequest($request); |
84
|
|
|
|
85
|
|
|
return $response; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Create an image either by pulling it from the registry or by importing it. |
90
|
|
|
* |
91
|
|
|
* @param array $parameters List of parameters |
92
|
|
|
* |
93
|
|
|
* (string)fromImage: Name of the image to pull. The name may include a tag or digest. This parameter may only be used when pulling an image. |
94
|
|
|
* (string)fromSrc: Source to import. The value may be a URL from which the image can be retrieved or - to read the image from the request body. This parameter may only be used when importing an image. |
95
|
|
|
* (string)repo: Repository name given to an image when it is imported. The repo may include a tag. This parameter may only be used when importing an image. |
96
|
|
|
* (string)tag: Tag or digest. |
97
|
|
|
* (string)X-Registry-Config: A base64-encoded AuthConfig object |
98
|
|
|
* @param string $fetch Fetch mode (object or response) |
99
|
|
|
* |
100
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
101
|
|
|
*/ |
102
|
|
|
public function create($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$queryParam = new QueryParam(); |
105
|
|
|
$queryParam->setDefault('fromImage', null); |
106
|
|
|
$queryParam->setDefault('fromSrc', null); |
107
|
|
|
$queryParam->setDefault('repo', null); |
108
|
|
|
$queryParam->setDefault('tag', null); |
109
|
|
|
$queryParam->setDefault('X-Registry-Config', null); |
110
|
|
|
$url = '/v1.21/images/create'; |
111
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
112
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
113
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
114
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body); |
115
|
|
|
$response = $this->httpClient->sendRequest($request); |
116
|
|
|
|
117
|
|
|
return $response; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Return low-level information on the image name. |
122
|
|
|
* |
123
|
|
|
* @param array $parameters List of parameters |
124
|
|
|
* @param string $fetch Fetch mode (object or response) |
125
|
|
|
* |
126
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\Image |
127
|
|
|
*/ |
128
|
|
View Code Duplication |
public function find($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$queryParam = new QueryParam(); |
131
|
|
|
$url = '/v1.21/images/{name}/json'; |
132
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
133
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
134
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
135
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $headers, $body); |
136
|
|
|
$response = $this->httpClient->sendRequest($request); |
137
|
|
|
if (self::FETCH_OBJECT == $fetch) { |
138
|
|
|
if ('200' == $response->getStatusCode()) { |
139
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\Image', 'json'); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $response; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Return the history of the image name. |
148
|
|
|
* |
149
|
|
|
* @param array $parameters List of parameters |
150
|
|
|
* @param string $fetch Fetch mode (object or response) |
151
|
|
|
* |
152
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\ImageHistoryItem[] |
153
|
|
|
*/ |
154
|
|
View Code Duplication |
public function history($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
$queryParam = new QueryParam(); |
157
|
|
|
$url = '/v1.21/images/{name}/history'; |
158
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
159
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
160
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
161
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $headers, $body); |
162
|
|
|
$response = $this->httpClient->sendRequest($request); |
163
|
|
|
if (self::FETCH_OBJECT == $fetch) { |
164
|
|
|
if ('200' == $response->getStatusCode()) { |
165
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ImageHistoryItem[]', 'json'); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $response; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Push the image name on the registry. |
174
|
|
|
* |
175
|
|
|
* @param array $parameters List of parameters |
176
|
|
|
* |
177
|
|
|
* (string)tag: The tag to associate with the image on the registry. |
178
|
|
|
* (string)X-Registry-Auth: A base64-encoded AuthConfig object |
179
|
|
|
* @param string $fetch Fetch mode (object or response) |
180
|
|
|
* |
181
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
182
|
|
|
*/ |
183
|
|
|
public function push($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
184
|
|
|
{ |
185
|
|
|
$queryParam = new QueryParam(); |
186
|
|
|
$queryParam->setDefault('tag', null); |
187
|
|
|
$queryParam->setDefault('X-Registry-Auth', null); |
188
|
|
|
$url = '/v1.21/images/{name}/push'; |
189
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
190
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
191
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
192
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body); |
193
|
|
|
$response = $this->httpClient->sendRequest($request); |
194
|
|
|
|
195
|
|
|
return $response; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Tag the image name into a repository. |
200
|
|
|
* |
201
|
|
|
* @param array $parameters List of parameters |
202
|
|
|
* |
203
|
|
|
* (string)repo: The repository to tag in. |
204
|
|
|
* (string)force: 1/True/true or 0/False/false, default false |
205
|
|
|
* (string)tag: The new tag name. |
206
|
|
|
* @param string $fetch Fetch mode (object or response) |
207
|
|
|
* |
208
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
209
|
|
|
*/ |
210
|
|
|
public function tag($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
$queryParam = new QueryParam(); |
213
|
|
|
$queryParam->setDefault('repo', null); |
214
|
|
|
$queryParam->setDefault('force', null); |
215
|
|
|
$queryParam->setDefault('tag', null); |
216
|
|
|
$url = '/v1.21/images/{name}/tag'; |
217
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
218
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
219
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
220
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body); |
221
|
|
|
$response = $this->httpClient->sendRequest($request); |
222
|
|
|
|
223
|
|
|
return $response; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Remove the image name from the filesystem. |
228
|
|
|
* |
229
|
|
|
* @param array $parameters List of parameters |
230
|
|
|
* |
231
|
|
|
* (string)force: 1/True/true or 0/False/false, default false |
232
|
|
|
* (string)noprune: 1/True/true or 0/False/false, default false. |
233
|
|
|
* @param string $fetch Fetch mode (object or response) |
234
|
|
|
* |
235
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
236
|
|
|
*/ |
237
|
|
|
public function remove($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
238
|
|
|
{ |
239
|
|
|
$queryParam = new QueryParam(); |
240
|
|
|
$queryParam->setDefault('force', null); |
241
|
|
|
$queryParam->setDefault('noprune', null); |
242
|
|
|
$url = '/v1.21/images/{name}'; |
243
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
244
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
245
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
246
|
|
|
$request = $this->messageFactory->createRequest('DELETE', $url, $headers, $body); |
247
|
|
|
$response = $this->httpClient->sendRequest($request); |
248
|
|
|
|
249
|
|
|
return $response; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Search for an image on Docker Hub. |
254
|
|
|
* |
255
|
|
|
* @param array $parameters List of parameters |
256
|
|
|
* |
257
|
|
|
* (string)term: Term to search |
258
|
|
|
* @param string $fetch Fetch mode (object or response) |
259
|
|
|
* |
260
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\ImageSearchResult[] |
261
|
|
|
*/ |
262
|
|
View Code Duplication |
public function search($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
263
|
|
|
{ |
264
|
|
|
$queryParam = new QueryParam(); |
265
|
|
|
$queryParam->setDefault('term', null); |
266
|
|
|
$url = '/v1.21/images/search'; |
267
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
268
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
269
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
270
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $headers, $body); |
271
|
|
|
$response = $this->httpClient->sendRequest($request); |
272
|
|
|
if (self::FETCH_OBJECT == $fetch) { |
273
|
|
|
if ('200' == $response->getStatusCode()) { |
274
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\ImageSearchResult[]', 'json'); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
return $response; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Create a new image from a container’s changes. |
283
|
|
|
* |
284
|
|
|
* @param \Docker\API\Model\ContainerConfig $containerConfig The container configuration |
285
|
|
|
* @param array $parameters List of parameters |
286
|
|
|
* |
287
|
|
|
* (string)container: Container id or name to commit |
288
|
|
|
* (string)repo: Repository name for the created image |
289
|
|
|
* (string)tag: Tag name for the create image |
290
|
|
|
* (string)comment: Commit message |
291
|
|
|
* (string)author: author (e.g., “John Hannibal Smith <[email protected]>“) |
292
|
|
|
* (string)pause: 1/True/true or 0/False/false, whether to pause the container before committing |
293
|
|
|
* (string)changes: Dockerfile instructions to apply while committing |
294
|
|
|
* @param string $fetch Fetch mode (object or response) |
295
|
|
|
* |
296
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\Docker\API\Model\CommitResult |
297
|
|
|
*/ |
298
|
|
|
public function commit(\Docker\API\Model\ContainerConfig $containerConfig, $parameters = [], $fetch = self::FETCH_OBJECT) |
299
|
|
|
{ |
300
|
|
|
$queryParam = new QueryParam(); |
301
|
|
|
$queryParam->setDefault('container', null); |
302
|
|
|
$queryParam->setDefault('repo', null); |
303
|
|
|
$queryParam->setDefault('tag', null); |
304
|
|
|
$queryParam->setDefault('comment', null); |
305
|
|
|
$queryParam->setDefault('author', null); |
306
|
|
|
$queryParam->setDefault('pause', null); |
307
|
|
|
$queryParam->setDefault('changes', null); |
308
|
|
|
$url = '/v1.21/commit'; |
309
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
310
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
311
|
|
|
$body = $this->serializer->serialize($containerConfig, 'json'); |
312
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body); |
313
|
|
|
$response = $this->httpClient->sendRequest($request); |
314
|
|
|
if (self::FETCH_OBJECT == $fetch) { |
315
|
|
|
if ('201' == $response->getStatusCode()) { |
316
|
|
|
return $this->serializer->deserialize($response->getBody()->getContents(), 'Docker\\API\\Model\\CommitResult', 'json'); |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
return $response; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Get a tarball containing all images and metadata for the repository specified by name. |
325
|
|
|
* |
326
|
|
|
* @param array $parameters List of parameters |
327
|
|
|
* @param string $fetch Fetch mode (object or response) |
328
|
|
|
* |
329
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
330
|
|
|
*/ |
331
|
|
View Code Duplication |
public function save($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
332
|
|
|
{ |
333
|
|
|
$queryParam = new QueryParam(); |
334
|
|
|
$url = '/v1.21/images/{name}/get'; |
335
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
336
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
337
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
338
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $headers, $body); |
339
|
|
|
$response = $this->httpClient->sendRequest($request); |
340
|
|
|
|
341
|
|
|
return $response; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get a tarball containing all images and metadata for one or more repositories. |
346
|
|
|
* |
347
|
|
|
* @param array $parameters List of parameters |
348
|
|
|
* |
349
|
|
|
* (array)names: Image names to filter |
350
|
|
|
* @param string $fetch Fetch mode (object or response) |
351
|
|
|
* |
352
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
353
|
|
|
*/ |
354
|
|
View Code Duplication |
public function saveAll($parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
355
|
|
|
{ |
356
|
|
|
$queryParam = new QueryParam(); |
357
|
|
|
$queryParam->setDefault('names', null); |
358
|
|
|
$url = '/v1.21/images/get'; |
359
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
360
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
361
|
|
|
$body = $queryParam->buildFormDataString($parameters); |
362
|
|
|
$request = $this->messageFactory->createRequest('GET', $url, $headers, $body); |
363
|
|
|
$response = $this->httpClient->sendRequest($request); |
364
|
|
|
|
365
|
|
|
return $response; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Load a set of images and tags into a Docker repository. See the image tarball format for more details. |
370
|
|
|
* |
371
|
|
|
* @param string $imagesTarball Tar archive containing images |
372
|
|
|
* @param array $parameters List of parameters |
373
|
|
|
* @param string $fetch Fetch mode (object or response) |
374
|
|
|
* |
375
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
376
|
|
|
*/ |
377
|
|
View Code Duplication |
public function load(string $imagesTarball, $parameters = [], $fetch = self::FETCH_OBJECT) |
|
|
|
|
378
|
|
|
{ |
379
|
|
|
$queryParam = new QueryParam(); |
380
|
|
|
$url = '/v1.21/images/load'; |
381
|
|
|
$url = $url . ('?' . $queryParam->buildQueryString($parameters)); |
382
|
|
|
$headers = array_merge(['Host' => 'localhost'], $queryParam->buildHeaders($parameters)); |
383
|
|
|
$body = $imagesTarball; |
384
|
|
|
$request = $this->messageFactory->createRequest('POST', $url, $headers, $body); |
385
|
|
|
$response = $this->httpClient->sendRequest($request); |
386
|
|
|
|
387
|
|
|
return $response; |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.