@nibgat/ncli 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +156 -2
- package/dist/bin/ncli.d.ts +2 -0
- package/dist/bin/ncli.js +9 -0
- package/dist/bin/ncli.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.js +723 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/buyment.d.ts +2 -0
- package/dist/commands/buyment.js +174 -0
- package/dist/commands/buyment.js.map +1 -0
- package/dist/commands/cloud.d.ts +2 -0
- package/dist/commands/cloud.js +281 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/context.d.ts +25 -0
- package/dist/commands/context.js +92 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/front.d.ts +2 -0
- package/dist/commands/front.js +135 -0
- package/dist/commands/front.js.map +1 -0
- package/dist/commands/git.d.ts +2 -0
- package/dist/commands/git.js +726 -0
- package/dist/commands/git.js.map +1 -0
- package/dist/commands/health.d.ts +2 -0
- package/dist/commands/health.js +99 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/mail.d.ts +2 -0
- package/dist/commands/mail.js +265 -0
- package/dist/commands/mail.js.map +1 -0
- package/dist/commands/pipeline.d.ts +2 -0
- package/dist/commands/pipeline.js +333 -0
- package/dist/commands/pipeline.js.map +1 -0
- package/dist/commands/profile.d.ts +2 -0
- package/dist/commands/profile.js +229 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/runner.d.ts +2 -0
- package/dist/commands/runner.js +266 -0
- package/dist/commands/runner.js.map +1 -0
- package/dist/commands/support.d.ts +2 -0
- package/dist/commands/support.js +133 -0
- package/dist/commands/support.js.map +1 -0
- package/dist/constants/index.d.ts +26 -0
- package/dist/constants/index.js +40 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/http/client.d.ts +46 -0
- package/dist/http/client.js +262 -0
- package/dist/http/client.js.map +1 -0
- package/dist/http/coreApi.d.ts +136 -0
- package/dist/http/coreApi.js +485 -0
- package/dist/http/coreApi.js.map +1 -0
- package/dist/http/gitApi.d.ts +128 -0
- package/dist/http/gitApi.js +255 -0
- package/dist/http/gitApi.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/pipeline/detect.d.ts +13 -0
- package/dist/pipeline/detect.js +90 -0
- package/dist/pipeline/detect.js.map +1 -0
- package/dist/pipeline/release.d.ts +36 -0
- package/dist/pipeline/release.js +250 -0
- package/dist/pipeline/release.js.map +1 -0
- package/dist/pipeline/schema.d.ts +10 -0
- package/dist/pipeline/schema.js +155 -0
- package/dist/pipeline/schema.js.map +1 -0
- package/dist/runner/config.d.ts +21 -0
- package/dist/runner/config.js +235 -0
- package/dist/runner/config.js.map +1 -0
- package/dist/runner/server.d.ts +25 -0
- package/dist/runner/server.js +803 -0
- package/dist/runner/server.js.map +1 -0
- package/dist/runner/systemd.d.ts +14 -0
- package/dist/runner/systemd.js +82 -0
- package/dist/runner/systemd.js.map +1 -0
- package/dist/runner/tarExtract.d.ts +4 -0
- package/dist/runner/tarExtract.js +215 -0
- package/dist/runner/tarExtract.js.map +1 -0
- package/dist/security/execSafe.d.ts +20 -0
- package/dist/security/execSafe.js +216 -0
- package/dist/security/execSafe.js.map +1 -0
- package/dist/security/pkce.d.ts +9 -0
- package/dist/security/pkce.js +35 -0
- package/dist/security/pkce.js.map +1 -0
- package/dist/security/redact.d.ts +3 -0
- package/dist/security/redact.js +76 -0
- package/dist/security/redact.js.map +1 -0
- package/dist/security/sanitize.d.ts +18 -0
- package/dist/security/sanitize.js +216 -0
- package/dist/security/sanitize.js.map +1 -0
- package/dist/security/vault.d.ts +34 -0
- package/dist/security/vault.js +291 -0
- package/dist/security/vault.js.map +1 -0
- package/dist/types/index.d.ts +116 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/output.d.ts +25 -0
- package/dist/ui/output.js +100 -0
- package/dist/ui/output.js.map +1 -0
- package/dist/ui/prompt.d.ts +4 -0
- package/dist/ui/prompt.js +100 -0
- package/dist/ui/prompt.js.map +1 -0
- package/package.json +54 -5
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_DELIVERY_CACHE_LIMIT, DEFAULT_WEBHOOK_MAX_AGE_SEC, DEFAULT_DELIVERY_TTL_MS, PIPELINE_CONFIG_FILENAME, MAX_WEBHOOK_BODY_BYTES, DEFAULT_REGISTRY_HOST, NCLI_VERSION } from "../constants/index.js";
|
|
7
|
+
import { GitApiClient } from "../http/gitApi.js";
|
|
8
|
+
import { validateComposeIdentifier, validateRelativeSubPath, validateStaticTargetDir, validateRegistryHost, validateBuildScript, sanitizeDockerTag, validateGitRef, parseRepoSpec, isPathInside } from "../security/sanitize.js";
|
|
9
|
+
import { redactSensitiveText } from "../security/redact.js";
|
|
10
|
+
import { checkBinaryAvailable, execSafe } from "../security/execSafe.js";
|
|
11
|
+
import { validatePipelineConfig } from "../pipeline/schema.js";
|
|
12
|
+
import { extractTarGzSafely } from "./tarExtract.js";
|
|
13
|
+
export const computeWebhookSignature = (rawBody, secret) => {
|
|
14
|
+
const hex = crypto
|
|
15
|
+
.createHmac("sha256", secret)
|
|
16
|
+
.update(rawBody)
|
|
17
|
+
.digest("hex");
|
|
18
|
+
return `sha256=${hex}`;
|
|
19
|
+
};
|
|
20
|
+
export const verifyWebhookSignature = (rawBody, signatureHeader, secret) => {
|
|
21
|
+
if (!secret || !signatureHeader || !signatureHeader.startsWith("sha256=")) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const providedHex = signatureHeader.slice(7).trim().toLowerCase();
|
|
25
|
+
if (!/^[a-f0-9]{64}$/.test(providedHex)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const expectedHex = crypto
|
|
29
|
+
.createHmac("sha256", secret)
|
|
30
|
+
.update(rawBody)
|
|
31
|
+
.digest("hex")
|
|
32
|
+
.toLowerCase();
|
|
33
|
+
if (providedHex.length !== expectedHex.length) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return crypto.timingSafeEqual(Buffer.from(providedHex, "hex"), Buffer.from(expectedHex, "hex"));
|
|
37
|
+
};
|
|
38
|
+
const atomicSyncStaticDir = async (srcDist, targetDir) => {
|
|
39
|
+
const parentDir = path.dirname(targetDir);
|
|
40
|
+
fs.mkdirSync(parentDir, {
|
|
41
|
+
recursive: true
|
|
42
|
+
});
|
|
43
|
+
if (process.platform !== "win32") {
|
|
44
|
+
const rsyncInfo = await checkBinaryAvailable("rsync", "--version");
|
|
45
|
+
if (rsyncInfo.available) {
|
|
46
|
+
fs.mkdirSync(targetDir, {
|
|
47
|
+
recursive: true
|
|
48
|
+
});
|
|
49
|
+
await execSafe("rsync", [
|
|
50
|
+
"-a",
|
|
51
|
+
"--delete",
|
|
52
|
+
`${srcDist}/`,
|
|
53
|
+
`${targetDir}/`
|
|
54
|
+
]);
|
|
55
|
+
return "rsync";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const suffix = `${Date.now()}-${crypto.randomBytes(4).toString("hex")}`;
|
|
59
|
+
const stagingDir = path.join(parentDir, `.${path.basename(targetDir)}.staging-${suffix}`);
|
|
60
|
+
const backupDir = path.join(parentDir, `.${path.basename(targetDir)}.prev-${suffix}`);
|
|
61
|
+
fs.cpSync(srcDist, stagingDir, {
|
|
62
|
+
recursive: true,
|
|
63
|
+
force: true
|
|
64
|
+
});
|
|
65
|
+
const hadTarget = fs.existsSync(targetDir);
|
|
66
|
+
try {
|
|
67
|
+
if (hadTarget) {
|
|
68
|
+
fs.renameSync(targetDir, backupDir);
|
|
69
|
+
}
|
|
70
|
+
fs.renameSync(stagingDir, targetDir);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
if (hadTarget && fs.existsSync(backupDir) && !fs.existsSync(targetDir)) {
|
|
74
|
+
fs.renameSync(backupDir, targetDir);
|
|
75
|
+
}
|
|
76
|
+
fs.rmSync(stagingDir, {
|
|
77
|
+
recursive: true,
|
|
78
|
+
force: true
|
|
79
|
+
});
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
if (fs.existsSync(backupDir)) {
|
|
83
|
+
fs.rmSync(backupDir, {
|
|
84
|
+
recursive: true,
|
|
85
|
+
force: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return "atomic-swap";
|
|
89
|
+
};
|
|
90
|
+
const sendJson = (res, statusCode, data) => {
|
|
91
|
+
const body = JSON.stringify(data);
|
|
92
|
+
res.writeHead(statusCode, {
|
|
93
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
94
|
+
"X-Content-Type-Options": "nosniff",
|
|
95
|
+
"Cache-Control": "no-store"
|
|
96
|
+
});
|
|
97
|
+
res.end(body);
|
|
98
|
+
};
|
|
99
|
+
export const startRunnerServer = async (config, options) => {
|
|
100
|
+
const gitClient = new GitApiClient(config.gitUrl);
|
|
101
|
+
const activeLocks = new Set();
|
|
102
|
+
const seenDeliveries = new Map();
|
|
103
|
+
const ipRateLimits = new Map();
|
|
104
|
+
const buildQueue = [];
|
|
105
|
+
let activeGlobalBuilds = 0;
|
|
106
|
+
const maxConcurrentBuilds = 1;
|
|
107
|
+
const enqueueBuild = (fn) => {
|
|
108
|
+
const pump = () => {
|
|
109
|
+
if (activeGlobalBuilds >= maxConcurrentBuilds || buildQueue.length === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const next = buildQueue.shift();
|
|
113
|
+
if (!next) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
activeGlobalBuilds += 1;
|
|
117
|
+
void next().finally(() => {
|
|
118
|
+
activeGlobalBuilds = Math.max(0, activeGlobalBuilds - 1);
|
|
119
|
+
pump();
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
buildQueue.push(fn);
|
|
123
|
+
pump();
|
|
124
|
+
};
|
|
125
|
+
const isIpRateLimited = (ip) => {
|
|
126
|
+
const now = Date.now();
|
|
127
|
+
if (ipRateLimits.size > 2000) {
|
|
128
|
+
for (const [k, v] of ipRateLimits.entries()) {
|
|
129
|
+
if (v.resetAt <= now) {
|
|
130
|
+
ipRateLimits.delete(k);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const rec = ipRateLimits.get(ip);
|
|
135
|
+
if (!rec || rec.resetAt <= now) {
|
|
136
|
+
ipRateLimits.set(ip, {
|
|
137
|
+
resetAt: now + 60_000,
|
|
138
|
+
count: 1
|
|
139
|
+
});
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
rec.count += 1;
|
|
143
|
+
return rec.count > 60;
|
|
144
|
+
};
|
|
145
|
+
const webhookPath = config.webhookPath || "/webhook";
|
|
146
|
+
const maxAgeSec = config.webhookMaxAgeSec ?? DEFAULT_WEBHOOK_MAX_AGE_SEC;
|
|
147
|
+
const log = (msg) => {
|
|
148
|
+
const line = `[ncli-runner] ${redactSensitiveText(msg)}`;
|
|
149
|
+
if (options?.onLog) {
|
|
150
|
+
options.onLog(line);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
process.stdout.write(`${line}\n`);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
// Normalize repo keys to lowercase
|
|
157
|
+
const allowlistedRepos = new Map();
|
|
158
|
+
for (const [rawRepoKey, repoCfg] of Object.entries(config.repos)) {
|
|
159
|
+
const parsed = parseRepoSpec(rawRepoKey);
|
|
160
|
+
allowlistedRepos.set(parsed.fullName, repoCfg);
|
|
161
|
+
}
|
|
162
|
+
const pruneDeliveries = (nowMs) => {
|
|
163
|
+
for (const [id, expiresAt] of seenDeliveries.entries()) {
|
|
164
|
+
if (expiresAt <= nowMs) {
|
|
165
|
+
seenDeliveries.delete(id);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (seenDeliveries.size > DEFAULT_DELIVERY_CACHE_LIMIT) {
|
|
169
|
+
const excess = seenDeliveries.size - DEFAULT_DELIVERY_CACHE_LIMIT;
|
|
170
|
+
let removed = 0;
|
|
171
|
+
for (const key of seenDeliveries.keys()) {
|
|
172
|
+
seenDeliveries.delete(key);
|
|
173
|
+
removed += 1;
|
|
174
|
+
if (removed >= excess) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const executeRepoDeployment = async (params) => {
|
|
181
|
+
const startedAt = Date.now();
|
|
182
|
+
const logLines = [];
|
|
183
|
+
const reportUpdate = async (stage, message, status, extra) => {
|
|
184
|
+
const ts = new Date().toISOString().slice(11, 19);
|
|
185
|
+
const cleanMessage = redactSensitiveText(message);
|
|
186
|
+
logLines.push(`[${ts}] [${stage.toUpperCase()}] ${cleanMessage}`);
|
|
187
|
+
log(`${params.fullName}@${params.ref} [${stage}] ${cleanMessage}`);
|
|
188
|
+
try {
|
|
189
|
+
await gitClient.reportDeployment(params.owner, params.repo, {
|
|
190
|
+
deploymentId: params.deploymentId,
|
|
191
|
+
id: params.deploymentId,
|
|
192
|
+
repoFullName: params.fullName,
|
|
193
|
+
runnerName: config.runnerName,
|
|
194
|
+
runnerId: params.repoCfg.runnerId,
|
|
195
|
+
triggeredBy: params.triggeredBy,
|
|
196
|
+
releaseTag: params.releaseTag,
|
|
197
|
+
durationMs: Date.now() - startedAt,
|
|
198
|
+
updatedAt: new Date().toISOString(),
|
|
199
|
+
event: params.event,
|
|
200
|
+
ref: params.ref,
|
|
201
|
+
logs: logLines.join("\n").slice(-48_000),
|
|
202
|
+
status,
|
|
203
|
+
stage,
|
|
204
|
+
...(extra || {})
|
|
205
|
+
}, params.repoCfg.runnerToken);
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
log(`Warning: deployment report callback failed (${err instanceof Error ? err.message : "error"})`);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
if (activeLocks.has(params.fullName)) {
|
|
212
|
+
await reportUpdate("queued", `Concurrent deployment already active for ${params.fullName}.`, "failed", {
|
|
213
|
+
finishedAt: new Date().toISOString()
|
|
214
|
+
});
|
|
215
|
+
const skippedRes = {
|
|
216
|
+
deploymentId: params.deploymentId,
|
|
217
|
+
repoFullName: params.fullName,
|
|
218
|
+
durationMs: Date.now() - startedAt,
|
|
219
|
+
error: "concurrent-deployment-locked",
|
|
220
|
+
logs: logLines.join("\n"),
|
|
221
|
+
status: "failed",
|
|
222
|
+
ref: params.ref
|
|
223
|
+
};
|
|
224
|
+
options?.onDeploymentComplete?.(skippedRes);
|
|
225
|
+
return skippedRes;
|
|
226
|
+
}
|
|
227
|
+
activeLocks.add(params.fullName);
|
|
228
|
+
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), "ncli-runner-"));
|
|
229
|
+
try {
|
|
230
|
+
await reportUpdate("downloading", `Downloading source archive for ${params.fullName}@${params.ref}...`, "building");
|
|
231
|
+
const archiveBuf = await gitClient.downloadArchive(params.owner, params.repo, params.ref, params.repoCfg.runnerToken);
|
|
232
|
+
extractTarGzSafely(archiveBuf, workDir, {
|
|
233
|
+
stripSingleTopDir: true
|
|
234
|
+
});
|
|
235
|
+
const allowedStaticRoot = params.repoCfg.allowedStaticRoot || config.allowedStaticRoot || "/var/www";
|
|
236
|
+
const deployCfgPath = path.join(workDir, PIPELINE_CONFIG_FILENAME);
|
|
237
|
+
let rawPipeline = null;
|
|
238
|
+
if (fs.existsSync(deployCfgPath)) {
|
|
239
|
+
rawPipeline = JSON.parse(fs.readFileSync(deployCfgPath, "utf8"));
|
|
240
|
+
await reportUpdate("config", `Loaded ${PIPELINE_CONFIG_FILENAME} from repository.`, "building");
|
|
241
|
+
}
|
|
242
|
+
else if (params.repoCfg.type) {
|
|
243
|
+
if (params.repoCfg.type === "docker") {
|
|
244
|
+
rawPipeline = {
|
|
245
|
+
composeService: params.repoCfg.composeService,
|
|
246
|
+
composeProject: params.repoCfg.composeProject,
|
|
247
|
+
composeFiles: params.repoCfg.composeFiles,
|
|
248
|
+
composeDir: params.repoCfg.composeDir,
|
|
249
|
+
subDir: params.repoCfg.subDir,
|
|
250
|
+
image: params.repoCfg.image,
|
|
251
|
+
type: "docker"
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
rawPipeline = {
|
|
256
|
+
buildScript: params.repoCfg.buildScript,
|
|
257
|
+
skipInstall: params.repoCfg.skipInstall,
|
|
258
|
+
skipBuild: params.repoCfg.skipBuild,
|
|
259
|
+
targetDir: params.repoCfg.targetDir,
|
|
260
|
+
distDir: params.repoCfg.distDir,
|
|
261
|
+
subDir: params.repoCfg.subDir,
|
|
262
|
+
type: "static"
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (!rawPipeline) {
|
|
267
|
+
throw new Error(`Pipeline configuration missing (.ngit-deploy.json or runner repo config) for ${params.fullName}.`);
|
|
268
|
+
}
|
|
269
|
+
// Runner-level static targetDir / composeDir overrides take precedence when explicitly pinned
|
|
270
|
+
const mergedPipeline = {
|
|
271
|
+
...rawPipeline
|
|
272
|
+
};
|
|
273
|
+
if (params.repoCfg.targetDir && mergedPipeline.type === "static") {
|
|
274
|
+
mergedPipeline.targetDir = params.repoCfg.targetDir;
|
|
275
|
+
}
|
|
276
|
+
if (params.repoCfg.skipInstall !== undefined && mergedPipeline.type === "static") {
|
|
277
|
+
mergedPipeline.skipInstall = params.repoCfg.skipInstall;
|
|
278
|
+
}
|
|
279
|
+
if (params.repoCfg.skipBuild !== undefined && mergedPipeline.type === "static") {
|
|
280
|
+
mergedPipeline.skipBuild = params.repoCfg.skipBuild;
|
|
281
|
+
}
|
|
282
|
+
if (params.repoCfg.composeDir && mergedPipeline.type === "docker") {
|
|
283
|
+
mergedPipeline.composeDir = params.repoCfg.composeDir;
|
|
284
|
+
}
|
|
285
|
+
if (params.repoCfg.composeService && mergedPipeline.type === "docker") {
|
|
286
|
+
mergedPipeline.composeService = params.repoCfg.composeService;
|
|
287
|
+
}
|
|
288
|
+
const validation = validatePipelineConfig(mergedPipeline, {
|
|
289
|
+
allowedStaticRoot
|
|
290
|
+
});
|
|
291
|
+
if (!validation.valid || !validation.config) {
|
|
292
|
+
throw new Error(`Pipeline validation failed: ${validation.errors.join("; ")}`);
|
|
293
|
+
}
|
|
294
|
+
const pipeline = validation.config;
|
|
295
|
+
if (params.event === "push" && pipeline.onPush !== true) {
|
|
296
|
+
await reportUpdate("skipped", "Pipeline configured for releases only (onPush=false).", "skipped", {
|
|
297
|
+
finishedAt: new Date().toISOString()
|
|
298
|
+
});
|
|
299
|
+
const res = {
|
|
300
|
+
deploymentId: params.deploymentId,
|
|
301
|
+
repoFullName: params.fullName,
|
|
302
|
+
durationMs: Date.now() - startedAt,
|
|
303
|
+
logs: logLines.join("\n"),
|
|
304
|
+
status: "skipped",
|
|
305
|
+
ref: params.ref
|
|
306
|
+
};
|
|
307
|
+
options?.onDeploymentComplete?.(res);
|
|
308
|
+
return res;
|
|
309
|
+
}
|
|
310
|
+
const projectRoot = pipeline.subDir
|
|
311
|
+
? path.resolve(workDir, validateRelativeSubPath(pipeline.subDir, "subDir", true))
|
|
312
|
+
: workDir;
|
|
313
|
+
if (!isPathInside(workDir, projectRoot)) {
|
|
314
|
+
throw new Error("Path confinement violation: subDir escapes workDir.");
|
|
315
|
+
}
|
|
316
|
+
const safeTag = sanitizeDockerTag(params.releaseTag || params.ref);
|
|
317
|
+
if (pipeline.type === "docker") {
|
|
318
|
+
const registryHost = validateRegistryHost(config.registryHost || DEFAULT_REGISTRY_HOST);
|
|
319
|
+
const imageBase = `${registryHost}/${pipeline.image}`;
|
|
320
|
+
const taggedImage = `${imageBase}:${safeTag}`;
|
|
321
|
+
const latestImage = `${imageBase}:latest`;
|
|
322
|
+
const relDockerfile = validateRelativeSubPath(pipeline.dockerfile || "Dockerfile", "dockerfile", false);
|
|
323
|
+
const relContext = validateRelativeSubPath(pipeline.context || ".", "context", true);
|
|
324
|
+
const dockerfilePath = path.resolve(projectRoot, relDockerfile);
|
|
325
|
+
const contextPath = path.resolve(projectRoot, relContext);
|
|
326
|
+
if (!isPathInside(workDir, dockerfilePath) || !isPathInside(workDir, contextPath)) {
|
|
327
|
+
throw new Error("Path confinement violation: dockerfile or context escapes workDir.");
|
|
328
|
+
}
|
|
329
|
+
await reportUpdate("building", `Building Docker image ${taggedImage}...`, "building", {
|
|
330
|
+
pipelineType: "docker",
|
|
331
|
+
imageTag: taggedImage
|
|
332
|
+
});
|
|
333
|
+
const buildArgs = [
|
|
334
|
+
"build",
|
|
335
|
+
"-f",
|
|
336
|
+
dockerfilePath,
|
|
337
|
+
"-t",
|
|
338
|
+
taggedImage,
|
|
339
|
+
"-t",
|
|
340
|
+
latestImage
|
|
341
|
+
];
|
|
342
|
+
if (pipeline.target) {
|
|
343
|
+
buildArgs.push("--target", validateComposeIdentifier(pipeline.target, "target"));
|
|
344
|
+
}
|
|
345
|
+
buildArgs.push(contextPath);
|
|
346
|
+
const buildRes = await execSafe("docker", buildArgs, {
|
|
347
|
+
cwd: projectRoot
|
|
348
|
+
});
|
|
349
|
+
logLines.push(redactSensitiveText(buildRes.combined.split(/\r?\n/).slice(-20).join("\n")));
|
|
350
|
+
if (params.repoCfg.runnerToken) {
|
|
351
|
+
await reportUpdate("pushing", `Pushing ${taggedImage} & :latest to ${registryHost}...`, "pushing", {
|
|
352
|
+
pipelineType: "docker",
|
|
353
|
+
imageTag: taggedImage
|
|
354
|
+
});
|
|
355
|
+
await execSafe("docker", [
|
|
356
|
+
"login",
|
|
357
|
+
registryHost,
|
|
358
|
+
"-u",
|
|
359
|
+
config.registryUsername || "token",
|
|
360
|
+
"--password-stdin"
|
|
361
|
+
], {
|
|
362
|
+
stdinData: `${params.repoCfg.runnerToken}\n`
|
|
363
|
+
});
|
|
364
|
+
try {
|
|
365
|
+
await execSafe("docker", [
|
|
366
|
+
"push",
|
|
367
|
+
taggedImage
|
|
368
|
+
]);
|
|
369
|
+
await execSafe("docker", [
|
|
370
|
+
"push",
|
|
371
|
+
latestImage
|
|
372
|
+
]);
|
|
373
|
+
}
|
|
374
|
+
finally {
|
|
375
|
+
await execSafe("docker", [
|
|
376
|
+
"logout",
|
|
377
|
+
registryHost
|
|
378
|
+
]).catch(() => undefined);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (pipeline.composeService) {
|
|
382
|
+
const composeService = validateComposeIdentifier(pipeline.composeService, "composeService");
|
|
383
|
+
const composeDir = params.repoCfg.composeDir || pipeline.composeDir;
|
|
384
|
+
if (!composeDir) {
|
|
385
|
+
throw new Error("composeDir must be configured to run docker compose deployment.");
|
|
386
|
+
}
|
|
387
|
+
await reportUpdate("deploying", `Recreating compose service ${composeService}...`, "deploying", {
|
|
388
|
+
pipelineType: "docker",
|
|
389
|
+
imageTag: taggedImage
|
|
390
|
+
});
|
|
391
|
+
const composeArgs = [
|
|
392
|
+
"compose"
|
|
393
|
+
];
|
|
394
|
+
if (pipeline.composeProject) {
|
|
395
|
+
composeArgs.push("-p", validateComposeIdentifier(pipeline.composeProject, "composeProject"));
|
|
396
|
+
}
|
|
397
|
+
if (Array.isArray(pipeline.composeFiles)) {
|
|
398
|
+
for (const cf of pipeline.composeFiles) {
|
|
399
|
+
composeArgs.push("-f", validateRelativeSubPath(cf, "composeFiles", false));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
composeArgs.push("up", "-d", "--no-deps", "--force-recreate", composeService);
|
|
403
|
+
await execSafe("docker", composeArgs, {
|
|
404
|
+
cwd: composeDir
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
await reportUpdate("completed", `Docker deployment succeeded: ${taggedImage}`, "success", {
|
|
408
|
+
finishedAt: new Date().toISOString(),
|
|
409
|
+
pipelineType: "docker",
|
|
410
|
+
imageTag: taggedImage
|
|
411
|
+
});
|
|
412
|
+
const okRes = {
|
|
413
|
+
deploymentId: params.deploymentId,
|
|
414
|
+
repoFullName: params.fullName,
|
|
415
|
+
durationMs: Date.now() - startedAt,
|
|
416
|
+
logs: logLines.join("\n"),
|
|
417
|
+
status: "success",
|
|
418
|
+
ref: params.ref
|
|
419
|
+
};
|
|
420
|
+
options?.onDeploymentComplete?.(okRes);
|
|
421
|
+
return okRes;
|
|
422
|
+
}
|
|
423
|
+
// Static pipeline
|
|
424
|
+
const safeTargetDir = validateStaticTargetDir(pipeline.targetDir, allowedStaticRoot);
|
|
425
|
+
const relDistDir = validateRelativeSubPath(pipeline.distDir || "dist", "distDir", false);
|
|
426
|
+
const srcDistPath = path.resolve(projectRoot, relDistDir);
|
|
427
|
+
if (!isPathInside(workDir, srcDistPath)) {
|
|
428
|
+
throw new Error("Path confinement violation: distDir escapes workDir.");
|
|
429
|
+
}
|
|
430
|
+
const pkgJsonPath = path.join(projectRoot, "package.json");
|
|
431
|
+
const shouldBuild = pipeline.skipBuild !== true && fs.existsSync(pkgJsonPath);
|
|
432
|
+
if (shouldBuild) {
|
|
433
|
+
const buildScript = validateBuildScript(pipeline.buildScript || "web:build");
|
|
434
|
+
const pm = pipeline.packageManager || (fs.existsSync(path.join(projectRoot, "yarn.lock")) ? "yarn" : "npm");
|
|
435
|
+
await reportUpdate("building", `Building static bundle (${pm} ${buildScript})...`, "building", {
|
|
436
|
+
imageTag: `${params.fullName}@${safeTag}`,
|
|
437
|
+
pipelineType: "static"
|
|
438
|
+
});
|
|
439
|
+
if (pipeline.skipInstall !== true) {
|
|
440
|
+
const installArgs = pm === "yarn" ? [
|
|
441
|
+
"install",
|
|
442
|
+
"--network-timeout",
|
|
443
|
+
"120000"
|
|
444
|
+
] : [
|
|
445
|
+
"ci"
|
|
446
|
+
];
|
|
447
|
+
await execSafe(pm, installArgs, {
|
|
448
|
+
cwd: projectRoot
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
const buildArgs = pm === "yarn" ? [
|
|
452
|
+
buildScript
|
|
453
|
+
] : [
|
|
454
|
+
"run",
|
|
455
|
+
buildScript
|
|
456
|
+
];
|
|
457
|
+
const buildOut = await execSafe(pm, buildArgs, {
|
|
458
|
+
cwd: projectRoot
|
|
459
|
+
});
|
|
460
|
+
logLines.push(redactSensitiveText(buildOut.combined.split(/\r?\n/).slice(-20).join("\n")));
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
await reportUpdate("building", "Using prebuilt static assets from archive.", "building", {
|
|
464
|
+
imageTag: `${params.fullName}@${safeTag}`,
|
|
465
|
+
pipelineType: "static"
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (!fs.existsSync(srcDistPath)) {
|
|
469
|
+
throw new Error(`Static build output directory not found: ${relDistDir}`);
|
|
470
|
+
}
|
|
471
|
+
await reportUpdate("deploying", `Publishing static bundle atomically -> ${safeTargetDir}`, "deploying", {
|
|
472
|
+
imageTag: `${params.fullName}@${safeTag}`,
|
|
473
|
+
pipelineType: "static"
|
|
474
|
+
});
|
|
475
|
+
const strategy = await atomicSyncStaticDir(srcDistPath, safeTargetDir);
|
|
476
|
+
await reportUpdate("completed", `Static deployment succeeded (${strategy}) -> ${safeTargetDir}`, "success", {
|
|
477
|
+
finishedAt: new Date().toISOString(),
|
|
478
|
+
imageTag: `${params.fullName}@${safeTag}`,
|
|
479
|
+
pipelineType: "static"
|
|
480
|
+
});
|
|
481
|
+
const staticOk = {
|
|
482
|
+
deploymentId: params.deploymentId,
|
|
483
|
+
repoFullName: params.fullName,
|
|
484
|
+
durationMs: Date.now() - startedAt,
|
|
485
|
+
logs: logLines.join("\n"),
|
|
486
|
+
status: "success",
|
|
487
|
+
ref: params.ref
|
|
488
|
+
};
|
|
489
|
+
options?.onDeploymentComplete?.(staticOk);
|
|
490
|
+
return staticOk;
|
|
491
|
+
}
|
|
492
|
+
catch (err) {
|
|
493
|
+
const errMsg = err instanceof Error ? err.message : "deployment-failed";
|
|
494
|
+
const outputTail = err?.output;
|
|
495
|
+
const fullDetail = outputTail ? `${errMsg}\n${String(outputTail).slice(-3000)}` : errMsg;
|
|
496
|
+
await reportUpdate("error", `Deployment failed: ${fullDetail}`, "failed", {
|
|
497
|
+
finishedAt: new Date().toISOString()
|
|
498
|
+
});
|
|
499
|
+
const failRes = {
|
|
500
|
+
deploymentId: params.deploymentId,
|
|
501
|
+
repoFullName: params.fullName,
|
|
502
|
+
durationMs: Date.now() - startedAt,
|
|
503
|
+
logs: logLines.join("\n"),
|
|
504
|
+
error: errMsg,
|
|
505
|
+
status: "failed",
|
|
506
|
+
ref: params.ref
|
|
507
|
+
};
|
|
508
|
+
options?.onDeploymentComplete?.(failRes);
|
|
509
|
+
return failRes;
|
|
510
|
+
}
|
|
511
|
+
finally {
|
|
512
|
+
activeLocks.delete(params.fullName);
|
|
513
|
+
try {
|
|
514
|
+
fs.rmSync(workDir, {
|
|
515
|
+
recursive: true,
|
|
516
|
+
force: true
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
// Ignore temp cleanup error
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
const handleRequest = (req, res) => {
|
|
525
|
+
const reqPath = (req.url || "/").split("?")[0];
|
|
526
|
+
const clientIp = String(req.socket?.remoteAddress || "unknown");
|
|
527
|
+
if (isIpRateLimited(clientIp)) {
|
|
528
|
+
sendJson(res, 429, {
|
|
529
|
+
error: "rate-limit-exceeded",
|
|
530
|
+
ok: false
|
|
531
|
+
});
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (req.method === "GET" && reqPath === "/health") {
|
|
535
|
+
sendJson(res, 200, {
|
|
536
|
+
ok: true,
|
|
537
|
+
runner: config.runnerName,
|
|
538
|
+
version: NCLI_VERSION,
|
|
539
|
+
activeJobsCount: activeLocks.size,
|
|
540
|
+
queuedJobsCount: buildQueue.length
|
|
541
|
+
});
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (req.method !== "POST" || reqPath !== webhookPath) {
|
|
545
|
+
sendJson(res, 404, {
|
|
546
|
+
error: "not-found",
|
|
547
|
+
ok: false
|
|
548
|
+
});
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const chunks = [];
|
|
552
|
+
let totalBytes = 0;
|
|
553
|
+
let overflowed = false;
|
|
554
|
+
req.on("data", (chunk) => {
|
|
555
|
+
totalBytes += chunk.length;
|
|
556
|
+
if (totalBytes > MAX_WEBHOOK_BODY_BYTES) {
|
|
557
|
+
overflowed = true;
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
chunks.push(chunk);
|
|
561
|
+
});
|
|
562
|
+
req.on("end", () => {
|
|
563
|
+
if (overflowed) {
|
|
564
|
+
sendJson(res, 413, {
|
|
565
|
+
error: "payload-too-large",
|
|
566
|
+
ok: false
|
|
567
|
+
});
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const rawBody = Buffer.concat(chunks);
|
|
571
|
+
const sigHeader = String(req.headers["x-ngit-signature-256"] || "").trim();
|
|
572
|
+
const tsHeader = String(req.headers["x-ngit-timestamp"] || "").trim();
|
|
573
|
+
const deliveryHeader = String(req.headers["x-ngit-delivery"] || "").trim();
|
|
574
|
+
const eventHeader = String(req.headers["x-ngit-event"] || "").trim().toLowerCase();
|
|
575
|
+
let payload;
|
|
576
|
+
try {
|
|
577
|
+
payload = JSON.parse(rawBody.toString("utf8"));
|
|
578
|
+
}
|
|
579
|
+
catch {
|
|
580
|
+
sendJson(res, 400, {
|
|
581
|
+
error: "invalid-json",
|
|
582
|
+
ok: false
|
|
583
|
+
});
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const repoObj = (payload.repository && typeof payload.repository === "object")
|
|
587
|
+
? payload.repository
|
|
588
|
+
: null;
|
|
589
|
+
let parsedRepo = null;
|
|
590
|
+
if (repoObj) {
|
|
591
|
+
const candidate = typeof repoObj.fullName === "string" && repoObj.fullName.includes("/")
|
|
592
|
+
? repoObj.fullName
|
|
593
|
+
: (repoObj.owner && repoObj.name ? `${String(repoObj.owner)}/${String(repoObj.name)}` : "");
|
|
594
|
+
if (candidate) {
|
|
595
|
+
try {
|
|
596
|
+
parsedRepo = parseRepoSpec(candidate);
|
|
597
|
+
}
|
|
598
|
+
catch {
|
|
599
|
+
sendJson(res, 400, {
|
|
600
|
+
error: "invalid-repository-name",
|
|
601
|
+
ok: false
|
|
602
|
+
});
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
const matchedRepoCfg = parsedRepo ? allowlistedRepos.get(parsedRepo.fullName) : undefined;
|
|
608
|
+
let signatureValid = false;
|
|
609
|
+
if (matchedRepoCfg) {
|
|
610
|
+
signatureValid = verifyWebhookSignature(rawBody, sigHeader, matchedRepoCfg.webhookSecret);
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
const candidateSecrets = new Set();
|
|
614
|
+
if (config.webhookSecret) {
|
|
615
|
+
candidateSecrets.add(config.webhookSecret);
|
|
616
|
+
}
|
|
617
|
+
for (const cfg of allowlistedRepos.values()) {
|
|
618
|
+
candidateSecrets.add(cfg.webhookSecret);
|
|
619
|
+
}
|
|
620
|
+
for (const candidate of candidateSecrets) {
|
|
621
|
+
if (verifyWebhookSignature(rawBody, sigHeader, candidate)) {
|
|
622
|
+
signatureValid = true;
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (!signatureValid) {
|
|
628
|
+
sendJson(res, 401, {
|
|
629
|
+
error: "invalid-hmac-signature",
|
|
630
|
+
ok: false
|
|
631
|
+
});
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
// Replay protection — timestamp window check
|
|
635
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
636
|
+
const tsNum = Number(tsHeader);
|
|
637
|
+
if (!tsHeader || !Number.isFinite(tsNum) || Math.abs(nowSec - tsNum) > maxAgeSec) {
|
|
638
|
+
sendJson(res, 401, {
|
|
639
|
+
error: "stale-or-missing-timestamp",
|
|
640
|
+
ok: false
|
|
641
|
+
});
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
// Replay protection — delivery ID deduplication
|
|
645
|
+
if (!deliveryHeader) {
|
|
646
|
+
sendJson(res, 400, {
|
|
647
|
+
error: "missing-delivery-id",
|
|
648
|
+
ok: false
|
|
649
|
+
});
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const nowMs = Date.now();
|
|
653
|
+
pruneDeliveries(nowMs);
|
|
654
|
+
if (seenDeliveries.has(deliveryHeader)) {
|
|
655
|
+
sendJson(res, 409, {
|
|
656
|
+
error: "duplicate-delivery-id",
|
|
657
|
+
ok: false
|
|
658
|
+
});
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
seenDeliveries.set(deliveryHeader, nowMs + DEFAULT_DELIVERY_TTL_MS);
|
|
662
|
+
if (eventHeader === "ping") {
|
|
663
|
+
sendJson(res, 200, {
|
|
664
|
+
ok: true,
|
|
665
|
+
runner: config.runnerName,
|
|
666
|
+
version: NCLI_VERSION,
|
|
667
|
+
message: "ncli-runner webhook verified."
|
|
668
|
+
});
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (!parsedRepo) {
|
|
672
|
+
sendJson(res, 400, {
|
|
673
|
+
error: "missing-repository-metadata",
|
|
674
|
+
ok: false
|
|
675
|
+
});
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (!matchedRepoCfg) {
|
|
679
|
+
sendJson(res, 403, {
|
|
680
|
+
error: "repository-not-allowlisted",
|
|
681
|
+
repo: parsedRepo.fullName,
|
|
682
|
+
ok: false
|
|
683
|
+
});
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
const releaseObj = (payload.release && typeof payload.release === "object")
|
|
687
|
+
? payload.release
|
|
688
|
+
: null;
|
|
689
|
+
if (eventHeader === "release" && releaseObj?.isDraft === true) {
|
|
690
|
+
sendJson(res, 200, {
|
|
691
|
+
skipped: "draft-release",
|
|
692
|
+
ok: true
|
|
693
|
+
});
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const rawRef = String(releaseObj?.tagName ||
|
|
697
|
+
payload.tagName ||
|
|
698
|
+
payload.ref ||
|
|
699
|
+
repoObj?.defaultBranch ||
|
|
700
|
+
"main").replace(/^refs\/(?:heads|tags)\//, "");
|
|
701
|
+
let safeRef;
|
|
702
|
+
try {
|
|
703
|
+
safeRef = validateGitRef(rawRef);
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
sendJson(res, 400, {
|
|
707
|
+
error: "invalid-git-ref",
|
|
708
|
+
ok: false
|
|
709
|
+
});
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const triggeredBy = String(payload.publisher || payload.pusher || payload.sender || "webhook");
|
|
713
|
+
const deploymentId = `dep_${Date.now()}_${crypto.randomBytes(4).toString("hex")}`;
|
|
714
|
+
sendJson(res, 202, {
|
|
715
|
+
ok: true,
|
|
716
|
+
deploymentId,
|
|
717
|
+
status: "queued",
|
|
718
|
+
repo: parsedRepo.fullName,
|
|
719
|
+
ref: safeRef
|
|
720
|
+
});
|
|
721
|
+
const repoMeta = parsedRepo;
|
|
722
|
+
setImmediate(() => {
|
|
723
|
+
enqueueBuild(async () => {
|
|
724
|
+
await executeRepoDeployment({
|
|
725
|
+
repoCfg: matchedRepoCfg,
|
|
726
|
+
fullName: repoMeta.fullName,
|
|
727
|
+
owner: repoMeta.owner,
|
|
728
|
+
repo: repoMeta.repo,
|
|
729
|
+
releaseTag: safeRef,
|
|
730
|
+
event: eventHeader,
|
|
731
|
+
deploymentId,
|
|
732
|
+
ref: safeRef,
|
|
733
|
+
triggeredBy
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
const server = http.createServer(handleRequest);
|
|
740
|
+
server.headersTimeout = 10_000;
|
|
741
|
+
server.requestTimeout = 30_000;
|
|
742
|
+
server.keepAliveTimeout = 15_000;
|
|
743
|
+
const heartbeatMs = config.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
|
|
744
|
+
let heartbeatTimer = null;
|
|
745
|
+
const sendHeartbeats = async () => {
|
|
746
|
+
for (const [fullName, repoCfg] of allowlistedRepos.entries()) {
|
|
747
|
+
if (!repoCfg.runnerToken) {
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
const { owner, repo } = parseRepoSpec(fullName);
|
|
751
|
+
try {
|
|
752
|
+
await gitClient.sendRunnerHeartbeat(owner, repo, {
|
|
753
|
+
runnerName: config.runnerName,
|
|
754
|
+
runnerId: repoCfg.runnerId,
|
|
755
|
+
version: NCLI_VERSION,
|
|
756
|
+
activeJobs: Array.from(activeLocks),
|
|
757
|
+
timestamp: new Date().toISOString()
|
|
758
|
+
}, repoCfg.runnerToken);
|
|
759
|
+
}
|
|
760
|
+
catch {
|
|
761
|
+
// Non-fatal heartbeat error
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
await new Promise((resolve, reject) => {
|
|
766
|
+
server.once("error", reject);
|
|
767
|
+
server.listen(config.port, config.bindHost, () => {
|
|
768
|
+
server.removeListener("error", reject);
|
|
769
|
+
resolve();
|
|
770
|
+
});
|
|
771
|
+
});
|
|
772
|
+
const address = server.address();
|
|
773
|
+
const boundPort = typeof address === "object" && address ? address.port : config.port;
|
|
774
|
+
const boundHost = typeof address === "object" && address ? address.address : config.bindHost;
|
|
775
|
+
if (heartbeatMs > 0) {
|
|
776
|
+
void sendHeartbeats();
|
|
777
|
+
heartbeatTimer = setInterval(() => {
|
|
778
|
+
void sendHeartbeats();
|
|
779
|
+
}, heartbeatMs);
|
|
780
|
+
heartbeatTimer.unref();
|
|
781
|
+
}
|
|
782
|
+
log(`Listening on http://${boundHost}:${boundPort}${webhookPath} (${allowlistedRepos.size} allowlisted repo(s))`);
|
|
783
|
+
return {
|
|
784
|
+
url: `http://${boundHost}:${boundPort}`,
|
|
785
|
+
host: boundHost,
|
|
786
|
+
port: boundPort,
|
|
787
|
+
server,
|
|
788
|
+
close: () => new Promise((resolve, reject) => {
|
|
789
|
+
if (heartbeatTimer) {
|
|
790
|
+
clearInterval(heartbeatTimer);
|
|
791
|
+
heartbeatTimer = null;
|
|
792
|
+
}
|
|
793
|
+
server.close((err) => {
|
|
794
|
+
if (err) {
|
|
795
|
+
reject(err);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
resolve();
|
|
799
|
+
});
|
|
800
|
+
})
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
//# sourceMappingURL=server.js.map
|