@wocker/mongodb-plugin 1.0.4 → 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.
@@ -3,7 +3,7 @@ export declare class MongodbController {
3
3
  protected readonly mongodbService: MongodbService;
4
4
  constructor(mongodbService: MongodbService);
5
5
  create(name?: string, username?: string, password?: string, imageName?: string, imageVersion?: string): Promise<void>;
6
- upgrade(name?: string, imageName?: string, imageVersion?: string): Promise<void>;
6
+ upgrade(name?: string, imageName?: string, imageVersion?: string, volume?: string, configVolume?: string): Promise<void>;
7
7
  destroy(name: string, yes?: boolean, force?: boolean): Promise<void>;
8
8
  use(name: string): Promise<void>;
9
9
  start(name?: string, restart?: boolean): Promise<void>;
@@ -39,12 +39,14 @@ let MongodbController = class MongodbController {
39
39
  });
40
40
  });
41
41
  }
42
- upgrade(name, imageName, imageVersion) {
42
+ upgrade(name, imageName, imageVersion, volume, configVolume) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
44
  yield this.mongodbService.upgrade({
45
45
  name,
46
46
  imageName,
47
- imageVersion
47
+ imageVersion,
48
+ volume,
49
+ configVolume
48
50
  });
49
51
  });
50
52
  }
@@ -128,8 +130,18 @@ __decorate([
128
130
  alias: "I",
129
131
  description: "The image version to start the service with"
130
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
+ })),
131
143
  __metadata("design:type", Function),
132
- __metadata("design:paramtypes", [String, String, String]),
144
+ __metadata("design:paramtypes", [String, String, String, String, String]),
133
145
  __metadata("design:returntype", Promise)
134
146
  ], MongodbController.prototype, "upgrade", null);
135
147
  __decorate([
@@ -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;
@@ -120,6 +120,14 @@ let MongodbService = class MongodbService {
120
120
  service.imageVersion = props.imageVersion;
121
121
  changed = true;
122
122
  }
123
+ if (props.volume) {
124
+ service.volume = props.volume;
125
+ changed = true;
126
+ }
127
+ if (props.configVolume) {
128
+ service.configVolume = props.configVolume;
129
+ changed = true;
130
+ }
123
131
  if (changed) {
124
132
  this.config.setDatabase(service);
125
133
  this.config.save();
@@ -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.4",
3
+ "version": "1.0.5",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Mongodb plugin for wocker",
6
6
  "license": "MIT",