release-it-docker-plugin 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of release-it-docker-plugin might be problematic. Click here for more details.
- package/package.json +2 -1
- package/src/index.js +73 -11
- package/src/base-plugin.js +0 -75
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "release-it-docker-plugin",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.4",
|
4
4
|
"description": "",
|
5
5
|
"keywords": [],
|
6
6
|
"repository": "",
|
@@ -8,6 +8,7 @@
|
|
8
8
|
"author": "Raiper34",
|
9
9
|
"license": "MIT",
|
10
10
|
"main": "src/index.js",
|
11
|
+
"type": "module",
|
11
12
|
"scripts": {
|
12
13
|
"build": "npx tsc"
|
13
14
|
},
|
package/src/index.js
CHANGED
@@ -1,22 +1,40 @@
|
|
1
|
-
import {
|
1
|
+
import { debug } from 'node:util';
|
2
|
+
import _ from 'lodash';
|
2
3
|
|
3
4
|
const DOCKER_HUB_BASE_URL = 'https://hub.docker.com';
|
4
5
|
|
5
|
-
export default class DockerPlugin
|
6
|
+
export default class DockerPlugin {
|
7
|
+
|
8
|
+
constructor({ namespace, options = {}, container = {} } = {}) {
|
9
|
+
this.namespace = namespace;
|
10
|
+
this.options = Object.freeze(this.getInitialOptions(options, namespace));
|
11
|
+
this.context = {};
|
12
|
+
this.config = container.config;
|
13
|
+
this.log = container.log;
|
14
|
+
this.shell = container.shell;
|
15
|
+
this.spinner = container.spinner;
|
16
|
+
this.prompt = container.prompt;
|
17
|
+
this.debug = debug(`release-it:${namespace}`);
|
18
|
+
|
19
|
+
this.registerPrompts({
|
20
|
+
build: {type: 'confirm', message: () => 'Build docker image?', default: !!this.options.build},
|
21
|
+
push: {type: 'confirm', message: () => 'Push to docker hub?', default: !!this.options.push},
|
22
|
+
});
|
23
|
+
}
|
6
24
|
|
7
25
|
async beforeRelease() {
|
8
26
|
if (this.options.build === false) return false;
|
9
|
-
return this.step({ task: () => this.build(), label: 'docker build', prompt:
|
27
|
+
return this.step({ task: () => this.build(), label: 'docker build', prompt: 'build'});
|
10
28
|
}
|
11
29
|
|
12
30
|
async release() {
|
13
|
-
if (this.options.
|
14
|
-
return this.step({ task: () => this.
|
31
|
+
if (this.options.push === false) return false;
|
32
|
+
return this.step({ task: () => this.push(), label: 'docker push', prompt: 'push'});
|
15
33
|
}
|
16
34
|
|
17
35
|
afterRelease() {
|
18
|
-
const {
|
19
|
-
if (
|
36
|
+
const { isPushed } = this.getContext();
|
37
|
+
if (isPushed) {
|
20
38
|
this.log.log(`🔗 ${DOCKER_HUB_BASE_URL}/r/${this.options.imageName}`);
|
21
39
|
}
|
22
40
|
}
|
@@ -24,7 +42,7 @@ export default class DockerPlugin extends BasePlugin{
|
|
24
42
|
build() {
|
25
43
|
const { imageName, latestTag } = this.options;
|
26
44
|
const args = [
|
27
|
-
'-t', `${imageName}:${this.
|
45
|
+
'-t', `${imageName}:${this.config.contextOptions.version}`,
|
28
46
|
...(latestTag ? ['-t', `${imageName}:latest`] : [])
|
29
47
|
];
|
30
48
|
return this.exec(`docker build ${args.filter(Boolean).join(' ')} .`).then(
|
@@ -36,17 +54,61 @@ export default class DockerPlugin extends BasePlugin{
|
|
36
54
|
);
|
37
55
|
}
|
38
56
|
|
39
|
-
|
57
|
+
push() {
|
40
58
|
const { imageName, latestTag } = this.options;
|
41
59
|
return Promise.all([
|
42
|
-
this.exec(`docker push ${imageName}:${this.
|
60
|
+
this.exec(`docker push ${imageName}:${this.config.contextOptions.version}`),
|
43
61
|
latestTag ? this.exec(`docker push ${imageName}:latest`) : Promise.resolve(),
|
44
62
|
]).then(
|
45
|
-
() => this.setContext({
|
63
|
+
() => this.setContext({ isPushed: true }),
|
46
64
|
(err) => {
|
47
65
|
this.debug(err);
|
48
66
|
throw new Error(err);
|
49
67
|
}
|
50
68
|
);
|
51
69
|
}
|
70
|
+
|
71
|
+
getInitialOptions(options, namespace) {
|
72
|
+
return options[namespace] || {};
|
73
|
+
}
|
74
|
+
|
75
|
+
init() {}
|
76
|
+
getName() {}
|
77
|
+
getLatestVersion() {}
|
78
|
+
getChangelog() {}
|
79
|
+
getIncrement() {}
|
80
|
+
getIncrementedVersionCI() {}
|
81
|
+
getIncrementedVersion() {}
|
82
|
+
beforeBump() {}
|
83
|
+
bump() {}
|
84
|
+
|
85
|
+
getContext(path) {
|
86
|
+
const context = _.merge({}, this.options, this.context);
|
87
|
+
return path ? _.get(context, path) : context;
|
88
|
+
}
|
89
|
+
|
90
|
+
setContext(context) {
|
91
|
+
_.merge(this.context, context);
|
92
|
+
}
|
93
|
+
|
94
|
+
exec(command, { options, context = {} } = {}) {
|
95
|
+
const ctx = Object.assign(context, this.config.getContext(), { [this.namespace]: this.getContext() });
|
96
|
+
return this.shell.exec(command, options, ctx);
|
97
|
+
}
|
98
|
+
|
99
|
+
registerPrompts(prompts) {
|
100
|
+
this.prompt.register(prompts, this.namespace);
|
101
|
+
}
|
102
|
+
|
103
|
+
async showPrompt(options) {
|
104
|
+
options.namespace = this.namespace;
|
105
|
+
return this.prompt.show(options);
|
106
|
+
}
|
107
|
+
|
108
|
+
step(options) {
|
109
|
+
const context = Object.assign({}, this.config.getContext(), { [this.namespace]: this.getContext() });
|
110
|
+
const opts = Object.assign({}, options, { context });
|
111
|
+
const isException = this.config.isPromptOnlyVersion && ['incrementList', 'publish', 'otp'].includes(opts.prompt);
|
112
|
+
return this.config.isCI && !isException ? this.spinner.show(opts) : this.showPrompt(opts);
|
113
|
+
}
|
52
114
|
}
|
package/src/base-plugin.js
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
import { debug } from 'node:util';
|
2
|
-
import _ from 'lodash';
|
3
|
-
|
4
|
-
// I was unable to import plugin class from release-it v18, so I copied and pasted it here and typed a bit for my use case.
|
5
|
-
// See: https://github.com/release-it/release-it/blob/main/lib/plugin/Plugin.js
|
6
|
-
class Plugin {
|
7
|
-
static isEnabled() {
|
8
|
-
return true;
|
9
|
-
}
|
10
|
-
|
11
|
-
static disablePlugin() {
|
12
|
-
return null;
|
13
|
-
}
|
14
|
-
|
15
|
-
constructor({ namespace, options = {}, container = {} } = {}) {
|
16
|
-
this.namespace = namespace;
|
17
|
-
this.options = Object.freeze(this.getInitialOptions(options, namespace));
|
18
|
-
this.context = {};
|
19
|
-
this.config = container.config;
|
20
|
-
this.log = container.log;
|
21
|
-
this.shell = container.shell;
|
22
|
-
this.spinner = container.spinner;
|
23
|
-
this.prompt = container.prompt;
|
24
|
-
this.debug = debug(`release-it:${namespace}`);
|
25
|
-
}
|
26
|
-
|
27
|
-
getInitialOptions(options, namespace) {
|
28
|
-
return options[namespace] || {};
|
29
|
-
}
|
30
|
-
|
31
|
-
init() {}
|
32
|
-
getName() {}
|
33
|
-
getLatestVersion() {}
|
34
|
-
getChangelog() {}
|
35
|
-
getIncrement() {}
|
36
|
-
getIncrementedVersionCI() {}
|
37
|
-
getIncrementedVersion() {}
|
38
|
-
beforeBump() {}
|
39
|
-
bump() {}
|
40
|
-
beforeRelease() {}
|
41
|
-
release() {}
|
42
|
-
afterRelease() {}
|
43
|
-
|
44
|
-
getContext(path) {
|
45
|
-
const context = _.merge({}, this.options, this.context);
|
46
|
-
return path ? _.get(context, path) : context;
|
47
|
-
}
|
48
|
-
|
49
|
-
setContext(context) {
|
50
|
-
_.merge(this.context, context);
|
51
|
-
}
|
52
|
-
|
53
|
-
exec(command, { options, context = {} } = {}) {
|
54
|
-
const ctx = Object.assign(context, this.config.getContext(), { [this.namespace]: this.getContext() });
|
55
|
-
return this.shell.exec(command, options, ctx);
|
56
|
-
}
|
57
|
-
|
58
|
-
registerPrompts(prompts) {
|
59
|
-
this.prompt.register(prompts, this.namespace);
|
60
|
-
}
|
61
|
-
|
62
|
-
async showPrompt(options) {
|
63
|
-
options.namespace = this.namespace;
|
64
|
-
return this.prompt.show(options);
|
65
|
-
}
|
66
|
-
|
67
|
-
step(options) {
|
68
|
-
const context = Object.assign({}, this.config.getContext(), { [this.namespace]: this.getContext() });
|
69
|
-
const opts = Object.assign({}, options, { context });
|
70
|
-
const isException = this.config.isPromptOnlyVersion && ['incrementList', 'publish', 'otp'].includes(opts.prompt);
|
71
|
-
return this.config.isCI && !isException ? this.spinner.show(opts) : this.showPrompt(opts);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
export default Plugin;
|