1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env node
import {
AnsiblePlaybookJob,
BuildDockerImageJob,
DefaultGitHookPipelineBuilder,
NpmPublishJob,
FetchCodeJob,
CoolifyWebhookJob,
Job,
} from '@emprespresso/ci_model';
import { join } from 'path';
const REGISTRY = 'img.liz.coffee';
const NAMESPACE = 'emprespresso';
const IMG = 'ci';
const REMOTE = 'https://code.liz.coffee';
const getPipeline = () => {
const gitHookPipeline = new DefaultGitHookPipelineBuilder();
const branch = gitHookPipeline.getBranch();
if (!branch) return gitHookPipeline.build();
const commonBuildArgs = {
context: gitHookPipeline.getSourceDestination(),
registry: REGISTRY,
namespace: NAMESPACE,
imageTag: branch,
};
const baseCiPackageBuild: BuildDockerImageJob = {
type: 'build_docker_image.js',
arguments: {
...commonBuildArgs,
repository: IMG + '_base',
buildTarget: IMG + '_base',
dockerfile: 'Dockerfile',
},
};
gitHookPipeline.addStage({
parallelJobs: [baseCiPackageBuild],
});
const subPackages = ['worker', 'server'].map(
(_package) =>
<BuildDockerImageJob>{
type: 'build_docker_image.js',
arguments: {
...commonBuildArgs,
repository: `${IMG}_${_package}`,
buildTarget: _package,
dockerfile: `${_package}/Dockerfile`,
},
},
);
subPackages.push(<BuildDockerImageJob>{
type: 'build_docker_image.js',
arguments: {
...commonBuildArgs,
repository: `${IMG}_packpub_npm`,
buildTarget: 'packpub_npm',
dockerfile: `Dockerfile`,
context: join(commonBuildArgs.context, 'packpub/npm'),
},
});
gitHookPipeline.addStage({
parallelJobs: subPackages,
});
const isRelease = branch === 'release';
if (!isRelease) {
return gitHookPipeline.build();
}
const publishModel: NpmPublishJob = {
type: 'npm_publish.js',
arguments: {
source: 'ci/model',
registry: 'registry.npmjs.org',
},
};
const deployWorker: CoolifyWebhookJob = {
type: 'coolify_webhook.js',
arguments: {
webhookUrl: 'https://plane.liz.coffee/api/v1/deploy?uuid=lg8400808cwo480wo4g44swg&force=false',
},
};
const deployServer: CoolifyWebhookJob = {
type: 'coolify_webhook.js',
arguments: {
webhookUrl: 'https://plane.liz.coffee/api/v1/deploy?uuid=gwsc0g8co84cwowggo8w4k0c&force=false'
},
};
gitHookPipeline.addStage({ parallelJobs: [
publishModel,
deployServer,
deployWorker,
] });
return gitHookPipeline.build();
};
const main = () => {
const data = getPipeline().serialize();
process.stdout.write(data);
};
main();
|