@omer-x/buttler 0.1.4 → 0.2.1
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/bin/cli.js +54 -55
- package/drizzle/0000_illegal_mattie_franklin.sql +38 -0
- package/drizzle/meta/0000_snapshot.json +266 -0
- package/drizzle/meta/_journal.json +13 -0
- package/package.json +42 -13
- package/ui/.next/BUILD_ID +1 -0
- package/ui/.next/app-build-manifest.json +62 -0
- package/ui/.next/app-path-routes-manifest.json +1 -0
- package/ui/.next/build-manifest.json +32 -0
- package/ui/.next/package.json +1 -0
- package/ui/.next/prerender-manifest.js +1 -0
- package/ui/.next/prerender-manifest.json +1 -0
- package/ui/.next/react-loadable-manifest.json +1 -0
- package/ui/.next/required-server-files.json +1 -0
- package/ui/.next/routes-manifest.json +1 -0
- package/ui/.next/server/app/_not-found/page.js +1 -0
- package/ui/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/ui/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
- package/ui/.next/server/app/_not-found.html +1 -0
- package/ui/.next/server/app/_not-found.meta +6 -0
- package/ui/.next/server/app/_not-found.rsc +15 -0
- package/ui/.next/server/app/index.html +1 -0
- package/ui/.next/server/app/index.meta +5 -0
- package/ui/.next/server/app/index.rsc +11 -0
- package/ui/.next/server/app/page.js +1 -0
- package/ui/.next/server/app/page.js.nft.json +1 -0
- package/ui/.next/server/app/page_client-reference-manifest.js +1 -0
- package/ui/.next/server/app/services/[id]/edit/page.js +22 -0
- package/ui/.next/server/app/services/[id]/edit/page.js.nft.json +1 -0
- package/ui/.next/server/app/services/[id]/edit/page_client-reference-manifest.js +1 -0
- package/ui/.next/server/app/services/[id]/page.js +1 -0
- package/ui/.next/server/app/services/[id]/page.js.nft.json +1 -0
- package/ui/.next/server/app/services/[id]/page_client-reference-manifest.js +1 -0
- package/ui/.next/server/app/services/page.js +1 -0
- package/ui/.next/server/app/services/page.js.nft.json +1 -0
- package/ui/.next/server/app/services/page_client-reference-manifest.js +1 -0
- package/ui/.next/server/app/webhook/route.js +1 -0
- package/ui/.next/server/app/webhook/route.js.nft.json +1 -0
- package/ui/.next/server/app-paths-manifest.json +8 -0
- package/ui/.next/server/chunks/227.js +13 -0
- package/ui/.next/server/chunks/397.js +6 -0
- package/ui/.next/server/chunks/600.js +1 -0
- package/ui/.next/server/chunks/682.js +6 -0
- package/ui/.next/server/chunks/714.js +13 -0
- package/ui/.next/server/chunks/902.js +1 -0
- package/ui/.next/server/chunks/948.js +2 -0
- package/ui/.next/server/chunks/969.js +6 -0
- package/ui/.next/server/edge-instrumentation.js +2 -0
- package/ui/.next/server/font-manifest.json +1 -0
- package/ui/.next/server/instrumentation.js +1 -0
- package/ui/.next/server/middleware-build-manifest.js +1 -0
- package/ui/.next/server/middleware-manifest.json +6 -0
- package/ui/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/ui/.next/server/next-font-manifest.js +1 -0
- package/ui/.next/server/next-font-manifest.json +1 -0
- package/ui/.next/server/pages/404.html +1 -0
- package/ui/.next/server/pages/500.html +1 -0
- package/ui/.next/server/pages/_app.js +1 -0
- package/ui/.next/server/pages/_app.js.nft.json +1 -0
- package/ui/.next/server/pages/_document.js +1 -0
- package/ui/.next/server/pages/_document.js.nft.json +1 -0
- package/ui/.next/server/pages/_error.js +1 -0
- package/ui/.next/server/pages/_error.js.nft.json +1 -0
- package/ui/.next/server/pages-manifest.json +1 -0
- package/ui/.next/server/server-reference-manifest.js +1 -0
- package/ui/.next/server/server-reference-manifest.json +1 -0
- package/ui/.next/server/webpack-runtime.js +1 -0
- package/ui/.next/static/chunks/165-7e97ab67ee9a333f.js +22 -0
- package/ui/.next/static/chunks/23-bb15da2f9712f1ee.js +2 -0
- package/ui/.next/static/chunks/33-f121499ca3b0a7c3.js +1 -0
- package/ui/.next/static/chunks/746-40fe8411fec84077.js +5 -0
- package/ui/.next/static/chunks/847-b131e825002abb54.js +1 -0
- package/ui/.next/static/chunks/app/_not-found/page-dea2b9568f6e4d73.js +1 -0
- package/ui/.next/static/chunks/app/layout-0091bc250c5e8149.js +1 -0
- package/ui/.next/static/chunks/app/page-ffc06cd4473239c6.js +1 -0
- package/ui/.next/static/chunks/app/services/[id]/edit/page-4a8cc8f0f01ac693.js +1 -0
- package/ui/.next/static/chunks/app/services/[id]/page-3fd0d76f332f1180.js +1 -0
- package/ui/.next/static/chunks/app/services/page-b3edace587d96b1b.js +1 -0
- package/ui/.next/static/chunks/fd9d1056-f761286b613acfb1.js +1 -0
- package/ui/.next/static/chunks/framework-f66176bb897dc684.js +33 -0
- package/ui/.next/static/chunks/main-7adbfc7fbfa35b2c.js +1 -0
- package/ui/.next/static/chunks/main-app-550ee52788cc088b.js +1 -0
- package/ui/.next/static/chunks/pages/_app-6a626577ffa902a4.js +1 -0
- package/ui/.next/static/chunks/pages/_error-1be831200e60c5c0.js +1 -0
- package/ui/.next/static/chunks/polyfills-78c92fac7aa8fdd8.js +1 -0
- package/ui/.next/static/chunks/webpack-de18e3bccf615c71.js +1 -0
- package/ui/.next/static/css/294dd07620d1a861.css +1 -0
- package/ui/.next/static/css/475865983e61b131.css +1 -0
- package/ui/.next/static/css/ce0509a911764719.css +1 -0
- package/ui/.next/static/css/ddbbacd21aa0bff3.css +1 -0
- package/ui/.next/static/pho1GiSWDiZsBRRZzz27D/_buildManifest.js +1 -0
- package/ui/.next/static/pho1GiSWDiZsBRRZzz27D/_ssgManifest.js +1 -0
- package/ui/package.json +97 -0
- package/ui/server.js +44 -0
- package/bin/api.js +0 -36
- package/bin/database.js +0 -23
- package/bin/docker.js +0 -60
- package/bin/git.js +0 -13
- package/bin/github.js +0 -14
- package/bin/index.js +0 -37
- package/bin/object.js +0 -9
- package/bin/services.js +0 -67
package/bin/api.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import bodyParser from "body-parser";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import { cancelBuild, removeContainer, removeImage } from "./docker.js";
|
|
4
|
-
import { verifySignature } from "./github.js";
|
|
5
|
-
import { omit } from "./object.js";
|
|
6
|
-
import { getAllServices, prepareService } from "./services.js";
|
|
7
|
-
const app = express();
|
|
8
|
-
app.use(bodyParser.json());
|
|
9
|
-
app.post("/webhook", bodyParser.json({ verify: verifySignature }), (req, res) => {
|
|
10
|
-
handleWebhookEvent(req.body);
|
|
11
|
-
res.status(200).send("Webhook received");
|
|
12
|
-
});
|
|
13
|
-
async function handleWebhookEvent(event) {
|
|
14
|
-
const savedServices = await getAllServices();
|
|
15
|
-
for (const [serviceId, service] of Object.entries(savedServices)) {
|
|
16
|
-
if (service.repo !== event.repository.ssh_url)
|
|
17
|
-
continue;
|
|
18
|
-
console.log(serviceId + " needs update");
|
|
19
|
-
if (service.containerId) {
|
|
20
|
-
await removeContainer(service.containerId);
|
|
21
|
-
}
|
|
22
|
-
if (service.imageId) {
|
|
23
|
-
if (service.state === "building") {
|
|
24
|
-
await cancelBuild(serviceId, service.imageId);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
await removeImage(service.imageId);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
await prepareService(serviceId, {
|
|
31
|
-
...omit(service, "state", "containerId", "imageId"),
|
|
32
|
-
state: "cloned",
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export default app;
|
package/bin/database.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
export async function saveNode(collectionName, id, data) {
|
|
4
|
-
const dirPath = path.resolve(process.cwd(), "storage/db", collectionName);
|
|
5
|
-
await fs.mkdir(dirPath, { recursive: true });
|
|
6
|
-
const filePath = path.resolve(dirPath, `${id}.json`);
|
|
7
|
-
return fs.writeFile(filePath, JSON.stringify(data), "utf8");
|
|
8
|
-
}
|
|
9
|
-
export async function readNode(collectionName, id) {
|
|
10
|
-
const dirPath = path.resolve(process.cwd(), "storage/db", collectionName);
|
|
11
|
-
await fs.mkdir(dirPath, { recursive: true });
|
|
12
|
-
const filePath = path.resolve(dirPath, `${id}.json`);
|
|
13
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
14
|
-
return JSON.parse(content);
|
|
15
|
-
}
|
|
16
|
-
export async function findNodes(collectionName) {
|
|
17
|
-
const dirPath = path.resolve(process.cwd(), "storage/db", collectionName);
|
|
18
|
-
await fs.mkdir(dirPath, { recursive: true });
|
|
19
|
-
const items = await fs.readdir(dirPath, { withFileTypes: true });
|
|
20
|
-
const files = items.filter(i => i.isFile() && i.name.endsWith(".json"));
|
|
21
|
-
const records = await Promise.all(files.map(f => readNode(collectionName, f.name.slice(0, -5))));
|
|
22
|
-
return Object.fromEntries(files.map((file, index) => [file.name.slice(0, -5), records[index]]));
|
|
23
|
-
}
|
package/bin/docker.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import Docker from "dockerode";
|
|
3
|
-
import tar from "tar-fs";
|
|
4
|
-
import { deleteRepo } from "./services.js";
|
|
5
|
-
const docker = new Docker();
|
|
6
|
-
const streams = {};
|
|
7
|
-
export function buildImage(imageId, repoPath) {
|
|
8
|
-
const dockerfilePath = path.join(repoPath, "Dockerfile");
|
|
9
|
-
// Create a tar stream of the directory containing the Dockerfile
|
|
10
|
-
const tarStream = tar.pack(path.dirname(dockerfilePath));
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
docker.buildImage(tarStream, { t: `${imageId}:latest` }, (err, stream) => {
|
|
13
|
-
if (err)
|
|
14
|
-
return reject(err);
|
|
15
|
-
if (!stream)
|
|
16
|
-
return reject(new Error("no stream"));
|
|
17
|
-
// stream.pipe(process.stdout, { end: true });
|
|
18
|
-
stream.on("data", () => null);
|
|
19
|
-
stream.on("end", () => {
|
|
20
|
-
resolve(true);
|
|
21
|
-
});
|
|
22
|
-
stream.on("error", reason => {
|
|
23
|
-
if (reason === "UPDATE") {
|
|
24
|
-
resolve(false);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
reject(reason);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
streams[imageId] = stream;
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
export async function cancelBuild(serviceId, imageId) {
|
|
35
|
-
const stream = streams[imageId];
|
|
36
|
-
await stream.destroy("UPDATE");
|
|
37
|
-
delete streams[imageId];
|
|
38
|
-
await deleteRepo(serviceId);
|
|
39
|
-
}
|
|
40
|
-
export async function removeImage(imageId) {
|
|
41
|
-
const image = docker.getImage(imageId);
|
|
42
|
-
await image.remove();
|
|
43
|
-
}
|
|
44
|
-
export async function createContainer(service) {
|
|
45
|
-
const container = await docker.createContainer({
|
|
46
|
-
name: service.name,
|
|
47
|
-
Image: service.imageId,
|
|
48
|
-
Env: Object.entries(service.env).map(([key, value]) => `${key}=${value}`),
|
|
49
|
-
HostConfig: {
|
|
50
|
-
PortBindings: Object.fromEntries(Object.entries(service.ports).map(([internal, external]) => {
|
|
51
|
-
return [`${internal}/tcp`, [{ HostPort: external }]];
|
|
52
|
-
})),
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
await container.start();
|
|
56
|
-
return container.id;
|
|
57
|
-
}
|
|
58
|
-
export async function removeContainer(containerId) {
|
|
59
|
-
await docker.getContainer(containerId).remove({ force: true });
|
|
60
|
-
}
|
package/bin/git.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import simpleGit from "simple-git";
|
|
2
|
-
export async function cloneRepo(repoUrl, targetPath) {
|
|
3
|
-
const git = simpleGit({
|
|
4
|
-
baseDir: targetPath,
|
|
5
|
-
binary: "git",
|
|
6
|
-
maxConcurrentProcesses: 6,
|
|
7
|
-
});
|
|
8
|
-
await git.clone(repoUrl, targetPath, {
|
|
9
|
-
"--depth": "1",
|
|
10
|
-
"--single-branch": null,
|
|
11
|
-
"--branch": "main",
|
|
12
|
-
});
|
|
13
|
-
}
|
package/bin/github.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
|
-
const app = {
|
|
3
|
-
secret: "",
|
|
4
|
-
};
|
|
5
|
-
export function setSecret(secret) {
|
|
6
|
-
app.secret = secret;
|
|
7
|
-
}
|
|
8
|
-
export function verifySignature(req, res, buf, _encoding) {
|
|
9
|
-
const sha1 = crypto.createHmac("sha1", app.secret).update(buf).digest("hex");
|
|
10
|
-
const signature = `sha1=${sha1}`;
|
|
11
|
-
if (req.headers["x-hub-signature"] !== signature) {
|
|
12
|
-
throw new Error("Invalid signature");
|
|
13
|
-
}
|
|
14
|
-
}
|
package/bin/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import http from "node:http";
|
|
2
|
-
import readline from "node:readline";
|
|
3
|
-
import dotenv from "dotenv";
|
|
4
|
-
import api from "./api.js";
|
|
5
|
-
import { setSecret } from "./github.js";
|
|
6
|
-
import { getAllServices, getPredefinedServices, prepareService, saveService } from "./services.js";
|
|
7
|
-
const server = http.createServer(api);
|
|
8
|
-
dotenv.config({ path: [".env.local", ".env"] });
|
|
9
|
-
const rl = readline.createInterface({
|
|
10
|
-
input: process.stdin,
|
|
11
|
-
output: process.stdout,
|
|
12
|
-
});
|
|
13
|
-
function askQuestion(query) {
|
|
14
|
-
return new Promise(resolve => rl.question(query, resolve));
|
|
15
|
-
}
|
|
16
|
-
(async () => {
|
|
17
|
-
const port = parseInt(process.env.PORT || await askQuestion("Port: "));
|
|
18
|
-
const secret = process.env.WEBHOOK_SECRET || await askQuestion("Secret: ");
|
|
19
|
-
setSecret(secret);
|
|
20
|
-
console.clear();
|
|
21
|
-
server.listen(port, () => {
|
|
22
|
-
console.log(`Server running at http://127.0.0.1:${port}/`);
|
|
23
|
-
});
|
|
24
|
-
// init services
|
|
25
|
-
const savedServices = await getAllServices();
|
|
26
|
-
const predefinedServices = await getPredefinedServices();
|
|
27
|
-
const unsavedServices = predefinedServices
|
|
28
|
-
.filter(s => !Object.keys(savedServices).includes(s.name));
|
|
29
|
-
await Promise.all(unsavedServices.map(s => saveService(s.name, {
|
|
30
|
-
...s,
|
|
31
|
-
state: "idle",
|
|
32
|
-
})));
|
|
33
|
-
const services = await getAllServices();
|
|
34
|
-
for (const [serviceId, service] of Object.entries(services)) {
|
|
35
|
-
await prepareService(serviceId, service);
|
|
36
|
-
}
|
|
37
|
-
})();
|
package/bin/object.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/* export function pick<T extends object, K extends keyof T>(object: T, ...keys: K[]) {
|
|
2
|
-
return Object.fromEntries(Object.entries(object).filter(([key]) => keys.includes(key as K))) as Pick<T, K>;
|
|
3
|
-
} */
|
|
4
|
-
export function omit(object, ...keys) {
|
|
5
|
-
return Object.fromEntries(Object.entries(object).filter(([key]) => !keys.includes(key)));
|
|
6
|
-
}
|
|
7
|
-
/* export function pluck<T, K extends keyof T>(collection: T[], key: K) {
|
|
8
|
-
return collection.map(item => item[key]) as T[K][];
|
|
9
|
-
} */
|
package/bin/services.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { findNodes, readNode, saveNode } from "./database.js";
|
|
4
|
-
import { buildImage, createContainer } from "./docker.js";
|
|
5
|
-
import { cloneRepo } from "./git.js";
|
|
6
|
-
export function getAllServices() {
|
|
7
|
-
return findNodes("services");
|
|
8
|
-
}
|
|
9
|
-
function getService(id) {
|
|
10
|
-
return readNode("services", id);
|
|
11
|
-
}
|
|
12
|
-
export function saveService(id, data) {
|
|
13
|
-
return saveNode("services", id, data);
|
|
14
|
-
}
|
|
15
|
-
async function getRepoPath(serviceId) {
|
|
16
|
-
const repoPath = path.resolve(process.cwd(), "storage/repos", serviceId);
|
|
17
|
-
await fs.mkdir(repoPath, { recursive: true });
|
|
18
|
-
return repoPath;
|
|
19
|
-
}
|
|
20
|
-
export async function deleteRepo(serviceId) {
|
|
21
|
-
const repoPath = await getRepoPath(serviceId);
|
|
22
|
-
await fs.rm(repoPath, { recursive: true, force: true });
|
|
23
|
-
}
|
|
24
|
-
export async function prepareService(id, data) {
|
|
25
|
-
console.log("service", `"${id}"`, "is", data.state);
|
|
26
|
-
await saveService(id, data);
|
|
27
|
-
switch (data.state) {
|
|
28
|
-
case "idle": {
|
|
29
|
-
const repoPath = await getRepoPath(id);
|
|
30
|
-
console.log("service", `"${id}"`, "is", "cloning");
|
|
31
|
-
await cloneRepo(data.repo, repoPath);
|
|
32
|
-
await prepareService(id, { ...data, state: "cloned" });
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
case "cloned": {
|
|
36
|
-
const imageId = crypto.randomUUID();
|
|
37
|
-
await saveService(id, { ...data, state: "building", imageId });
|
|
38
|
-
console.log("service", `"${id}"`, "is", "building");
|
|
39
|
-
const repoPath = await getRepoPath(id);
|
|
40
|
-
const success = await buildImage(imageId, repoPath);
|
|
41
|
-
if (success) {
|
|
42
|
-
await deleteRepo(id);
|
|
43
|
-
await prepareService(id, { ...data, state: "built", imageId });
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
case "building": {
|
|
48
|
-
await prepareService(id, { ...data, state: "cloned" });
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case "built": {
|
|
52
|
-
if (!data.imageId)
|
|
53
|
-
throw new Error("image ID of the service is not defined");
|
|
54
|
-
const containerId = await createContainer(data);
|
|
55
|
-
await prepareService(id, { ...data, state: "ready", containerId });
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case "ready": {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export async function getPredefinedServices() {
|
|
64
|
-
const filePath = path.resolve(process.cwd(), "services.json");
|
|
65
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
66
|
-
return JSON.parse(content);
|
|
67
|
-
}
|