mythix 2.5.5 → 2.5.7
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.
- package/package.json +1 -1
- package/src/cli/cli-utils.js +1 -1
- package/src/cli/deploy-command.js +66 -11
package/package.json
CHANGED
package/src/cli/cli-utils.js
CHANGED
|
@@ -478,7 +478,7 @@ async function executeCommand(_config, appOptions, commandContext, CommandKlass,
|
|
|
478
478
|
args,
|
|
479
479
|
{
|
|
480
480
|
env: {
|
|
481
|
-
NODE_ENV: commandContext.environment ||
|
|
481
|
+
NODE_ENV: commandContext.environment || process.env.NODE_ENV,
|
|
482
482
|
MYTHIX_RUNTIME: runtime,
|
|
483
483
|
MYTHIX_CONFIG_PATH: configPath,
|
|
484
484
|
MYTHIX_COMMAND_PATH: commandPath,
|
|
@@ -12,7 +12,8 @@ const { defineCommand } = require('./cli-utils');
|
|
|
12
12
|
const { Logger } = require('../logger');
|
|
13
13
|
const { walkDir } = require('../utils/file-utils');
|
|
14
14
|
|
|
15
|
-
const DEFAULT_SSH_PORT
|
|
15
|
+
const DEFAULT_SSH_PORT = 22;
|
|
16
|
+
const LATEST_DEPLOY_VERSIONS_TO_KEEP = 5;
|
|
16
17
|
|
|
17
18
|
module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
18
19
|
return class DeployCommand extends Parent {
|
|
@@ -494,12 +495,12 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
494
495
|
if (options && Nife.isNotEmpty(options.sshArgs))
|
|
495
496
|
args = args.concat(options.sshArgs);
|
|
496
497
|
else
|
|
497
|
-
args = args.concat([ '-t' ]);
|
|
498
|
+
args = args.concat([ '-t', '-q' ]);
|
|
498
499
|
|
|
499
500
|
if (Nife.isNotEmpty(args))
|
|
500
501
|
args = args.map((arg) => this.substituteURLParams(target, arg));
|
|
501
502
|
|
|
502
|
-
await this.spawnCommand(
|
|
503
|
+
return await this.spawnCommand(
|
|
503
504
|
dryRun,
|
|
504
505
|
command,
|
|
505
506
|
args.concat([
|
|
@@ -560,9 +561,13 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
560
561
|
return await this.iterateDeployTargets(deployConfig, this.remoteDeploy.bind(this));
|
|
561
562
|
}
|
|
562
563
|
|
|
563
|
-
async copyFileToRemote(target, deployConfig,
|
|
564
|
+
async copyFileToRemote(target, deployConfig, _filePath, options) {
|
|
565
|
+
let filePath = _filePath;
|
|
566
|
+
let fileName = Path.basename(filePath);
|
|
567
|
+
|
|
564
568
|
let {
|
|
565
569
|
dryRun,
|
|
570
|
+
tempLocation,
|
|
566
571
|
} = deployConfig;
|
|
567
572
|
|
|
568
573
|
let {
|
|
@@ -584,6 +589,16 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
584
589
|
args = [];
|
|
585
590
|
}
|
|
586
591
|
|
|
592
|
+
if (!dryRun && options && typeof options.substituteContent === 'function') {
|
|
593
|
+
let content = FileSystem.readFileSync(filePath, 'utf8');
|
|
594
|
+
content = options.substituteContent.call(this, content);
|
|
595
|
+
|
|
596
|
+
await this.mkdirSync(false, tempLocation);
|
|
597
|
+
|
|
598
|
+
filePath = Path.join(tempLocation, fileName);
|
|
599
|
+
FileSystem.writeFileSync(filePath, content, 'utf8');
|
|
600
|
+
}
|
|
601
|
+
|
|
587
602
|
await this.spawnCommand(
|
|
588
603
|
dryRun,
|
|
589
604
|
command,
|
|
@@ -593,7 +608,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
593
608
|
]),
|
|
594
609
|
);
|
|
595
610
|
|
|
596
|
-
return `/tmp/${
|
|
611
|
+
return `/tmp/${fileName}`;
|
|
597
612
|
}
|
|
598
613
|
|
|
599
614
|
async copyArchiveToRemote(target, deployConfig) {
|
|
@@ -638,20 +653,25 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
638
653
|
relativeConfigPath,
|
|
639
654
|
} = deployConfig;
|
|
640
655
|
|
|
641
|
-
let deployLocation
|
|
642
|
-
let targetConfigPath
|
|
643
|
-
let sourceConfigPath
|
|
644
|
-
let
|
|
656
|
+
let deployLocation = this.joinUnixPath(decodeURIComponent(target.pathname), '' + deployConfig.version);
|
|
657
|
+
let targetConfigPath = this.joinUnixPath(decodeURIComponent(target.pathname), 'shared', 'config');
|
|
658
|
+
let sourceConfigPath = this.joinUnixPath(deployLocation, relativeConfigPath);
|
|
659
|
+
let nodeModulesLink = this.joinUnixPath(targetConfigPath, 'node_modules');
|
|
645
660
|
|
|
661
|
+
// Ensure shared/config exists
|
|
646
662
|
await this.executeRemoteCommands(target, deployConfig, [
|
|
647
663
|
{ command: 'test', args: [ '!', '-d', `"${targetConfigPath}"`, '&&', `${this.sudo(deployConfig)}cp -a "${sourceConfigPath}" "${targetConfigPath}"`, '|| true' ] },
|
|
648
664
|
]);
|
|
649
665
|
|
|
666
|
+
// Ensure shared/config/node_modules symlink exists
|
|
667
|
+
await this.executeRemoteCommands(target, deployConfig, [
|
|
668
|
+
{ command: 'test', args: [ '!', '-e', `"${nodeModulesLink}"`, '&&', `{ cd "${targetConfigPath}"; ${this.sudo(deployConfig)}ln -s "../../current/node_modules" "node_modules"; }`, '|| true' ] },
|
|
669
|
+
]);
|
|
670
|
+
|
|
671
|
+
// Remove app/config and symlink to ../shared/app/config
|
|
650
672
|
await this.executeRemoteCommands(target, deployConfig, [
|
|
651
673
|
{ command: 'rm', args: [ '-fr', `"${sourceConfigPath}"` ] },
|
|
652
674
|
{ command: 'ln', args: [ '-s', `"${targetConfigPath}"`, `"${sourceConfigPath}"` ] },
|
|
653
|
-
{ command: 'rm', args: [ '-f', `"${currentLinkLocation}"` ] },
|
|
654
|
-
{ command: 'ln', args: [ '-s', `"${deployLocation}"`, `"${currentLinkLocation}"` ] },
|
|
655
675
|
]);
|
|
656
676
|
|
|
657
677
|
await this.installModulesForApp(target, deployConfig);
|
|
@@ -665,6 +685,25 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
665
685
|
);
|
|
666
686
|
}
|
|
667
687
|
|
|
688
|
+
async cleanupOldDeployVersions(target, deployConfig) {
|
|
689
|
+
let deployLocation = decodeURIComponent(target.pathname);
|
|
690
|
+
|
|
691
|
+
let result = await this.executeRemoteCommands(target, deployConfig, [
|
|
692
|
+
{ command: 'ls', args: [ '-1', `"${deployLocation}"`, '|', 'grep', '-P', '"\\d+"' ] },
|
|
693
|
+
]);
|
|
694
|
+
|
|
695
|
+
let versions = result.stdout.split(/\n+/g).map((part) => part.trim()).filter(Boolean).sort();
|
|
696
|
+
let versionsToRemove = versions.slice(0, -LATEST_DEPLOY_VERSIONS_TO_KEEP);
|
|
697
|
+
|
|
698
|
+
if (Nife.isNotEmpty(versionsToRemove)) {
|
|
699
|
+
versionsToRemove = versionsToRemove.map((part) => `"${this.joinUnixPath(deployLocation, part)}"`);
|
|
700
|
+
|
|
701
|
+
await this.executeRemoteCommands(target, deployConfig, [
|
|
702
|
+
{ command: 'rm', args: [ '-fr' ].concat(versionsToRemove) },
|
|
703
|
+
]);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
668
707
|
async remoteFinalizeDeploy(target, deployConfig) {
|
|
669
708
|
if (typeof target.finalizeDeploy === 'function')
|
|
670
709
|
return await target.finalizeDeploy.call(this, target, deployConfig);
|
|
@@ -678,6 +717,18 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
678
717
|
]);
|
|
679
718
|
}
|
|
680
719
|
|
|
720
|
+
// Finally, upon success, swap the "current" symlink to
|
|
721
|
+
// point to the new deploy
|
|
722
|
+
let deployLocation = this.joinUnixPath(decodeURIComponent(target.pathname), '' + deployConfig.version);
|
|
723
|
+
let currentLinkLocation = this.joinUnixPath(decodeURIComponent(target.pathname), 'current');
|
|
724
|
+
await this.executeRemoteCommands(target, deployConfig, [
|
|
725
|
+
{ command: 'rm', args: [ '-f', `"${currentLinkLocation}"` ] },
|
|
726
|
+
{ command: 'ln', args: [ '-s', `"${deployLocation}"`, `"${currentLinkLocation}"` ] },
|
|
727
|
+
]);
|
|
728
|
+
|
|
729
|
+
// Cleanup old deploy versions
|
|
730
|
+
await this.cleanupOldDeployVersions(target, deployConfig);
|
|
731
|
+
|
|
681
732
|
if (Nife.isNotEmpty(target.restartService)) {
|
|
682
733
|
await this.executeRemoteCommands(target, deployConfig, [
|
|
683
734
|
target.restartService,
|
|
@@ -717,6 +768,8 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
717
768
|
return 1;
|
|
718
769
|
}
|
|
719
770
|
|
|
771
|
+
deployConfig.target = args.target;
|
|
772
|
+
|
|
720
773
|
deployConfig.targets = deployConfig.targets.filter(Boolean).map((target) => {
|
|
721
774
|
if (Nife.instanceOf(target, 'string')) {
|
|
722
775
|
return {
|
|
@@ -877,6 +930,8 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
|
|
|
877
930
|
await this.allRemotesDeploy(deployConfig);
|
|
878
931
|
await this.allRemotesPostDeploy(deployConfig);
|
|
879
932
|
await this.allRemotesFinalizeDeploy(deployConfig);
|
|
933
|
+
|
|
934
|
+
console.log(`Deployment of version "${deployConfig.version}" completed successfully!`);
|
|
880
935
|
} catch (error) {
|
|
881
936
|
console.error(error);
|
|
882
937
|
return 1;
|