|
1 | | -'use strict'; |
2 | | - |
3 | | -var DockerCommand = require('../models/dockerCommand'); |
| 1 | +const DockerCommand = require('../models/dockerCommand'); |
4 | 2 |
|
5 | 3 | var dataInitializer = function () { |
6 | 4 |
|
7 | | - var initializeData = function(callback) { |
8 | | - |
9 | | - var runDockerCommand = new DockerCommand({ |
10 | | - command : 'run', |
11 | | - description : 'Runs a Docker container', |
12 | | - examples : [ |
13 | | - { |
14 | | - example: 'docker run imageName', |
15 | | - description: 'Creates a running container from the image. Pulls it from Docker Hub if the image is not local' |
16 | | - }, |
17 | | - { |
18 | | - example: 'docker run -d -p 8080:3000 imageName', |
19 | | - description: 'Runs a container in "detached" mode with an external port of 8080 and a container port of 3000.' |
20 | | - } |
21 | | - ]}); |
22 | | - |
23 | | - runDockerCommand.save(function(err) { |
24 | | - if (err) { |
25 | | - return callback(err); |
26 | | - } |
27 | | - }); |
28 | | - |
29 | | - var psDockerCommand = new DockerCommand({ |
30 | | - command : 'ps', |
31 | | - description : 'Lists containers', |
32 | | - examples : [ |
33 | | - { |
34 | | - example: 'docker ps', |
35 | | - description: 'Lists all running containers' |
36 | | - }, |
37 | | - { |
38 | | - example: 'docker ps -a', |
39 | | - description: 'Lists all containers (even if they are not running)' |
40 | | - } |
41 | | - ]}); |
42 | | - |
43 | | - psDockerCommand.save(function(err) { |
44 | | - if (err) { |
45 | | - return callback(err); |
46 | | - } |
47 | | - }); |
48 | | - |
49 | | - callback(); |
50 | | - |
51 | | - }; |
| 5 | + const initializeData = async (callback) => { |
| 6 | + |
| 7 | + const runDockerCommand = new DockerCommand({ |
| 8 | + command: 'run', |
| 9 | + description: 'Runs a Docker container', |
| 10 | + examples: [ |
| 11 | + { |
| 12 | + example: 'docker run imageName', |
| 13 | + description: 'Creates a running container from the image. Pulls it from Docker Hub if the image is not local' |
| 14 | + }, |
| 15 | + { |
| 16 | + example: 'docker run -d -p 8080:3000 imageName', |
| 17 | + description: 'Runs a container in "detached" mode with an external port of 8080 and a container port of 3000.' |
| 18 | + } |
| 19 | + ] |
| 20 | + }); |
| 21 | + |
| 22 | + const psDockerCommand = new DockerCommand({ |
| 23 | + command: 'ps', |
| 24 | + description: 'Lists containers', |
| 25 | + examples: [ |
| 26 | + { |
| 27 | + example: 'docker ps', |
| 28 | + description: 'Lists all running containers' |
| 29 | + }, |
| 30 | + { |
| 31 | + example: 'docker ps -a', |
| 32 | + description: 'Lists all containers (even if they are not running)' |
| 33 | + } |
| 34 | + ] |
| 35 | + }); |
| 36 | + |
| 37 | + |
| 38 | + try { |
| 39 | + await runDockerCommand.save(); |
| 40 | + await psDockerCommand.save(); |
| 41 | + callback(); |
| 42 | + } catch (err) { |
| 43 | + callback(err); |
| 44 | + } |
| 45 | + |
| 46 | + }; |
52 | 47 |
|
53 | 48 |
|
54 | 49 | return { |
|
0 commit comments