1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | /**
|
4 | * Class representing an image
|
5 | */
|
6 | class Image {
|
7 | /**
|
8 | * Creates a new image
|
9 | * @param {Modem} modem Modem to connect to the remote service
|
10 | * @param {string} id Container id
|
11 | */
|
12 | constructor(modem, id) {
|
13 | this.data = {};
|
14 | this.modem = modem;
|
15 | this.id = id;
|
16 | }
|
17 | /**
|
18 | * Get low-level information on an image
|
19 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/inspect-an-image
|
20 | * The reason why this module isn't called inspect is because that interferes with the inspect utility of node.
|
21 | * @param {Object} opts Query params in the request (optional)
|
22 | * @return {Promise} Promise return the image
|
23 | */
|
24 | status(opts) {
|
25 | const call = {
|
26 | path: `/images/${this.id}/json?`,
|
27 | method: 'GET',
|
28 | options: opts,
|
29 | statusCodes: {
|
30 | 200: true,
|
31 | 404: 'no such image',
|
32 | 500: 'server error'
|
33 | }
|
34 | };
|
35 | return new Promise((resolve, reject) => {
|
36 | this.modem.dial(call, (err, conf) => {
|
37 | if (err)
|
38 | return reject(err);
|
39 | const image = new Image(this.modem, this.id);
|
40 | image.data = conf;
|
41 | resolve(image);
|
42 | });
|
43 | });
|
44 | }
|
45 | /**
|
46 | * History of the image
|
47 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/get-the-history-of-an-image
|
48 | * @param {Object} opts Query params in the request (optional)
|
49 | * @param {String} id ID of the image to inspect, if it's not set, use the id of the object (optional)
|
50 | * @return {Promise} Promise return the events in the history
|
51 | */
|
52 | history(opts) {
|
53 | const call = {
|
54 | path: `/images/${this.id}/history?`,
|
55 | method: 'GET',
|
56 | options: opts,
|
57 | statusCodes: {
|
58 | 200: true,
|
59 | 404: 'no such image',
|
60 | 500: 'server error'
|
61 | }
|
62 | };
|
63 | return new Promise((resolve, reject) => {
|
64 | this.modem.dial(call, (err, events) => {
|
65 | if (err)
|
66 | return reject(err);
|
67 | resolve(events);
|
68 | });
|
69 | });
|
70 | }
|
71 | /**
|
72 | * Push an image to the registry
|
73 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/push-an-image-on-the-registry
|
74 | * @param {Object} auth Authentication (optional)
|
75 | * @param {Object} opts Query params in the request (optional)
|
76 | * @return {Promise} Promise return the resulting stream
|
77 | */
|
78 | push(auth, opts) {
|
79 | const call = {
|
80 | path: `/images/${this.id}/push?`,
|
81 | method: 'POST',
|
82 | options: opts,
|
83 | isStream: true,
|
84 | authconfig: auth,
|
85 | statusCodes: {
|
86 | 200: true,
|
87 | 404: 'no such image',
|
88 | 500: 'server error'
|
89 | }
|
90 | };
|
91 | return new Promise((resolve, reject) => {
|
92 | this.modem.dial(call, (err, stream) => {
|
93 | if (err)
|
94 | return reject(err);
|
95 | resolve(stream);
|
96 | });
|
97 | });
|
98 | }
|
99 | /**
|
100 | * Tag the image into the registry
|
101 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/tag-an-image-into-a-repository
|
102 | * @param {Object} opts Query params in the request (optional)
|
103 | * @return {Promise} Promise return the image
|
104 | */
|
105 | tag(opts) {
|
106 | const call = {
|
107 | path: `/images/${this.id}/tag?`,
|
108 | method: 'POST',
|
109 | options: opts,
|
110 | statusCodes: {
|
111 | 201: true,
|
112 | 400: 'bad parameter',
|
113 | 404: 'no such image',
|
114 | 409: 'conflict',
|
115 | 500: 'server error'
|
116 | }
|
117 | };
|
118 | return new Promise((resolve, reject) => {
|
119 | this.modem.dial(call, (err, res) => {
|
120 | if (err)
|
121 | return reject(err);
|
122 | const image = new Image(this.modem, this.id);
|
123 | resolve(image);
|
124 | });
|
125 | }).then((image) => image.status());
|
126 | }
|
127 | /**
|
128 | * Remove an image from the filesystem
|
129 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/remove-an-image
|
130 | * @param {Object} opts Query params in the request (optional)
|
131 | * @return {Promise} Promise return the result
|
132 | */
|
133 | remove(opts) {
|
134 | const call = {
|
135 | path: `/images/${this.id}?`,
|
136 | method: 'DELETE',
|
137 | options: opts,
|
138 | statusCodes: {
|
139 | 200: true,
|
140 | 404: 'no such image',
|
141 | 409: 'conflict',
|
142 | 500: 'server error'
|
143 | }
|
144 | };
|
145 | return new Promise((resolve, reject) => {
|
146 | this.modem.dial(call, (err, res) => {
|
147 | if (err)
|
148 | return reject(err);
|
149 | resolve(res);
|
150 | });
|
151 | });
|
152 | }
|
153 | /**
|
154 | * Get an image in a tarball
|
155 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/get-a-tarball-containing-all-images-in-a-repository
|
156 | * @param {Object} opts Query params in the request (optional)
|
157 | * @return {Promise} Promise return the stream with the tarball
|
158 | */
|
159 | get(opts) {
|
160 | const call = {
|
161 | path: `/images/${this.id}/get?`,
|
162 | method: 'GET',
|
163 | options: opts,
|
164 | isStream: true,
|
165 | statusCodes: {
|
166 | 200: true,
|
167 | 500: 'server error'
|
168 | }
|
169 | };
|
170 | return new Promise((resolve, reject) => {
|
171 | this.modem.dial(call, (err, stream) => {
|
172 | if (err)
|
173 | return reject(err);
|
174 | resolve(stream);
|
175 | });
|
176 | });
|
177 | }
|
178 | }
|
179 | exports.Image = Image;
|
180 | class default_1 {
|
181 | constructor(modem) {
|
182 | this.modem = modem;
|
183 | }
|
184 | /**
|
185 | * Get a Image object
|
186 | * @param {id} string ID of the secret
|
187 | * @return {Image}
|
188 | */
|
189 | get(id) {
|
190 | return new Image(this.modem, id);
|
191 | }
|
192 | /**
|
193 | * Search an image on Docker Hub
|
194 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/search-images
|
195 | * @param {Object} opts Query params in the request (optional)
|
196 | * @return {Promise} Promise return the images
|
197 | */
|
198 | search(opts) {
|
199 | const call = {
|
200 | path: `/images/search?`,
|
201 | method: 'GET',
|
202 | options: opts,
|
203 | statusCodes: {
|
204 | 200: true,
|
205 | 500: 'server error'
|
206 | }
|
207 | };
|
208 | return new Promise((resolve, reject) => {
|
209 | this.modem.dial(call, (err, images) => {
|
210 | if (err)
|
211 | return reject(err);
|
212 | resolve(images);
|
213 | });
|
214 | });
|
215 | }
|
216 | /**
|
217 | * Get the list of images
|
218 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-images
|
219 | * @param {Object} opts Query params in the request (optional)
|
220 | * @return {Promise} Promise returning the result as a list of images
|
221 | */
|
222 | list(opts) {
|
223 | const call = {
|
224 | path: '/images/json?',
|
225 | method: 'GET',
|
226 | options: opts,
|
227 | statusCodes: {
|
228 | 200: true,
|
229 | 400: 'bad request',
|
230 | 500: 'server error'
|
231 | }
|
232 | };
|
233 | return new Promise((resolve, reject) => {
|
234 | this.modem.dial(call, (err, images) => {
|
235 | if (err)
|
236 | return reject(err);
|
237 | resolve(images.map((conf) => {
|
238 | const image = new Image(this.modem, conf.Id);
|
239 | image.data = conf;
|
240 | return image;
|
241 | }));
|
242 | });
|
243 | });
|
244 | }
|
245 | /**
|
246 | * Build image from dockerfile
|
247 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/build-image-from-a-dockerfile
|
248 | * @file {File} file Dockerfile to build
|
249 | * @param {Object} opts Query params in the request (optional)
|
250 | * @param {Object} auth Registry Auth Config, see linked engine documentation for details (optional)
|
251 | * @return {Promise} Promise return the resulting stream
|
252 | */
|
253 | build(file, opts, auth) {
|
254 | const call = {
|
255 | path: '/build?',
|
256 | method: 'POST',
|
257 | options: opts,
|
258 | file: file,
|
259 | isStream: true,
|
260 | registryconfig: auth,
|
261 | statusCodes: {
|
262 | 200: true,
|
263 | 500: 'server error'
|
264 | }
|
265 | };
|
266 | return new Promise((resolve, reject) => {
|
267 | this.modem.dial(call, (err, stream) => {
|
268 | if (err)
|
269 | return reject(err);
|
270 | resolve(stream);
|
271 | });
|
272 | });
|
273 | }
|
274 | /**
|
275 | * Create an image
|
276 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/create-an-image
|
277 | * @param {Object} auth Authentication (optional)
|
278 | * @param {Object} opts Query params in the request (optional)
|
279 | * @return {Promise} Promise return the resulting stream
|
280 | */
|
281 | create(auth, opts) {
|
282 | const call = {
|
283 | path: '/images/create?',
|
284 | method: 'POST',
|
285 | options: opts,
|
286 | isStream: true,
|
287 | authconfig: auth,
|
288 | statusCodes: {
|
289 | 200: true,
|
290 | 500: 'server error'
|
291 | }
|
292 | };
|
293 | return new Promise((resolve, reject) => {
|
294 | this.modem.dial(call, (err, stream) => {
|
295 | if (err)
|
296 | return reject(err);
|
297 | resolve(stream);
|
298 | });
|
299 | });
|
300 | }
|
301 | /**
|
302 | * Get all images in a tarball
|
303 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/get-a-tarball-containing-all-images
|
304 | * @param {Object} opts Query params in the request (optional)
|
305 | * @return {Promise} Promise return the stream with the tarball
|
306 | */
|
307 | getAll(opts) {
|
308 | const call = {
|
309 | path: `/images/get?`,
|
310 | method: 'GET',
|
311 | options: opts,
|
312 | isStream: true,
|
313 | statusCodes: {
|
314 | 200: true,
|
315 | 500: 'server error'
|
316 | }
|
317 | };
|
318 | return new Promise((resolve, reject) => {
|
319 | this.modem.dial(call, (err, stream) => {
|
320 | if (err)
|
321 | return reject(err);
|
322 | resolve(stream);
|
323 | });
|
324 | });
|
325 | }
|
326 | /**
|
327 | * Load image from tarball
|
328 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/load-a-tarball-with-a-set-of-images-and-tags-into-docker
|
329 | * @file {File} file Tarball to load
|
330 | * @param {Object} opts Query params in the request (optional)
|
331 | * @return {Promise} Promise return the stream with the process
|
332 | */
|
333 | load(file, opts) {
|
334 | const call = {
|
335 | path: '/images/load?',
|
336 | method: 'POST',
|
337 | options: opts,
|
338 | file: file,
|
339 | isStream: true,
|
340 | statusCodes: {
|
341 | 200: true,
|
342 | 500: 'server error'
|
343 | }
|
344 | };
|
345 | return new Promise((resolve, reject) => {
|
346 | this.modem.dial(call, (err, stream) => {
|
347 | if (err)
|
348 | return reject(err);
|
349 | resolve(stream);
|
350 | });
|
351 | });
|
352 | }
|
353 | /**
|
354 | * Prune images
|
355 | * https://docs.docker.com/engine/api/v1.25/#operation/ImagePrune
|
356 | * @param {Object} opts Query params in the request (optional)
|
357 | * @return {Promise} Promise returning the container
|
358 | */
|
359 | prune(opts) {
|
360 | const call = {
|
361 | path: `/images/prune`,
|
362 | method: 'POST',
|
363 | options: opts,
|
364 | statusCodes: {
|
365 | 200: true,
|
366 | 500: 'server error'
|
367 | }
|
368 | };
|
369 | return new Promise((resolve, reject) => {
|
370 | this.modem.dial(call, (err, res) => {
|
371 | if (err)
|
372 | return reject(err);
|
373 | resolve(res);
|
374 | });
|
375 | });
|
376 | }
|
377 | }
|
378 | exports.default = default_1;
|
379 | //# sourceMappingURL=image.js.map |
\ | No newline at end of file |