import { chmod, mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { reproRun } from "../../helpers/repro-run.js"; const LOKI_VERSION = "v2.7.3"; // returns path to statically compiled binary export async function buildLoki(): Promise { const dir = "cache/loki"; await mkdir(dir, { recursive: true }); const versionFile = join(dir, "version"); const output = join(dir, "rootfs/loki"); try { if ((await readFile(versionFile, "utf-8")) === LOKI_VERSION) return output; } catch {} { const buildScript = join(dir, "build"); await writeFile( buildScript, `#!/bin/sh -e runprint() { echo "==> $@" "$@" } runprint apk add --quiet git go make libc-dev bash git config --global advice.detachedHead false # TODO: cachear clon de repo runprint git clone https://github.com/grafana/loki --branch '${LOKI_VERSION}' --depth 1 --single-branch cd loki runprint make -j1 GOMOD=readonly logcli loki mv cmd/loki/loki /loki ` ); await chmod(buildScript, 0o700); } await reproRun({ cwd: dir, command: "/src/build", cache: [ "/home/repro/.cache/go-build", "/home/repro/go", "/home/repro/.npm", ], }); await writeFile(versionFile, LOKI_VERSION); return output; }