codefresh 1.3.6 → 2.0.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.
Files changed (42) hide show
  1. package/lib/binary/components.js +0 -57
  2. package/lib/interface/cli/commands/agent/install.cmd.js +6 -126
  3. package/lib/interface/cli/commands/components/download.cmd.js +1 -1
  4. package/lib/interface/cli/commands/hybrid/execute-test-pipeline.cmd.js +37 -11
  5. package/lib/interface/cli/commands/hybrid/helper.js +8 -896
  6. package/lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js +3 -103
  7. package/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +8 -134
  8. package/lib/interface/cli/completion/tree.json +1 -1
  9. package/lib/interface/cli/helpers/kubernetes.js +8 -42
  10. package/package.json +1 -10
  11. package/lib/interface/cli/commands/agent/uninstall.cmd.js +0 -92
  12. package/lib/interface/cli/commands/app-proxy/helper.js +0 -63
  13. package/lib/interface/cli/commands/app-proxy/install.cmd.js +0 -204
  14. package/lib/interface/cli/commands/app-proxy/uninstall.cmd.js +0 -175
  15. package/lib/interface/cli/commands/app-proxy/upgrade.cmd.js +0 -110
  16. package/lib/interface/cli/commands/gitops/argocd/install.js +0 -9
  17. package/lib/interface/cli/commands/gitops/argocd/uninstall.js +0 -11
  18. package/lib/interface/cli/commands/gitops/argocd/upgrade.js +0 -9
  19. package/lib/interface/cli/commands/gitops/codefresh/install.js +0 -50
  20. package/lib/interface/cli/commands/gitops/codefresh/uninstall.js +0 -14
  21. package/lib/interface/cli/commands/gitops/codefresh/upgrade.js +0 -9
  22. package/lib/interface/cli/commands/gitops/common/install.js +0 -62
  23. package/lib/interface/cli/commands/gitops/common/uninstall.js +0 -39
  24. package/lib/interface/cli/commands/gitops/common/upgrade.js +0 -45
  25. package/lib/interface/cli/commands/gitops/install.cmd.js +0 -116
  26. package/lib/interface/cli/commands/gitops/install.spec.js +0 -77
  27. package/lib/interface/cli/commands/gitops/uninstall.cmd.js +0 -56
  28. package/lib/interface/cli/commands/gitops/upgrade.cmd.js +0 -56
  29. package/lib/interface/cli/commands/hybrid/InstallationPlan.js +0 -216
  30. package/lib/interface/cli/commands/hybrid/delete.cmd.js +0 -341
  31. package/lib/interface/cli/commands/hybrid/init.cmd.js +0 -957
  32. package/lib/interface/cli/commands/hybrid/installation-process.js +0 -51
  33. package/lib/interface/cli/commands/hybrid/key-helper.js +0 -82
  34. package/lib/interface/cli/commands/hybrid/migration.js +0 -192
  35. package/lib/interface/cli/commands/hybrid/pipeline-helper.js +0 -71
  36. package/lib/interface/cli/commands/hybrid/upgrade.cmd.js +0 -195
  37. package/lib/interface/cli/commands/monitor/install.cmd.js +0 -160
  38. package/lib/interface/cli/commands/monitor/uninstall.cmd.js +0 -78
  39. package/lib/interface/cli/commands/root/uninstall.cmd.js +0 -17
  40. package/lib/interface/cli/commands/runtimeEnvironments/create.cmd.js +0 -23
  41. package/lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js +0 -149
  42. package/lib/interface/cli/helpers/progressEvents.js +0 -25
@@ -1,62 +0,0 @@
1
- const { detectProxy } = require('../../../helpers/general');
2
- const { downloadProvider } = require('../../hybrid/helper');
3
- const { Runner, components } = require('../../../../../binary');
4
- const _ = require('lodash');
5
-
6
- class GitopsInstaller {
7
- // eslint-disable-next-line class-methods-use-this
8
- async install(argv) {
9
- let { httpProxy, httpsProxy } = argv;
10
- const { kubeConfigPath, provider, argoHost, argoUsername, argoPassword, bypassDownload } = argv;
11
-
12
- const binLocation = await downloadProvider({ provider }, bypassDownload);
13
- const componentRunner = new Runner(binLocation);
14
-
15
- const commands = [
16
- 'install',
17
- ];
18
-
19
- if (kubeConfigPath) {
20
- commands.push('--kubeconfig');
21
- commands.push(kubeConfigPath);
22
- }
23
-
24
- const installOptions = _.pick(argv, ['git-integration', 'codefresh-integration', 'argo-token', 'output',
25
- 'update', 'kube-context-name', 'kube-namespace', 'sync-mode', 'sync-apps', 'codefresh-host',
26
- 'codefresh-token', 'codefresh-agent-suffix', 'in-cluster']);
27
- installOptions['argo-host'] = argoHost;
28
- installOptions['argo-username'] = argoUsername;
29
- installOptions['argo-password'] = argoPassword;
30
-
31
- _.forEach(_.pickBy(installOptions, _.identity), (value, key) => {
32
- if (_.isArray(value)) {
33
- value.forEach((item) => {
34
- commands.push(`--${key}`);
35
- commands.push(item);
36
- });
37
- } else {
38
- commands.push(`--${key}`);
39
- if (value !== true) commands.push(value);
40
- }
41
- });
42
-
43
- const detectedProxyVars = detectProxy();
44
- httpProxy = httpProxy || detectedProxyVars.httpProxy;
45
- httpsProxy = httpsProxy || detectedProxyVars.httpsProxy;
46
-
47
- if (httpProxy) {
48
- commands.push('--http-proxy');
49
- commands.push(httpProxy);
50
- }
51
-
52
- if (httpsProxy) {
53
- commands.push('--https-proxy');
54
- commands.push(httpsProxy);
55
- }
56
-
57
-
58
- await componentRunner.run(components.gitops[provider], commands);
59
- }
60
- }
61
-
62
- module.exports = new GitopsInstaller();
@@ -1,39 +0,0 @@
1
- const { downloadProvider } = require('../../hybrid/helper');
2
- const { Runner, components } = require('../../../../../binary');
3
- const _ = require('lodash');
4
-
5
- class GitopsUninstaller {
6
- // eslint-disable-next-line class-methods-use-this
7
- async uninstall(provider, argv) {
8
- const { 'kube-config-path': kubeConfigPath, 'bypass-download': bypassDownload } = argv;
9
- const binLocation = await downloadProvider({ provider }, bypassDownload);
10
- const componentRunner = new Runner(binLocation);
11
-
12
- const commands = [
13
- 'uninstall',
14
- ];
15
-
16
- if (kubeConfigPath) {
17
- commands.push('--kubeconfig');
18
- commands.push(kubeConfigPath);
19
- }
20
-
21
- const installOptions = _.omit(argv, 'kube-config-path');
22
-
23
- _.forEach(_.pickBy(installOptions, _.identity), (value, key) => {
24
- if (_.isArray(value)) {
25
- value.forEach((item) => {
26
- commands.push(`--${key}`);
27
- commands.push(item);
28
- });
29
- } else {
30
- commands.push(`--${key}`);
31
- if (value !== true) commands.push(value);
32
- }
33
- });
34
-
35
- await componentRunner.run(components.gitops[provider], commands);
36
- }
37
- }
38
-
39
- module.exports = new GitopsUninstaller();
@@ -1,45 +0,0 @@
1
- const { downloadProvider } = require('../../hybrid/helper');
2
- const { Runner, components } = require('../../../../../binary');
3
- const _ = require('lodash');
4
-
5
- class GitopsUpgrader {
6
- // eslint-disable-next-line class-methods-use-this
7
- async upgrade(argv) {
8
- const {
9
- provider,
10
- 'kube-config-path': kubeConfigPath,
11
- 'kube-namespace': kubeNamespace,
12
- 'kube-context-name': kubeContextName,
13
- 'in-cluster': inCluster,
14
- 'bypass-download': bypassDownload,
15
- } = argv;
16
-
17
- const binLocation = await downloadProvider({ provider }, bypassDownload);
18
- const componentRunner = new Runner(binLocation);
19
-
20
- const commands = [
21
- 'update',
22
- ];
23
-
24
- if (kubeConfigPath) {
25
- commands.push('--kubeconfig');
26
- commands.push(kubeConfigPath);
27
- }
28
- if (kubeNamespace) {
29
- commands.push('--kube-namespace');
30
- commands.push(kubeNamespace);
31
- }
32
- if (kubeContextName) {
33
- commands.push('--kube-context-name');
34
- commands.push(kubeContextName);
35
- }
36
- if (inCluster) {
37
- commands.push('--in-cluster');
38
- commands.push('true');
39
- }
40
-
41
- await componentRunner.run(components.gitops[provider], commands);
42
- }
43
- }
44
-
45
- module.exports = new GitopsUpgrader();
@@ -1,116 +0,0 @@
1
- /* eslint-disable max-len */
2
- const _ = require('lodash');
3
- const Command = require('../../Command');
4
- const installRoot = require('../root/install.cmd');
5
-
6
- const PROVIDERS = {
7
- codefresh: require('./codefresh/install'),
8
- 'argocd-agent': require('./argocd/install'),
9
- };
10
-
11
- const installArgoCmd = new Command({
12
- root: false,
13
- parent: installRoot,
14
- command: 'gitops <provider>',
15
- description: 'Install gitops',
16
- webDocs: {
17
- category: 'Gitops',
18
- title: 'Install',
19
- weight: 100,
20
- },
21
- builder: yargs => yargs
22
- .env('CF_ARG_')
23
- .positional('provider', {
24
- describe: 'Gitops provider',
25
- choices: ['codefresh', 'argocd-agent'],
26
- required: true,
27
- })
28
- .option('git-integration', {
29
- describe: 'Name of git integration in Codefresh',
30
- })
31
- .option('git-repo-url', {
32
- describe: 'Url to manifest repo',
33
- })
34
- .option('codefresh-integration', {
35
- describe: 'Name of gitops integration in Codefresh ( Please create a dedicated context for the agent to avoid hitting the Github rate limits )',
36
- })
37
- .option('argo-host', {
38
- describe: 'Host of argocd installation',
39
- })
40
- .option('argo-token', {
41
- describe: 'Token of argocd installation. Preferred auth method',
42
- })
43
- .option('argo-username', {
44
- describe: 'Username of existing argocd installation. Should be used with argo-password',
45
- })
46
- .option('argo-password', {
47
- describe: 'Password of existing argocd installation. Should be used with argo-username',
48
- })
49
- .option('update', {
50
- describe: 'Update gitops integration if exists',
51
- })
52
- .option('kube-config-path', {
53
- describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
54
- })
55
- .option('kube-context-name', {
56
- describe: 'Name of Kubernetes context',
57
- })
58
- .option('kube-namespace', {
59
- describe: 'Namespace in Kubernetes cluster',
60
- })
61
- .option('in-cluster', {
62
- type: 'boolean',
63
- default: false,
64
- describe: 'Use this option if gitops provider is been updated from inside a cluster',
65
- })
66
- .option('output', {
67
- describe: 'Path to k8s manifest output file, example: -o /home/user/out.yaml',
68
- alias: 'o',
69
- })
70
- .option('sync-mode', {
71
- choices: ['NONE', 'SELECT', 'CONTINUE_SYNC', 'ONE_TIME_SYNC'],
72
- describe: 'Synchronization mode\nNONE - don\'t synchronize\nSELECT - select applications for synchronization\nCONTINUE_SYNC - continuous synchronization\nONE_TIME_SYNC - synchronize one time',
73
- })
74
- .option('sync-apps', {
75
- array: true,
76
- describe: 'Applications to be synchronized',
77
- })
78
- .option('http-proxy', {
79
- describe: 'http proxy to be used in the runner',
80
- })
81
- .option('https-proxy', {
82
- describe: 'https proxy to be used in the runner',
83
- })
84
- .option('install-manifest', {
85
- describe: 'Url of argocd install manifest',
86
- default: 'https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml',
87
- })
88
- .option('set-argo-password', {
89
- describe: 'Set password for admin user of new argocd installation',
90
- })
91
- .option('codefresh-host', {
92
- describe: 'Codefresh api host',
93
- default: 'https://g.codefresh.io/',
94
- })
95
- .option('codefresh-agent-suffix', {
96
- describe: 'Suffix for agent application\'s resources. Can be used for installing multiple agents in one namespace',
97
- default: '',
98
- })
99
- .option('values', {
100
- describe: 'Specify values in a YAML file',
101
- })
102
- .option('bypass-download', {
103
- describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to use the binary from the components folder',
104
- default: false,
105
- type: 'boolean',
106
- }),
107
-
108
- handler: async (argv) => {
109
- const { provider } = argv;
110
-
111
- const providerInstaller = PROVIDERS[provider];
112
- return providerInstaller.install(argv);
113
- },
114
- });
115
-
116
- module.exports = installArgoCmd;
@@ -1,77 +0,0 @@
1
- const installCmd = require('./install.cmd').toCommand();
2
- const { Runner } = require('../../../../binary');
3
- const yargs = require('yargs');
4
-
5
- jest.mock('../hybrid/helper', () => ({
6
- downloadProvider: async () => {},
7
- }));
8
-
9
- jest.mock('../../../../binary');
10
-
11
- describe('install gitops', () => {
12
- beforeEach(async () => {
13
- Runner.mockClear();
14
- });
15
-
16
- it('install gitops argocd-agent w/o arguments', async () => {
17
- const argv = { provider: 'argocd-agent' };
18
- await installCmd.handler(argv);
19
- const { calls } = Runner.mock.instances[0].run.mock;
20
- expect(calls).toHaveLength(1);
21
- const [component, commands] = calls[0];
22
- expect(component.name).toEqual('gitops');
23
- expect(commands).toEqual(['install']);
24
- });
25
-
26
- it('install gitops argocd-agent with arguments', async () => {
27
- const argv = {
28
- provider: 'argocd-agent',
29
- 'git-integration': 'gitIntegration',
30
- 'codefresh-integration': 'codefreshIntegration',
31
- 'kube-context-name': 'kubeContextName',
32
- 'kube-namespace': 'kubeNamespace',
33
- 'sync-mode': 'SELECT',
34
- 'sync-apps': 'syncApps',
35
- };
36
- await installCmd.handler(argv);
37
- const { calls } = Runner.mock.instances[0].run.mock;
38
- expect(calls).toHaveLength(1);
39
- const [component, commands] = calls[0];
40
- expect(component.name).toEqual('gitops');
41
- expect(commands).toEqual([
42
- 'install',
43
- '--git-integration',
44
- 'gitIntegration',
45
- '--codefresh-integration',
46
- 'codefreshIntegration',
47
- '--kube-context-name',
48
- 'kubeContextName',
49
- '--kube-namespace',
50
- 'kubeNamespace',
51
- '--sync-mode',
52
- 'SELECT',
53
- '--sync-apps',
54
- 'syncApps',
55
- ]);
56
- });
57
-
58
- it('install gitops codefresh with required arguments', async () => {
59
- const argv = {
60
- provider: 'codefresh',
61
- 'set-argo-password': 'pass',
62
- setArgoPassword: 'pass',
63
- 'kube-namespace': 'ns',
64
- kubeNamespace: 'ns',
65
- };
66
- await installCmd.handler(argv);
67
- const { calls } = Runner.mock.instances[0].run.mock;
68
- expect(calls).toHaveLength(1);
69
- const [component, commands] = calls[0];
70
- expect(component.name).toEqual('cf-gitops-controller');
71
- expect(commands).toEqual([
72
- 'install',
73
- '--kube-namespace',
74
- 'ns',
75
- ]);
76
- });
77
- });
@@ -1,56 +0,0 @@
1
- /* eslint-disable max-len */
2
- const Command = require('../../Command');
3
- const unInstallRoot = require('../root/uninstall.cmd');
4
- const { downloadProvider } = require('../hybrid/helper');
5
- const { Runner, components } = require('../../../../binary');
6
- const codefreshProvider = require('./codefresh/uninstall');
7
- const argocdAgentProvider = require('./argocd/uninstall');
8
-
9
- const PROVIDERS = {
10
- codefresh: codefreshProvider,
11
- 'argocd-agent': argocdAgentProvider,
12
- };
13
-
14
- const unInstallAgentCmd = new Command({
15
- root: false,
16
- parent: unInstallRoot,
17
- command: 'gitops <provider>',
18
- description: 'Uninstall gitops agent',
19
- webDocs: {
20
- category: 'Gitops',
21
- title: 'Uninstall',
22
- weight: 100,
23
- },
24
- builder: yargs => yargs
25
- .env('CF_ARG_')
26
- .positional('provider', {
27
- describe: 'Gitops provider',
28
- choices: Object.keys(PROVIDERS),
29
- required: true,
30
- })
31
- .option('kube-config-path', {
32
- describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
33
- })
34
- .option('kube-context-name', {
35
- describe: 'Name of Kubernetes context',
36
- })
37
- .option('kube-namespace', {
38
- describe: 'Namespace in Kubernetes cluster',
39
- })
40
- .option('install-manifest', {
41
- describe: 'Url of argocd install manifest',
42
- default: 'https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml',
43
- })
44
- .option('in-cluster', {
45
- type: 'boolean',
46
- default: false,
47
- describe: 'Use this option if gitops provider is been updated from inside a cluster',
48
- }),
49
- handler: async (argv) => {
50
- const { provider } = argv;
51
- const providerInstaller = PROVIDERS[provider];
52
- return providerInstaller.uninstall(argv);
53
- },
54
- });
55
-
56
- module.exports = unInstallAgentCmd;
@@ -1,56 +0,0 @@
1
- const Command = require('../../Command');
2
- const upgradeRoot = require('../root/upgrade.cmd');
3
- const codefreshProvider = require('./codefresh/upgrade');
4
- const argocdAgentProvider = require('./argocd/upgrade');
5
-
6
- const PROVIDERS = {
7
- codefresh: codefreshProvider,
8
- 'argocd-agent': argocdAgentProvider,
9
- };
10
-
11
- const command = new Command({
12
- root: false,
13
- parent: upgradeRoot,
14
- command: 'gitops <provider>',
15
- description: 'Upgrade gitops agent',
16
- webDocs: {
17
- category: 'Gitops',
18
- title: 'Upgrade',
19
- weight: 100,
20
- },
21
- builder: (yargs) => {
22
- yargs
23
- .positional('provider', {
24
- describe: 'Gitops provider',
25
- choices: Object.keys(PROVIDERS),
26
- required: true,
27
- })
28
- .option('kube-config-path', {
29
- describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
30
- })
31
- .option('kube-namespace', {
32
- describe: 'Name of the namespace on which Argo agent should be updated',
33
- })
34
- .option('kube-context-name', {
35
- describe: 'Name of the kubernetes context where Argo agent should be updated (default is current-context)',
36
- })
37
- .option('in-cluster', {
38
- type: 'boolean',
39
- default: false,
40
- describe: 'Use this option if gitops provider is been updated from inside a cluster',
41
- })
42
- .example(
43
- 'codefresh upgrade gitops argocd-agent',
44
- 'Update gitops agent',
45
- );
46
- },
47
- handler: async (argv) => {
48
- const { provider } = argv;
49
-
50
- const providerInstaller = PROVIDERS[provider];
51
- return providerInstaller.upgrade(argv);
52
- },
53
- });
54
-
55
- module.exports = command;
56
-
@@ -1,216 +0,0 @@
1
- /* eslint-disable no-await-in-loop */
2
- const _ = require('lodash');
3
- const installationProgress = require('./installation-process');
4
- const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
5
- const colors = require('colors');
6
- const {
7
- resolve, join,
8
- } = require('path');
9
- const {
10
- homedir,
11
- } = require('os');
12
- const {
13
- existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync,
14
- } = require('fs');
15
-
16
- const CODEFRESH_PATH = resolve(homedir(), '.Codefresh');
17
- const RUNNER_INSTALLATIONS_PATH = join(CODEFRESH_PATH, 'installations');
18
- const INSTALLATION_STATE_FILE_PATH = join(RUNNER_INSTALLATIONS_PATH, 'installation_state.json');
19
- const STEP_STATUSES = {
20
- SUCCESS: 'success',
21
- FAILURE: 'failure',
22
- PENDING: 'pending',
23
- SKIPPED: 'skipped',
24
- };
25
-
26
- const DRY_RUN_VALUES = {
27
- agentName: 'dry-run-agent-id',
28
- agentToken: 'dry-run-token',
29
- runtimeName: 'dry-run-runtime-name',
30
- };
31
-
32
- function _ensureDirectory(location) {
33
- if (!existsSync(location)) {
34
- mkdirSync(location);
35
- }
36
- }
37
-
38
- class InstallationPlan {
39
- constructor({
40
- pendingSteps,
41
- finishedSteps,
42
- progressReporter,
43
- errHandler,
44
- context,
45
- }) {
46
- this.state = {
47
- pendingSteps: pendingSteps || [],
48
- finishedSteps: finishedSteps || [],
49
- context: context || {},
50
- };
51
- this.completedSteps = {}; // used for fast lookup of completed steps
52
- this.progressReporter = progressReporter;
53
- this.errHandler = errHandler;
54
- _ensureDirectory(RUNNER_INSTALLATIONS_PATH);
55
- }
56
-
57
- addStep({
58
- name,
59
- func,
60
- args,
61
- arg,
62
- errMessage,
63
- successMessage,
64
- installationEvent,
65
- exitOnError = true,
66
- condition = true,
67
- executeOnDryRun = false,
68
- bypassDownload,
69
- }) {
70
- if (!this.completedSteps[name]) {
71
- this.state.pendingSteps.push({
72
- name,
73
- func,
74
- args,
75
- arg,
76
- errMessage,
77
- successMessage,
78
- installationEvent,
79
- exitOnError,
80
- condition,
81
- executeOnDryRun,
82
- bypassDownload,
83
- status: STEP_STATUSES.PENDING,
84
- });
85
- }
86
- }
87
-
88
- reset() {
89
- this.state.finishedSteps = this.state.finishedSteps.filter((step) => {
90
- if (step.status === STEP_STATUSES.SUCCESS || step.status === STEP_STATUSES.SKIPPED) {
91
- this.completedSteps[step.name] = step;
92
- return true;
93
- }
94
- return false;
95
- });
96
-
97
- this.state.pendingSteps = [];
98
- }
99
-
100
- async execute() {
101
- while (this.state.pendingSteps.length) {
102
- const step = this.state.pendingSteps.shift();
103
- this.state.finishedSteps.push(step);
104
- const _args = step.args || [step.arg];
105
-
106
- let shouldSkip = false;
107
-
108
- if (this._isDryRun() && !step.executeOnDryRun) {
109
- shouldSkip = true;
110
- }
111
-
112
- if (!step.condition || (_.isFunction(step.condition) && !await step.condition())) {
113
- shouldSkip = true;
114
- }
115
-
116
- if (shouldSkip) {
117
- console.log(`skipping step: ${colors.cyan(step.name)}`);
118
- step.status = STEP_STATUSES.SKIPPED;
119
- this._writeState();
120
- // eslint-disable-next-line no-continue
121
- continue;
122
- }
123
-
124
- if (step.name) {
125
- console.log(`executing step: ${colors.cyan(step.name)}`);
126
- }
127
-
128
- const [stepErr] = await to(step.func(..._args));
129
- if (stepErr) {
130
- step.status = STEP_STATUSES.FAILURE;
131
- this._writeState();
132
- await this.errHandler(
133
- stepErr,
134
- step.errMessage || `Failed to ${step.name}`,
135
- this.progressReporter, step.installationEvent,
136
- step.exitOnError,
137
- );
138
- } else {
139
- step.status = STEP_STATUSES.SUCCESS;
140
- this._writeState();
141
- if (step.successMessage) {
142
- console.log(step.successMessage);
143
- }
144
- if (step.installationEvent && this.progressReporter) {
145
- await to(this.progressReporter.report(step.installationEvent, installationProgress.status.SUCCESS));
146
- }
147
- }
148
- }
149
-
150
- InstallationPlan._cleanup();
151
- }
152
-
153
- setProgressReporter(progressReporter) {
154
- this.progressReporter = progressReporter;
155
- }
156
-
157
- setErrorHandler(errHandler) {
158
- this.errHandler = errHandler;
159
- }
160
-
161
- addContext(key, value) {
162
- this.state.context[key] = value;
163
- }
164
-
165
- getContext(key) {
166
- if (this._isDryRun() && _.isUndefined(this.state.context.key)) {
167
- return DRY_RUN_VALUES[key];
168
- }
169
- return this.state.context[key];
170
- }
171
-
172
- _isDryRun() {
173
- const { argv } = this.state.context;
174
- return argv && argv.dryRun;
175
- }
176
-
177
- _writeState() {
178
- writeFileSync(INSTALLATION_STATE_FILE_PATH, JSON.stringify(this.state));
179
- }
180
-
181
- static _cleanup() {
182
- try {
183
- unlinkSync(INSTALLATION_STATE_FILE_PATH);
184
- } catch (err) {
185
- console.warn('** could not delete installation state file **');
186
- }
187
- }
188
-
189
- static restorePreviousState() {
190
- try {
191
- const data = readFileSync(join(RUNNER_INSTALLATIONS_PATH, 'installation_state.json'));
192
- const oldState = JSON.parse(data.toString('utf-8'));
193
- return new InstallationPlan({ ...oldState });
194
- } catch (err) {
195
- return undefined;
196
- }
197
- }
198
-
199
- printState() {
200
- this.state.finishedSteps.forEach((step) => {
201
- if (step.status === STEP_STATUSES.SUCCESS) {
202
- console.log(`${colors.green('✓')} ${step.name}`);
203
- } else if (step.status === STEP_STATUSES.SKIPPED) {
204
- console.log(`${colors.cyan('⤳')} ${step.name}`);
205
- } else if (step.status === STEP_STATUSES.FAILURE) {
206
- console.log(`${colors.red('✘')} ${step.name}`);
207
- }
208
- });
209
-
210
- this.state.pendingSteps.forEach((step) => {
211
- console.log(`${colors.white('◼')} ${step.name}`);
212
- });
213
- }
214
- }
215
-
216
- module.exports = InstallationPlan;