zeche 0.0.6 → 0.1.0
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.
|
@@ -90,12 +90,25 @@ class DeployDatabase {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
let tmpDirFrom = TMP_DIR;
|
|
94
|
+
if (fromEnvironment.paths.tmpDir) {
|
|
95
|
+
tmpDirFrom = fromEnvironment.paths.tmpDir;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let tmpDirTo = TMP_DIR;
|
|
99
|
+
if (toEnvironment.paths.tmpDir) {
|
|
100
|
+
tmpDirTo = toEnvironment.paths.tmpDir;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const filenameFrom = `${tmpDirFrom}/${fromEnvironment.db.database}__${moment().
|
|
104
|
+
format('YYYY_MM_DD_HH_mm_ss')}.sql`;
|
|
105
|
+
|
|
106
|
+
const filenameTo = `${tmpDirTo}/${fromEnvironment.db.database}__${moment().
|
|
94
107
|
format('YYYY_MM_DD_HH_mm_ss')}.sql`;
|
|
95
108
|
|
|
96
109
|
/** 1. Export dump on source environment: */
|
|
97
110
|
let exportCommands = [
|
|
98
|
-
`mysqldump --opt -h ${fromEnvironment.db.host} -P ${fromEnvironment.db.port} -u ${fromEnvironment.db.user} -p'${fromEnvironment.db.password}' ${fromEnvironment.db.database} > ${
|
|
111
|
+
`mysqldump --opt -h ${fromEnvironment.db.host} -P ${fromEnvironment.db.port} -u ${fromEnvironment.db.user} -p'${fromEnvironment.db.password}' ${fromEnvironment.db.database} > ${filenameFrom}`,
|
|
99
112
|
];
|
|
100
113
|
|
|
101
114
|
/** Container exec for docker/vagrant: */
|
|
@@ -106,7 +119,7 @@ class DeployDatabase {
|
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
/** Create tmp dir: */
|
|
109
|
-
exportCommands.unshift(`mkdir -p ${
|
|
122
|
+
exportCommands.unshift(`mkdir -p ${tmpDirFrom}`);
|
|
110
123
|
|
|
111
124
|
if (this.services.sshService.useSsh(fromEnvironment)) {
|
|
112
125
|
exportCommands = exportCommands.map(command => {
|
|
@@ -117,12 +130,12 @@ class DeployDatabase {
|
|
|
117
130
|
this.services.execService.exec(exportCommands);
|
|
118
131
|
|
|
119
132
|
/** 2. Copy dump to target environment: */
|
|
120
|
-
this.services.syncService.sync(
|
|
133
|
+
this.services.syncService.sync(filenameFrom, filenameTo, fromEnvironment,
|
|
121
134
|
toEnvironment);
|
|
122
135
|
|
|
123
136
|
/** 3. Import dump on target environment: */
|
|
124
137
|
let importCommands = [
|
|
125
|
-
`mysql -h ${toEnvironment.db.host} -P ${toEnvironment.db.port} -u ${toEnvironment.db.user} -p'${toEnvironment.db.password}' ${toEnvironment.db.database} < ${
|
|
138
|
+
`mysql -h ${toEnvironment.db.host} -P ${toEnvironment.db.port} -u ${toEnvironment.db.user} -p'${toEnvironment.db.password}' ${toEnvironment.db.database} < ${filenameTo}`,
|
|
126
139
|
];
|
|
127
140
|
|
|
128
141
|
/** Container exec for docker/vagrant: */
|
|
@@ -132,6 +145,9 @@ class DeployDatabase {
|
|
|
132
145
|
});
|
|
133
146
|
}
|
|
134
147
|
|
|
148
|
+
/** Create tmp dir to: */
|
|
149
|
+
exportCommands.unshift(`mkdir -p ${tmpDirTo}`);
|
|
150
|
+
|
|
135
151
|
if (this.services.sshService.useSsh(toEnvironment)) {
|
|
136
152
|
importCommands = importCommands.map(command => {
|
|
137
153
|
return this.services.sshService.wrapCommand(command, toEnvironment);
|
|
@@ -140,7 +156,7 @@ class DeployDatabase {
|
|
|
140
156
|
this.services.execService.exec(importCommands);
|
|
141
157
|
|
|
142
158
|
/** Remove dump on export environment: */
|
|
143
|
-
let cleanUpExportCommands = [`rm ${
|
|
159
|
+
let cleanUpExportCommands = [`rm ${filenameFrom}`];
|
|
144
160
|
if (this.services.sshService.useSsh(fromEnvironment)) {
|
|
145
161
|
cleanUpExportCommands = cleanUpExportCommands.map(command => {
|
|
146
162
|
return this.services.sshService.wrapCommand(command, fromEnvironment);
|
|
@@ -149,7 +165,7 @@ class DeployDatabase {
|
|
|
149
165
|
this.services.execService.exec(cleanUpExportCommands);
|
|
150
166
|
|
|
151
167
|
/** Remove dump on import environment: */
|
|
152
|
-
let cleanUpImportCommands = [`rm ${
|
|
168
|
+
let cleanUpImportCommands = [`rm ${filenameTo}`];
|
|
153
169
|
if (this.services.sshService.useSsh(toEnvironment)) {
|
|
154
170
|
cleanUpImportCommands = cleanUpImportCommands.map(command => {
|
|
155
171
|
return this.services.sshService.wrapCommand(command, toEnvironment);
|
|
@@ -160,4 +176,4 @@ class DeployDatabase {
|
|
|
160
176
|
|
|
161
177
|
}
|
|
162
178
|
|
|
163
|
-
module.exports = DeployDatabase;
|
|
179
|
+
module.exports = DeployDatabase;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const moment = require('moment');
|
|
5
|
-
const TMP_DIR = '/tmp/zechetmp';
|
|
6
5
|
|
|
7
6
|
module.exports = class DumpDatabase {
|
|
8
7
|
|
|
@@ -177,6 +176,7 @@ module.exports = class DumpDatabase {
|
|
|
177
176
|
`mysql -h ${environment.db.host} -P ${environment.db.port} -u ${environment.db.user} -p'${environment.db.password}' ${environment.db.database} < ${path}/${fullFilename}`,
|
|
178
177
|
];
|
|
179
178
|
|
|
179
|
+
|
|
180
180
|
/** Container exec for docker/vagrant: */
|
|
181
181
|
if (environment.db.container_exec) {
|
|
182
182
|
commands = commands.map(command => {
|
|
@@ -192,4 +192,4 @@ module.exports = class DumpDatabase {
|
|
|
192
192
|
|
|
193
193
|
this.services.execService.exec(commands);
|
|
194
194
|
}
|
|
195
|
-
};
|
|
195
|
+
};
|
package/lib/action/ssh.js
CHANGED
|
@@ -63,7 +63,6 @@ module.exports = class Ssh {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
init(environment) {
|
|
66
|
-
console.log('iniinit', environment);
|
|
67
66
|
if (!_.has(this.config, `environments.${environment}`)) {
|
|
68
67
|
this.services.outputService.print(
|
|
69
68
|
`environment ${environment} does not exist in configuration`,
|
|
@@ -94,4 +93,4 @@ module.exports = class Ssh {
|
|
|
94
93
|
this.services.execService.exec(commands);
|
|
95
94
|
|
|
96
95
|
}
|
|
97
|
-
};
|
|
96
|
+
};
|
|
@@ -58,7 +58,7 @@ class SyncService {
|
|
|
58
58
|
localToLocal(source, target) {
|
|
59
59
|
let commands = [
|
|
60
60
|
`mkdir -p ${target}`,
|
|
61
|
-
`rsync -r
|
|
61
|
+
`rsync -r --links ${source} ${target}`
|
|
62
62
|
];
|
|
63
63
|
this.services.execService.exec(commands);
|
|
64
64
|
}
|
|
@@ -70,7 +70,7 @@ class SyncService {
|
|
|
70
70
|
const key = targetEnvironment.ssh.key;
|
|
71
71
|
let commands = [
|
|
72
72
|
SyncService.getSSHCommand(targetEnvironment, `mkdir -p ${target}`),
|
|
73
|
-
`rsync -r
|
|
73
|
+
`rsync -r --links -e "ssh -i ${key} ${sshParams}" ${source} ${user}@${host}:${target}`
|
|
74
74
|
];
|
|
75
75
|
this.services.execService.exec(commands);
|
|
76
76
|
}
|
|
@@ -89,7 +89,7 @@ class SyncService {
|
|
|
89
89
|
const key = sourceEnvironment.ssh.key;
|
|
90
90
|
let commands = [];
|
|
91
91
|
commands.push(`mkdir -p ${target}`);
|
|
92
|
-
commands.push(`rsync -r
|
|
92
|
+
commands.push(`rsync -r --links -e "ssh -i ${key} ${sshParams}" ${user}@${host}:${source} ${target}`);
|
|
93
93
|
|
|
94
94
|
this.services.execService.exec(commands);
|
|
95
95
|
}
|