@wocker/mongodb-plugin 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,8 @@ import { MongodbService } from "../services/MongodbService";
2
2
  export declare class MongodbController {
3
3
  protected readonly mongodbService: MongodbService;
4
4
  constructor(mongodbService: MongodbService);
5
- create(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
5
+ create(name?: string, username?: string, password?: string, imageName?: string, imageVersion?: string): Promise<void>;
6
+ upgrade(name?: string, imageName?: string, imageVersion?: string, volume?: string, configVolume?: string): Promise<void>;
6
7
  destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
7
8
  use(name: string): Promise<void>;
8
9
  start(name?: string, restart?: boolean): Promise<void>;
@@ -28,15 +28,28 @@ let MongodbController = class MongodbController {
28
28
  constructor(mongodbService) {
29
29
  this.mongodbService = mongodbService;
30
30
  }
31
- create(name, imageName, imageVersion) {
31
+ create(name, username, password, imageName, imageVersion) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
33
  yield this.mongodbService.create({
34
34
  name,
35
+ username,
36
+ password,
35
37
  imageName,
36
38
  imageVersion
37
39
  });
38
40
  });
39
41
  }
42
+ upgrade(name, imageName, imageVersion, volume, configVolume) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ yield this.mongodbService.upgrade({
45
+ name,
46
+ imageName,
47
+ imageVersion,
48
+ volume,
49
+ configVolume
50
+ });
51
+ });
52
+ }
40
53
  destroy(name, yes, force) {
41
54
  return __awaiter(this, void 0, void 0, function* () {
42
55
  yield this.mongodbService.stop(name);
@@ -79,20 +92,58 @@ __decorate([
79
92
  (0, core_1.Command)("mongodb:create [name]"),
80
93
  (0, core_1.Description)("Creates a MongoDB service with configurable credentials, host, and storage options."),
81
94
  __param(0, (0, core_1.Param)("name")),
82
- __param(1, (0, core_1.Option)("image", {
95
+ __param(1, (0, core_1.Option)("user", {
96
+ type: "string",
97
+ alias: "u",
98
+ description: "The username to start the service with"
99
+ })),
100
+ __param(2, (0, core_1.Option)("password", {
101
+ type: "string",
102
+ alias: "p",
103
+ description: "The password to start the service with"
104
+ })),
105
+ __param(3, (0, core_1.Option)("image", {
83
106
  type: "string",
84
107
  alias: "i",
85
108
  description: "The image name to start the service with",
86
109
  })),
87
- __param(2, (0, core_1.Option)("image-version", {
110
+ __param(4, (0, core_1.Option)("image-version", {
88
111
  type: "string",
89
112
  alias: "I",
90
113
  description: "The image version to start the service with"
91
114
  })),
92
115
  __metadata("design:type", Function),
93
- __metadata("design:paramtypes", [String, String, String]),
116
+ __metadata("design:paramtypes", [String, String, String, String, String]),
94
117
  __metadata("design:returntype", Promise)
95
118
  ], MongodbController.prototype, "create", null);
119
+ __decorate([
120
+ (0, core_1.Command)("mongodb:upgrade [name]"),
121
+ (0, core_1.Description)("Upgrades a specified MongoDB service instance."),
122
+ __param(0, (0, core_1.Param)("name")),
123
+ __param(1, (0, core_1.Option)("image", {
124
+ type: "string",
125
+ alias: "i",
126
+ description: "The image name to start the service with"
127
+ })),
128
+ __param(2, (0, core_1.Option)("image-version", {
129
+ type: "string",
130
+ alias: "I",
131
+ description: "The image version to start the service with"
132
+ })),
133
+ __param(3, (0, core_1.Option)("volume", {
134
+ type: "string",
135
+ alias: "v",
136
+ description: "The volume name to start the service with"
137
+ })),
138
+ __param(4, (0, core_1.Option)("config-volume", {
139
+ type: "string",
140
+ alias: "V",
141
+ description: "The config volume name to start the service with"
142
+ })),
143
+ __metadata("design:type", Function),
144
+ __metadata("design:paramtypes", [String, String, String, String, String]),
145
+ __metadata("design:returntype", Promise)
146
+ ], MongodbController.prototype, "upgrade", null);
96
147
  __decorate([
97
148
  (0, core_1.Command)("mongodb:destroy <name>"),
98
149
  (0, core_1.Description)("Destroys a specified MongodbDB service instance with an option to force deletion."),
@@ -6,17 +6,24 @@ export type DatabaseProps = ConfigProperties & {
6
6
  password: string;
7
7
  configStorage?: string;
8
8
  storage?: string;
9
+ volume?: string;
10
+ configVolume?: string;
9
11
  };
10
12
  export declare class Database extends Config<DatabaseProps> {
11
13
  imageName?: string;
12
14
  imageVersion?: string;
13
15
  username: string;
14
16
  password: string;
15
- configStorage: string;
16
- storage: string;
17
+ protected _configVolume?: string;
18
+ protected _volume?: string;
17
19
  constructor(props: DatabaseProps);
18
20
  get containerName(): string;
19
21
  get image(): string;
22
+ get volume(): string;
23
+ set volume(volume: string);
24
+ get configVolume(): string;
25
+ set configVolume(configVolume: string);
20
26
  get defaultStorage(): string;
21
27
  get defaultConfigStorage(): string;
28
+ toObject(): DatabaseProps;
22
29
  }
@@ -5,26 +5,59 @@ const core_1 = require("@wocker/core");
5
5
  class Database extends core_1.Config {
6
6
  constructor(props) {
7
7
  super(props);
8
- const { imageName, imageVersion, username, password, configStorage, storage } = props;
8
+ const { name, imageName, imageVersion, username, password, configStorage, configVolume, storage, volume } = props;
9
+ this.name = name;
9
10
  this.imageName = imageName;
10
11
  this.imageVersion = imageVersion;
11
12
  this.username = username;
12
13
  this.password = password;
13
- this.configStorage = configStorage || this.defaultConfigStorage;
14
- this.storage = storage || this.defaultStorage;
14
+ this._configVolume = configStorage || configVolume;
15
+ this._volume = storage || volume;
15
16
  }
16
17
  get containerName() {
17
18
  return `mongodb-${this.name}.ws`;
18
19
  }
19
20
  get image() {
20
- const imageName = this.imageName || "mongo", imageVersion = this.imageVersion || "latest";
21
+ const imageName = this.imageName || "mongo", imageVersion = this.imageVersion;
22
+ if (!imageVersion) {
23
+ return imageName;
24
+ }
21
25
  return `${imageName}:${imageVersion}`;
22
26
  }
27
+ get volume() {
28
+ if (!this._volume) {
29
+ this._volume = this.defaultStorage;
30
+ }
31
+ return this._volume;
32
+ }
33
+ set volume(volume) {
34
+ this._volume = volume;
35
+ }
36
+ get configVolume() {
37
+ if (!this._configVolume) {
38
+ this._configVolume = this.defaultConfigStorage;
39
+ }
40
+ return this._configVolume;
41
+ }
42
+ set configVolume(configVolume) {
43
+ this._configVolume = configVolume;
44
+ }
23
45
  get defaultStorage() {
24
46
  return `wocker-mongodb-${this.name}`;
25
47
  }
26
48
  get defaultConfigStorage() {
27
49
  return `wocker-mongodb-config-${this.name}`;
28
50
  }
51
+ toObject() {
52
+ return {
53
+ name: this.name,
54
+ imageName: this.imageName,
55
+ imageVersion: this.imageVersion,
56
+ username: this.username,
57
+ password: this.password,
58
+ volume: this._volume,
59
+ configVolume: this._configVolume
60
+ };
61
+ }
29
62
  }
30
63
  exports.Database = Database;
@@ -11,7 +11,7 @@ export declare class MongodbService {
11
11
  constructor(appConfigService: AppConfigService, pluginConfigService: PluginConfigService, dockerService: DockerService, proxyService: ProxyService);
12
12
  get config(): Config;
13
13
  create(props?: Partial<DatabaseProps>): Promise<void>;
14
- upgrade(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
14
+ upgrade(props: Partial<DatabaseProps>): Promise<void>;
15
15
  destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
16
16
  use(name: string): void;
17
17
  start(name?: string, restart?: boolean): Promise<void>;
@@ -108,16 +108,24 @@ let MongodbService = class MongodbService {
108
108
  this.config.save();
109
109
  });
110
110
  }
111
- upgrade(name, imageName, imageVersion) {
111
+ upgrade(props) {
112
112
  return __awaiter(this, void 0, void 0, function* () {
113
- const service = this.config.getDatabaseOrDefault(name);
113
+ const service = this.config.getDatabaseOrDefault(props.name);
114
114
  let changed = false;
115
- if (imageName) {
116
- service.imageName = imageName;
115
+ if (props.imageName) {
116
+ service.imageName = props.imageName;
117
117
  changed = true;
118
118
  }
119
- if (imageVersion) {
120
- service.imageVersion = imageVersion;
119
+ if (props.imageVersion) {
120
+ service.imageVersion = props.imageVersion;
121
+ changed = true;
122
+ }
123
+ if (props.volume) {
124
+ service.volume = props.volume;
125
+ changed = true;
126
+ }
127
+ if (props.configVolume) {
128
+ service.configVolume = props.configVolume;
121
129
  changed = true;
122
130
  }
123
131
  if (changed) {
@@ -144,11 +152,11 @@ let MongodbService = class MongodbService {
144
152
  throw new Error("Aborted");
145
153
  }
146
154
  }
147
- if (database.configStorage === database.defaultConfigStorage && (yield this.dockerService.hasVolume(database.configStorage))) {
148
- yield this.dockerService.rmVolume(database.configStorage);
155
+ if (database.configVolume === database.defaultConfigStorage && (yield this.dockerService.hasVolume(database.configVolume))) {
156
+ yield this.dockerService.rmVolume(database.configVolume);
149
157
  }
150
- if (database.storage === database.defaultStorage && (yield this.dockerService.hasVolume(database.storage))) {
151
- yield this.dockerService.rmVolume(database.storage);
158
+ if (database.volume === database.defaultStorage && (yield this.dockerService.hasVolume(database.volume))) {
159
+ yield this.dockerService.rmVolume(database.volume);
152
160
  }
153
161
  this.config.removeDatabase(database.name);
154
162
  this.config.save();
@@ -174,6 +182,12 @@ let MongodbService = class MongodbService {
174
182
  container = null;
175
183
  }
176
184
  if (!container) {
185
+ if (!(yield this.dockerService.hasVolume(database.configVolume))) {
186
+ yield this.dockerService.createVolume(database.configVolume);
187
+ }
188
+ if (!(yield this.dockerService.hasVolume(database.volume))) {
189
+ yield this.dockerService.createVolume(database.volume);
190
+ }
177
191
  container = yield this.dockerService.createContainer({
178
192
  name: database.containerName,
179
193
  restart: "always",
@@ -185,8 +199,8 @@ let MongodbService = class MongodbService {
185
199
  MONGO_ROOT_PASSWORD: database.password
186
200
  },
187
201
  volumes: [
188
- `${database.configStorage}:/data/configdb`,
189
- `${database.storage}:/data/db`
202
+ `${database.configVolume}:/data/configdb`,
203
+ `${database.volume}:/data/db`
190
204
  ]
191
205
  });
192
206
  }
@@ -271,7 +285,7 @@ let MongodbService = class MongodbService {
271
285
  database.username,
272
286
  database.containerName,
273
287
  database.image,
274
- `${database.configStorage}\n${database.storage}`
288
+ `${database.configVolume}\n${database.volume}`
275
289
  ]);
276
290
  }
277
291
  return table.toString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/mongodb-plugin",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Mongodb plugin for wocker",
6
6
  "license": "MIT",