release-it-docker-plugin 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Filip Gulan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Release It! 🚀 - Docker plugin
2
+
3
+ Plugin to ability build docker images and push to docker hub in release-it workflow.
4
+
5
+ # Options
6
+ | Name | Default value | Description |
7
+ |-----------|---------------|--------------------------------------------------|
8
+ | build | false | if plugin should build docker image |
9
+ | push | false | if plugin should push docker image to docker hub |
10
+ | latestTag | false | if also `latest` tag should be built and pushed |
11
+ | imageName | undefined | name of docker image to build and push |
12
+
13
+ ## Example
14
+
15
+ ```json
16
+ {
17
+ "$schema": "https://unpkg.com/release-it/schema/release-it.json",
18
+ "plugins": {
19
+ "release-it-docker-plugin": {
20
+ "build": true,
21
+ "push": true,
22
+ "latestTag": true,
23
+ "imageName": "<YOUR_IMAGE_NAME>"
24
+ }
25
+ }
26
+ }
27
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "release-it-docker-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": "",
package/src/index.js CHANGED
@@ -1,22 +1,46 @@
1
- import {BasePlugin} from "./base-plugin";
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 extends BasePlugin {
6
+ export default class DockerPlugin {
7
+
8
+ static isEnabled() {
9
+ return true;
10
+ }
11
+
12
+ static disablePlugin() {
13
+ return null;
14
+ }
15
+
16
+ constructor({ namespace, options = {}, container = {} } = {}) {
17
+ this.namespace = namespace;
18
+ this.options = Object.freeze(this.getInitialOptions(options, namespace));
19
+ this.context = {};
20
+ this.config = container.config;
21
+ this.log = container.log;
22
+ this.shell = container.shell;
23
+ this.spinner = container.spinner;
24
+ this.prompt = container.prompt;
25
+ this.debug = debug(`release-it:${namespace}`);
26
+
27
+ this.registerPrompts({
28
+ build: {type: 'confirm', message: () => 'Build docker image?', default: !!this.options.build},
29
+ push: {type: 'confirm', message: () => 'Push to docker hub?', default: !!this.options.push},
30
+ });
31
+ }
6
32
 
7
33
  async beforeRelease() {
8
- if (this.options.build === false) return false;
9
- return this.step({ task: () => this.build(), label: 'docker build', prompt: {message: 'Build?', default: this.options.build}});
34
+ return this.step({ task: () => this.build(), label: 'docker build', prompt: 'build'});
10
35
  }
11
36
 
12
37
  async release() {
13
- if (this.options.publish === false) return false;
14
- return this.step({ task: () => this.publish(), label: 'docker publish', prompt: {message: 'Publish?', default: this.options.publish} });
38
+ return this.step({ task: () => this.push(), label: 'docker push', prompt: 'push'});
15
39
  }
16
40
 
17
41
  afterRelease() {
18
- const { isPublished } = this.getContext();
19
- if (isPublished) {
42
+ const { isPushed } = this.getContext();
43
+ if (isPushed) {
20
44
  this.log.log(`🔗 ${DOCKER_HUB_BASE_URL}/r/${this.options.imageName}`);
21
45
  }
22
46
  }
@@ -24,7 +48,7 @@ export default class DockerPlugin extends BasePlugin {
24
48
  build() {
25
49
  const { imageName, latestTag } = this.options;
26
50
  const args = [
27
- '-t', `${imageName}:${this.getContext().version}`,
51
+ '-t', `${imageName}:${this.config.contextOptions.version}`,
28
52
  ...(latestTag ? ['-t', `${imageName}:latest`] : [])
29
53
  ];
30
54
  return this.exec(`docker build ${args.filter(Boolean).join(' ')} .`).then(
@@ -36,17 +60,61 @@ export default class DockerPlugin extends BasePlugin {
36
60
  );
37
61
  }
38
62
 
39
- publish() {
63
+ push() {
40
64
  const { imageName, latestTag } = this.options;
41
65
  return Promise.all([
42
- this.exec(`docker push ${imageName}:${this.getContext().version}`),
66
+ this.exec(`docker push ${imageName}:${this.config.contextOptions.version}`),
43
67
  latestTag ? this.exec(`docker push ${imageName}:latest`) : Promise.resolve(),
44
68
  ]).then(
45
- () => this.setContext({ isPublished: true }),
69
+ () => this.setContext({ isPushed: true }),
46
70
  (err) => {
47
71
  this.debug(err);
48
72
  throw new Error(err);
49
73
  }
50
74
  );
51
75
  }
76
+
77
+ getInitialOptions(options, namespace) {
78
+ return options[namespace] || {};
79
+ }
80
+
81
+ init() {}
82
+ getName() {}
83
+ getLatestVersion() {}
84
+ getChangelog() {}
85
+ getIncrement() {}
86
+ getIncrementedVersionCI() {}
87
+ getIncrementedVersion() {}
88
+ beforeBump() {}
89
+ bump() {}
90
+
91
+ getContext(path) {
92
+ const context = _.merge({}, this.options, this.context);
93
+ return path ? _.get(context, path) : context;
94
+ }
95
+
96
+ setContext(context) {
97
+ _.merge(this.context, context);
98
+ }
99
+
100
+ exec(command, { options, context = {} } = {}) {
101
+ const ctx = Object.assign(context, this.config.getContext(), { [this.namespace]: this.getContext() });
102
+ return this.shell.exec(command, options, ctx);
103
+ }
104
+
105
+ registerPrompts(prompts) {
106
+ this.prompt.register(prompts, this.namespace);
107
+ }
108
+
109
+ async showPrompt(options) {
110
+ options.namespace = this.namespace;
111
+ return this.prompt.show(options);
112
+ }
113
+
114
+ step(options) {
115
+ const context = Object.assign({}, this.config.getContext(), { [this.namespace]: this.getContext() });
116
+ const opts = Object.assign({}, options, { context });
117
+ const isException = this.config.isPromptOnlyVersion && ['incrementList', 'publish', 'otp'].includes(opts.prompt);
118
+ return this.config.isCI && !isException ? this.spinner.show(opts) : this.showPrompt(opts);
119
+ }
52
120
  }
@@ -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;