This repository has been archived by the owner on Nov 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (55 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// images
const ghostImage = 'ghost:latest';
exports.getQuestions = () => [
{
type: 'input',
name: 'projectName',
message: 'Ghost project name:',
},
{
type: 'input',
name: 'ghostDomain',
message: 'Domain for Ghost:',
},
];
const startGhost = async ({util, answers, serverConfig, username, docker, volume}) => {
const deploymentName = util.nameFromImage(ghostImage);
return docker.startFromParams({
image: ghostImage,
projectName: answers.projectName,
username,
deploymentName,
frontend: `Host:${answers.ghostDomain}`,
restartPolicy: 'always',
Env: [`url=http${serverConfig.letsencrypt ? 's' : ''}://${answers.ghostDomain}`],
Mounts: [
{
Type: 'volume',
Source: volume.name,
Target: '/var/lib/ghost/content',
},
],
});
};
exports.runSetup = async ({answers, serverConfig, username, docker, util}) => {
// init log
const log = [];
const ghostVolumeName = answers.projectName.toLowerCase().replace(/\s/g, '-');
try {
util.logger.debug('starting work..');
// create new volume for ghost data
const ghostVolume = await docker.daemon.createVolume({Name: ghostVolumeName});
util.logger.debug(ghostVolume);
// pull latest image
await docker.pullImage(ghostImage);
// start ghost container
util.logger.debug('starting ghost..');
const ghost = await startGhost({util, answers, serverConfig, username, docker, volume: ghostVolume});
log.push({message: 'Ghost container started', data: ghost, level: 'info'});
util.logger.debug('created ghost container..');
} catch (e) {
util.logger.error('error:', e);
log.push({message: e.toString(), data: e, level: 'error'});
}
return log;
};