@contrail/cli 1.0.22 → 1.0.24
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/lib/apps/deploy-app/actions-deployer.d.ts +1 -1
- package/lib/apps/deploy-app/app-deployer.d.ts +2 -2
- package/lib/apps/deploy-app/app-deployer.js +4 -8
- package/lib/apps/deploy-app/app-template-parsers.d.ts +1 -1
- package/lib/apps/deploy-app/deploy.js +1 -2
- package/lib/apps/deploy-app/docker-action-builder.d.ts +10 -0
- package/lib/apps/deploy-app/docker-action-builder.js +97 -0
- package/lib/apps/deploy-app/interfaces.d.ts +2 -41
- package/lib/apps/deploy-app/workflow-definition-deployer.d.ts +2 -2
- package/lib/apps/deploy-app/workflow-definition-deployer.js +19 -15
- package/lib/cli.js +34 -9
- package/lib/colors/color-loader.js +3 -1
- package/lib/interfaces.d.ts +124 -0
- package/lib/interfaces.js +4 -0
- package/lib/workflows/workflow-template-deployer.d.ts +14 -0
- package/lib/workflows/workflow-template-deployer.js +127 -0
- package/lib/workflows/workflowCommands.d.ts +3 -0
- package/lib/workflows/workflowCommands.js +46 -0
- package/package.json +1 -1
- package/src/apps/deploy-app/actions-deployer.ts +1 -1
- package/src/apps/deploy-app/app-deployer.ts +5 -8
- package/src/apps/deploy-app/app-template-parsers.ts +1 -1
- package/src/apps/deploy-app/deploy.ts +2 -3
- package/src/apps/deploy-app/workflow-definition-deployer.ts +21 -18
- package/src/cli.ts +33 -9
- package/src/colors/color-loader.ts +3 -1
- package/src/{apps/deploy-app/interfaces.ts → interfaces.ts} +14 -6
- package/src/workflows/workflow-template-deployer.ts +157 -0
- package/src/workflows/workflowCommands.ts +54 -0
- package/templates/typescript/app.yml +1 -0
- package/src/apps/deploy-app/workflow-deployer.ts +0 -111
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import { WorkflowTemplateDeclaration } from '../interfaces';
|
|
6
|
+
import { getSeparatorByPlatform } from '../common';
|
|
7
|
+
const yaml = require('js-yaml');
|
|
8
|
+
import { WorkflowTemplateDeployer } from './workflow-template-deployer';
|
|
9
|
+
|
|
10
|
+
export async function deleteWorkflowTemplate() {
|
|
11
|
+
let wtDeclaration: WorkflowTemplateDeclaration;
|
|
12
|
+
try {
|
|
13
|
+
wtDeclaration = loadTemplateConfig();
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
await authUser();
|
|
21
|
+
await new WorkflowTemplateDeployer().deleteWorkflowTemplates(wtDeclaration);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function deployWorkflowTemplate() {
|
|
25
|
+
let wtDeclaration: WorkflowTemplateDeclaration;
|
|
26
|
+
try {
|
|
27
|
+
wtDeclaration = loadTemplateConfig();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
console.log(`%s Workflow Deletion Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await authUser();
|
|
35
|
+
await new WorkflowTemplateDeployer().deployWorkflows(wtDeclaration);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export async function listWorkflowTemplate() {
|
|
40
|
+
await authUser();
|
|
41
|
+
return await new WorkflowTemplateDeployer().listExistingWorkflowTemplates();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function loadTemplateConfig() {
|
|
45
|
+
const TARGET_DIR = process.cwd();
|
|
46
|
+
try {
|
|
47
|
+
const separator = getSeparatorByPlatform();
|
|
48
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'workflow.yml', 'utf8'));
|
|
49
|
+
console.log(doc);
|
|
50
|
+
return doc;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -4,6 +4,7 @@ appDescription: "Your app description."
|
|
|
4
4
|
visibility: public
|
|
5
5
|
publisher: "Your company name"
|
|
6
6
|
version: 1.0
|
|
7
|
+
isDockerBased: true # this flag should be deprecated since all apps should be docker-based anyway
|
|
7
8
|
|
|
8
9
|
# eventWorkflowTriggerKeyMapping will be used to parse an incoming event into a key that can trigger workflows
|
|
9
10
|
# {} indicates a field on the event. You can use nested fields by separating the levels with a '.'
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Entities } from '@contrail/sdk';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { App, AppDeclaration, WorkflowTemplateDeclaration } from './interfaces';
|
|
4
|
-
import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer'
|
|
5
|
-
|
|
6
|
-
export class WorkflowDeployer {
|
|
7
|
-
async deployWorkflows(appDeclaration: AppDeclaration, app: App) {
|
|
8
|
-
|
|
9
|
-
// FETCH ALL WORKFLOWS FROM THE API.
|
|
10
|
-
const existingWorkflows = await this.getWorkflowsForApp(app);
|
|
11
|
-
|
|
12
|
-
// UPSERT / DELETE BASED ON WORKFLOW IDENTIFIER
|
|
13
|
-
console.log('%s \tDeploying workflows.', chalk.yellow.bold('WORKFLOW'));
|
|
14
|
-
|
|
15
|
-
for (const workflowKey of Object.keys(appDeclaration.workflows)) {
|
|
16
|
-
await this.deployWorkflow(workflowKey,
|
|
17
|
-
appDeclaration.workflows[workflowKey] as WorkflowTemplateDeclaration,
|
|
18
|
-
app,
|
|
19
|
-
existingWorkflows,
|
|
20
|
-
appDeclaration);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getWorkflowsForApp(app: App) {
|
|
25
|
-
return await new Entities().get({
|
|
26
|
-
entityName: 'event-workflow-template',
|
|
27
|
-
criteria: { ownerKey: `app:${app.id}` },
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async deployWorkflow(workflowKey: string, workflow: WorkflowTemplateDeclaration, app: App, existingWorkflows: Array<any>, appDeclaration: AppDeclaration) {
|
|
32
|
-
console.log(`%s \tDeploying workflow: ${workflowKey}`, chalk.yellow.bold('WORKFLOW'));
|
|
33
|
-
|
|
34
|
-
const identifier = this.getWorkflowDeclarationIdentifier(workflowKey, app);
|
|
35
|
-
const existingDefinition = existingWorkflows.find(ad => ad.identifier === identifier);
|
|
36
|
-
|
|
37
|
-
if (existingDefinition) {
|
|
38
|
-
return await this.updateWorkflowDefinition(existingDefinition, workflow, app, appDeclaration);
|
|
39
|
-
}
|
|
40
|
-
return await this.createNewWorkflowDefinition(workflowKey, workflow, app, appDeclaration);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private async createNewWorkflowDefinition(workflowKey: string, workflowDeclaration: WorkflowTemplateDeclaration, app: App, appDeclaration: AppDeclaration) {
|
|
44
|
-
await this.populateActionIds(workflowDeclaration, appDeclaration, app);
|
|
45
|
-
const newObject: WorkflowTemplateDeclaration = {
|
|
46
|
-
identifier: this.getWorkflowDeclarationIdentifier(workflowKey, app),
|
|
47
|
-
name: workflowDeclaration.name,
|
|
48
|
-
ownerKey: `app:${app.id}`,
|
|
49
|
-
triggerKey: workflowDeclaration.triggerKey,
|
|
50
|
-
workflowDefinition: workflowDeclaration.workflowDefinition,
|
|
51
|
-
isActive: workflowDeclaration.isActive,
|
|
52
|
-
supportingAppId: workflowDeclaration.supportingAppId,
|
|
53
|
-
messageGroupId: workflowDeclaration.messageGroupId,
|
|
54
|
-
parallelWorkerCount: workflowDeclaration.parallelWorkerCount,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const workflowTemplate = await new Entities().create({
|
|
58
|
-
entityName: 'event-workflow-template',
|
|
59
|
-
object: newObject,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
console.log(`%s Created new workflow definition: ${workflowKey}`, chalk.yellow.bold('WORKFLOW'));
|
|
63
|
-
|
|
64
|
-
return workflowTemplate;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private async populateActionIds(workflowDeclaration: WorkflowTemplateDeclaration, appDeclaration: AppDeclaration, app: App) {
|
|
68
|
-
let availableAppActions = await getActionsForApp(app);
|
|
69
|
-
if (!workflowDeclaration.workflowDefinition?.paths) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
for (const path of workflowDeclaration.workflowDefinition.paths) {
|
|
73
|
-
if (!path?.actionDefinitionConfigs) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
for (const actionConfiguration of path.actionDefinitionConfigs) {
|
|
77
|
-
const actionKey = actionConfiguration.action;
|
|
78
|
-
const action = availableAppActions.find(
|
|
79
|
-
action => action.identifier === getActionDeclarationIdentifier(actionKey, app)
|
|
80
|
-
)
|
|
81
|
-
if (!action) {
|
|
82
|
-
throw new Error(`Could not find action ${actionKey} declared in ${workflowDeclaration.name}`);
|
|
83
|
-
}
|
|
84
|
-
actionConfiguration.id = action.id;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private async updateWorkflowDefinition(existingWorkflowDefinition: WorkflowTemplateDeclaration, workflowDeclaration: WorkflowTemplateDeclaration, app: App, appDeclaration: AppDeclaration) {
|
|
90
|
-
await this.populateActionIds(workflowDeclaration, appDeclaration, app);
|
|
91
|
-
const updates = Object.assign(new Object(), {
|
|
92
|
-
name: workflowDeclaration.name,
|
|
93
|
-
triggerKey: workflowDeclaration.triggerKey,
|
|
94
|
-
workflowDefinition: workflowDeclaration.workflowDefinition
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const updatedWorkflowDefinition = await new Entities().update({
|
|
98
|
-
entityName: 'event-workflow-template',
|
|
99
|
-
id: existingWorkflowDefinition.id,
|
|
100
|
-
object: updates,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
console.log(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk.yellow.bold('WORKFLOW'));
|
|
104
|
-
|
|
105
|
-
return updatedWorkflowDefinition;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
getWorkflowDeclarationIdentifier(actionKey, app: App) {
|
|
109
|
-
return app.identifier + ':' + actionKey;
|
|
110
|
-
}
|
|
111
|
-
}
|