-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (37 loc) · 1.64 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
/* jshint node: true */
'use strict';
const BasePlugin = require('ember-cli-deploy-plugin');
const child_process = require('child_process');
module.exports = {
name: 'ember-cli-deploy-docker-hub',
createDeployPlugin(options) {
const DeployPlugin = BasePlugin.extend({
name: options.name,
defaultConfig: { dockerFilePath: 'Dockerfile' }, // eslint-disable-line
requiredConfig: [ 'repository' ], // eslint-disable-line
spawnProcess() {
let result = child_process.spawnSync(...arguments); // eslint-disable-line
if(result.status != 0){
this.log(`Error: ${result.stderr}`, { color: 'red' });
return
}
},
upload(context) {
const repositoryName = this.readConfig('repository');
const revisionKey = context.revisionData.revisionKey
const revisionedName = `${repositoryName}:${revisionKey}`;
const latestName = `${repositoryName}:latest`;
this.log(`Generating docker build ${revisionedName}`);
this.spawnProcess('docker', ['build','-f', this.readConfig('dockerFilePath'), '-t', revisionedName, '.'])
this.log(`Generating docker build ${latestName}`);
this.spawnProcess('docker', ['build','-f', this.readConfig('dockerFilePath'), '-t', latestName, '.']);
this.log(`Pushing image to repository: ${revisionedName}`);
this.spawnProcess('docker', ['push', revisionedName]);
this.log(`Pushing image to repository: ${latestName}`);
this.spawnProcess('docker', ['push', latestName]);
this.log('All done!');
}
});
return new DeployPlugin();
}
};