@vamship/build-utils 2.2.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/project.js +14 -10
- package/src/schema/project-definition.js +29 -0
- package/src/task-builders/docs-ts-task-builder.js +8 -4
- package/src/task-builders/package-container-task-builder.js +7 -1
- package/src/task-builders/publish-container-task-builder.js +3 -1
- package/src/task-builders/publish-task-builder.js +9 -3
- package/src/task-factories/api-task-factory.js +7 -6
- package/src/task-factories/cli-task-factory.js +17 -6
- package/src/task-factories/container-task-factory.js +7 -6
package/package.json
CHANGED
package/src/project.js
CHANGED
@@ -88,12 +88,15 @@ export class Project {
|
|
88
88
|
|
89
89
|
this._containerTargets = Object.keys(this._container).reduce(
|
90
90
|
(result, key) => {
|
91
|
-
const { repo, buildFile, buildArgs } =
|
91
|
+
const { repo, buildFile, buildArgs, buildSecrets } =
|
92
|
+
this._container[key];
|
93
|
+
|
92
94
|
result[key] = {
|
93
95
|
name: key,
|
94
96
|
repo,
|
95
|
-
buildFile,
|
96
|
-
buildArgs,
|
97
|
+
buildFile: buildFile || 'Dockerfile',
|
98
|
+
buildArgs: buildArgs || {},
|
99
|
+
buildSecrets: buildSecrets || {},
|
97
100
|
};
|
98
101
|
return result;
|
99
102
|
},
|
@@ -276,11 +279,7 @@ export class Project {
|
|
276
279
|
}
|
277
280
|
|
278
281
|
/**
|
279
|
-
* Returns a list of docker targets defined for the project.
|
280
|
-
* will define the following properties:
|
281
|
-
* - repo: The docker repo
|
282
|
-
* - buildFile: The name of the build file to use
|
283
|
-
* - buildArgs: Arguments to be passed to the docker build
|
282
|
+
* Returns a list of docker targets defined for the project.
|
284
283
|
*
|
285
284
|
* @return {Array}
|
286
285
|
*/
|
@@ -289,9 +288,14 @@ export class Project {
|
|
289
288
|
}
|
290
289
|
|
291
290
|
/**
|
292
|
-
* Gets
|
291
|
+
* Gets the definition for a specific container target. The definition will
|
292
|
+
* include the following properties:
|
293
|
+
* - repo: The docker repo
|
294
|
+
* - buildFile: The name of the build file to use
|
295
|
+
* - buildArgs: Arguments to be passed to the docker build
|
296
|
+
* - buildSecrets: Secrets to be passed to the docker build
|
293
297
|
*
|
294
|
-
* @param {String} target The
|
298
|
+
* @param {String} target The container target name
|
295
299
|
* @returns {Object} The container definition corresponding to the target.
|
296
300
|
*/
|
297
301
|
getContainerDefinition(target) {
|
@@ -109,6 +109,35 @@ export default {
|
|
109
109
|
},
|
110
110
|
additionalProperties: false,
|
111
111
|
},
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Collection of secrets passed to the
|
115
|
+
* container build.
|
116
|
+
*/
|
117
|
+
buildSecrets: {
|
118
|
+
type: 'object',
|
119
|
+
/**
|
120
|
+
* Individual build arguments
|
121
|
+
*/
|
122
|
+
patternProperties: {
|
123
|
+
'^[a-zA-Z0-9-_]+$': {
|
124
|
+
type: 'object',
|
125
|
+
properties: {
|
126
|
+
type: {
|
127
|
+
type: 'string',
|
128
|
+
minLength: 1,
|
129
|
+
},
|
130
|
+
src: {
|
131
|
+
type: 'string',
|
132
|
+
minLength: 1,
|
133
|
+
},
|
134
|
+
},
|
135
|
+
required: ['type', 'src'],
|
136
|
+
additionalProperties: false,
|
137
|
+
},
|
138
|
+
},
|
139
|
+
additionalProperties: false,
|
140
|
+
},
|
112
141
|
},
|
113
142
|
required: ['repo'],
|
114
143
|
additionalProperties: false,
|
@@ -35,12 +35,16 @@ export class DocsTsTaskBuilder extends TaskBuilder {
|
|
35
35
|
|
36
36
|
const { rootDir } = project;
|
37
37
|
const docsDir = rootDir.getChild('docs').getFilePath(project.version);
|
38
|
-
const
|
38
|
+
const srcPath = rootDir.getChild('src').getAllFilesGlob('ts');
|
39
39
|
|
40
40
|
const task = () =>
|
41
|
-
_execa(
|
42
|
-
|
43
|
-
|
41
|
+
_execa(
|
42
|
+
'typedoc',
|
43
|
+
['--out', docsDir, srcPath, '--entryPointStrategy', 'resolve'],
|
44
|
+
{
|
45
|
+
stdio: 'inherit',
|
46
|
+
},
|
47
|
+
).then(undefined, (err) => {
|
44
48
|
/*
|
45
49
|
* Do nothing. This handler prevents the gulp task from
|
46
50
|
* crashing with an unhandled error.
|
@@ -67,7 +67,7 @@ export class PackageContainerTaskBuilder extends TaskBuilder {
|
|
67
67
|
|
68
68
|
const repo =
|
69
69
|
typeof this._repo === 'undefined' ? definition.repo : this._repo;
|
70
|
-
const { buildFile, buildArgs } = definition;
|
70
|
+
const { buildFile, buildArgs, buildSecrets } = definition;
|
71
71
|
|
72
72
|
const dockerBin = 'docker';
|
73
73
|
const args = [
|
@@ -94,6 +94,12 @@ export class PackageContainerTaskBuilder extends TaskBuilder {
|
|
94
94
|
args.push(`${key}=${buildArgs[key]}`);
|
95
95
|
});
|
96
96
|
|
97
|
+
Object.keys(buildSecrets).forEach((key) => {
|
98
|
+
const { type, src } = buildSecrets[key];
|
99
|
+
args.push('--secret');
|
100
|
+
args.push(`id=${key},src=${src},type=${type}`);
|
101
|
+
});
|
102
|
+
|
97
103
|
args.push('.');
|
98
104
|
|
99
105
|
const task = () =>
|
@@ -31,7 +31,7 @@ export class PublishContainerTaskBuilder extends TaskBuilder {
|
|
31
31
|
super(
|
32
32
|
// When specifying the container target, if it is not called default, this
|
33
33
|
// will create a named task
|
34
|
-
`publish-container${target === 'default' ? '' : '-' + target}`,
|
34
|
+
`publish-container${target === 'default' ? '' : '-' + target}-${tag}`,
|
35
35
|
`Publish container image for ${target}:${tag}`,
|
36
36
|
);
|
37
37
|
|
@@ -71,6 +71,7 @@ export class PublishContainerTaskBuilder extends TaskBuilder {
|
|
71
71
|
* crashing with an unhandled error.
|
72
72
|
*/
|
73
73
|
});
|
74
|
+
tagTask.displayName = `tag-${definition.name}-${tag}`;
|
74
75
|
return tagTask;
|
75
76
|
});
|
76
77
|
const pushTaskList = semverComponents.map((tag) => {
|
@@ -84,6 +85,7 @@ export class PublishContainerTaskBuilder extends TaskBuilder {
|
|
84
85
|
* crashing with an unhandled error.
|
85
86
|
*/
|
86
87
|
});
|
88
|
+
pushTask.displayName = `push-${definition.name}-${tag}`;
|
87
89
|
return pushTask;
|
88
90
|
});
|
89
91
|
|
@@ -80,19 +80,25 @@ export class PublishTaskBuilder extends TaskBuilder {
|
|
80
80
|
}
|
81
81
|
// Type container
|
82
82
|
else if (type === 'container') {
|
83
|
-
return [
|
83
|
+
return [
|
84
|
+
new PublishContainerTaskBuilder('default', project.version),
|
85
|
+
];
|
84
86
|
}
|
85
87
|
// Type cli
|
86
88
|
else if (type === 'cli') {
|
87
89
|
if (containerTargetList.length > 0) {
|
88
|
-
return [
|
90
|
+
return [
|
91
|
+
new PublishContainerTaskBuilder('default', project.version),
|
92
|
+
];
|
89
93
|
} else {
|
90
94
|
return [new PublishNpmTaskBuilder()];
|
91
95
|
}
|
92
96
|
}
|
93
97
|
// Type api
|
94
98
|
else if (type === 'api') {
|
95
|
-
return [
|
99
|
+
return [
|
100
|
+
new PublishContainerTaskBuilder('default', project.version),
|
101
|
+
];
|
96
102
|
}
|
97
103
|
// Type ui (and potentially others that are not supported)
|
98
104
|
else {
|
@@ -42,13 +42,9 @@ export class ApiTaskFactory extends TaskFactory {
|
|
42
42
|
const additionalTaskList = (target) => {
|
43
43
|
return [
|
44
44
|
new PackageContainerTaskBuilder(target),
|
45
|
-
new PublishContainerTaskBuilder(target),
|
45
|
+
new PublishContainerTaskBuilder(target, this._project.version),
|
46
46
|
];
|
47
47
|
};
|
48
|
-
const additionalTasks = generateAdditionalContainerTasks(
|
49
|
-
this._project,
|
50
|
-
additionalTaskList,
|
51
|
-
);
|
52
48
|
|
53
49
|
return [
|
54
50
|
new CleanTaskBuilder(),
|
@@ -62,6 +58,11 @@ export class ApiTaskFactory extends TaskFactory {
|
|
62
58
|
new BuildTaskBuilder(this._project),
|
63
59
|
new PackageTaskBuilder(this._project),
|
64
60
|
new PublishTaskBuilder(this._project),
|
65
|
-
|
61
|
+
new PublishContainerTaskBuilder('default'),
|
62
|
+
].concat(
|
63
|
+
generateAdditionalContainerTasks(this._project, additionalTaskList),
|
64
|
+
); // Note: Instantiating the additional container tasks in a different
|
65
|
+
// order will break tests. This is less than ideal, but it will have
|
66
|
+
// to do for now.
|
66
67
|
}
|
67
68
|
}
|
@@ -44,13 +44,11 @@ export class CliTaskFactory extends TaskFactory {
|
|
44
44
|
const additionalTaskList = (target) => {
|
45
45
|
return [
|
46
46
|
new PackageContainerTaskBuilder(target),
|
47
|
-
new PublishContainerTaskBuilder(target),
|
47
|
+
new PublishContainerTaskBuilder(target, this._project.version),
|
48
48
|
];
|
49
49
|
};
|
50
|
-
|
51
|
-
|
52
|
-
additionalTaskList,
|
53
|
-
);
|
50
|
+
|
51
|
+
const hasContainer = this._project.getContainerTargets().length > 0;
|
54
52
|
|
55
53
|
return [
|
56
54
|
new CleanTaskBuilder(),
|
@@ -63,6 +61,19 @@ export class CliTaskFactory extends TaskFactory {
|
|
63
61
|
new BuildTaskBuilder(this._project),
|
64
62
|
new PackageTaskBuilder(this._project),
|
65
63
|
new PublishTaskBuilder(this._project),
|
66
|
-
|
64
|
+
hasContainer
|
65
|
+
? new PublishContainerTaskBuilder('default')
|
66
|
+
: undefined,
|
67
|
+
// Note: Instantiating the additional container tasks in a different
|
68
|
+
// order will break tests. This is less than ideal, but it will have
|
69
|
+
// to do for now.
|
70
|
+
]
|
71
|
+
.concat(
|
72
|
+
generateAdditionalContainerTasks(
|
73
|
+
this._project,
|
74
|
+
additionalTaskList,
|
75
|
+
),
|
76
|
+
)
|
77
|
+
.filter(Boolean);
|
67
78
|
}
|
68
79
|
}
|
@@ -42,13 +42,9 @@ export class ContainerTaskFactory extends TaskFactory {
|
|
42
42
|
const additionalTaskList = (target) => {
|
43
43
|
return [
|
44
44
|
new PackageContainerTaskBuilder(target),
|
45
|
-
new PublishContainerTaskBuilder(target),
|
45
|
+
new PublishContainerTaskBuilder(target, this._project.version),
|
46
46
|
];
|
47
47
|
};
|
48
|
-
const additionalTasks = generateAdditionalContainerTasks(
|
49
|
-
this._project,
|
50
|
-
additionalTaskList,
|
51
|
-
);
|
52
48
|
|
53
49
|
return [
|
54
50
|
new CleanTaskBuilder(),
|
@@ -59,6 +55,11 @@ export class ContainerTaskFactory extends TaskFactory {
|
|
59
55
|
new DocsTaskBuilder(this._project),
|
60
56
|
new PackageTaskBuilder(this._project),
|
61
57
|
new PublishTaskBuilder(this._project),
|
62
|
-
|
58
|
+
new PublishContainerTaskBuilder('default'),
|
59
|
+
].concat(
|
60
|
+
generateAdditionalContainerTasks(this._project, additionalTaskList),
|
61
|
+
); // Note: Instantiating the additional container tasks in a different
|
62
|
+
// order will break tests. This is less than ideal, but it will have
|
63
|
+
// to do for now.
|
63
64
|
}
|
64
65
|
}
|