2023-01-16 15:14:20 +00:00
|
|
|
import { mkdir, mkdtemp } from "node:fs/promises";
|
2023-01-16 12:42:10 +00:00
|
|
|
import { tmpdir } from "node:os";
|
|
|
|
import path from "node:path";
|
2023-02-08 14:46:33 +00:00
|
|
|
import { cwd, exit } from "node:process";
|
2023-01-16 15:14:20 +00:00
|
|
|
import { Alpine } from "./alpine.js";
|
2023-02-08 14:46:33 +00:00
|
|
|
import { setupForgejo } from "./forgejo/index.js";
|
|
|
|
import { generateForgejoSecretsFile } from "./forgejo/secrets.js";
|
2023-02-02 22:02:38 +00:00
|
|
|
import { execFile } from "./helpers/better-api.js";
|
|
|
|
import { sudoChownToRunningUser } from "./helpers/sudo.js";
|
2023-01-23 15:30:21 +00:00
|
|
|
import { setupKernel } from "./kernel.js";
|
2023-02-02 21:25:11 +00:00
|
|
|
import { runQemu } from "./qemu.js";
|
2023-01-16 15:14:20 +00:00
|
|
|
import { Runit } from "./runit/index.js";
|
2023-01-16 12:42:10 +00:00
|
|
|
|
2023-02-08 14:46:33 +00:00
|
|
|
if (process.argv[2] === "generate-secrets") {
|
|
|
|
await generateForgejoSecretsFile();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2023-01-16 12:42:10 +00:00
|
|
|
{
|
2023-01-23 15:30:21 +00:00
|
|
|
console.time("Building");
|
|
|
|
|
2023-02-02 21:25:11 +00:00
|
|
|
const artifactsDir = path.join(cwd(), "artifacts/");
|
|
|
|
const kernelDir = path.join(artifactsDir, "kernel");
|
|
|
|
await mkdir(artifactsDir, { recursive: true });
|
|
|
|
await mkdir(kernelDir, { recursive: true });
|
|
|
|
|
2023-01-16 12:42:10 +00:00
|
|
|
const rootfsDir = await mkdtemp(path.join(tmpdir(), "define-alpine-"));
|
|
|
|
console.debug(rootfsDir);
|
2023-01-16 15:14:20 +00:00
|
|
|
const alpine = await Alpine.makeWorld({ dir: rootfsDir });
|
2023-02-08 14:46:33 +00:00
|
|
|
|
|
|
|
await alpine.addPackages(["helix", "iproute2-ss", "socat"]);
|
2023-01-16 15:14:20 +00:00
|
|
|
const runit = await Runit.setup(alpine);
|
2023-02-08 14:46:33 +00:00
|
|
|
await setupForgejo(alpine, runit);
|
2023-02-02 21:25:11 +00:00
|
|
|
const kernel = await setupKernel(alpine, kernelDir);
|
|
|
|
|
|
|
|
const squashfs = path.join(artifactsDir, "image.squashfs");
|
|
|
|
await execFile("sudo", [
|
|
|
|
"mksquashfs",
|
|
|
|
alpine.dir,
|
|
|
|
squashfs,
|
|
|
|
"-comp",
|
|
|
|
"zstd",
|
|
|
|
"-Xcompression-level",
|
|
|
|
"3",
|
|
|
|
"-noappend",
|
|
|
|
"-quiet",
|
|
|
|
]);
|
|
|
|
await sudoChownToRunningUser(squashfs);
|
2023-01-23 15:30:21 +00:00
|
|
|
|
|
|
|
console.timeEnd("Building");
|
|
|
|
|
2023-02-02 21:28:57 +00:00
|
|
|
runQemu(squashfs, kernel, { graphic: true });
|
2023-01-23 15:30:21 +00:00
|
|
|
|
2023-01-16 15:14:20 +00:00
|
|
|
// await makeService({
|
|
|
|
// parentDir: rootfsDir,
|
|
|
|
// name: "grafana",
|
|
|
|
// packages: ["grafana"],
|
|
|
|
// setup: async (dir) => {},
|
|
|
|
// initScript: async (dir) => {},
|
|
|
|
// });
|
2023-01-23 15:30:21 +00:00
|
|
|
// try {
|
|
|
|
// await spawn("sudo", ["chroot", rootfsDir], { stdio: "inherit" });
|
|
|
|
// } catch {}
|
2023-01-16 12:42:10 +00:00
|
|
|
}
|
|
|
|
|
2023-01-16 15:14:20 +00:00
|
|
|
// interface Service {}
|
|
|
|
// async function makeService({
|
|
|
|
// parentDir,
|
|
|
|
// name,
|
|
|
|
// packages,
|
|
|
|
// setup,
|
|
|
|
// initScript: _initScript,
|
|
|
|
// }: {
|
|
|
|
// parentDir: string;
|
|
|
|
// name: string;
|
|
|
|
// packages?: string[];
|
|
|
|
// setup: (dir: string) => Promise<void>;
|
|
|
|
// initScript: (dir: string) => Promise<string>;
|
|
|
|
// }) {
|
|
|
|
// const rootsDir = path.join(parentDir, "/nulo/roots/");
|
|
|
|
// await mkdir(rootsDir, { recursive: true });
|
2023-01-16 12:42:10 +00:00
|
|
|
|
2023-01-16 15:14:20 +00:00
|
|
|
// const alpine = await Alpine.makeWorld({
|
|
|
|
// dir: path.join(rootsDir, name),
|
|
|
|
// packages,
|
|
|
|
// });
|
2023-01-16 12:42:10 +00:00
|
|
|
|
2023-01-16 15:14:20 +00:00
|
|
|
// await setup(alpine.dir);
|
|
|
|
|
|
|
|
// // const initScript = await _initScript(rootfsDir);
|
|
|
|
// }
|