reutilizar código de buildear cacheado reprorun
This commit is contained in:
parent
cb813b19b1
commit
bcd0280e69
3 changed files with 65 additions and 63 deletions
|
@ -1,3 +1,5 @@
|
|||
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { Writable } from "node:stream";
|
||||
import { execFile } from "./better-api.js";
|
||||
|
||||
|
@ -21,3 +23,29 @@ export async function reproRun(opts: {
|
|||
run.child.stderr?.pipe(process.stderr);
|
||||
await run;
|
||||
}
|
||||
|
||||
export async function buildRepro<T>(
|
||||
cacheName: string,
|
||||
cacheKey: string,
|
||||
buildScript: string,
|
||||
run: (cwd: string) => Promise<void>,
|
||||
getArtifacts: (cwd: string) => T
|
||||
): Promise<T> {
|
||||
const dir = join("cache", cacheName);
|
||||
await mkdir(dir, { recursive: true });
|
||||
const cacheKeyFile = join(dir, "version");
|
||||
const output = getArtifacts(dir);
|
||||
try {
|
||||
if ((await readFile(cacheKeyFile, "utf-8")) === cacheKey) return output;
|
||||
} catch {}
|
||||
|
||||
{
|
||||
const buildScriptPath = join(dir, "build");
|
||||
await writeFile(buildScriptPath, buildScript);
|
||||
await chmod(buildScriptPath, 0o700);
|
||||
}
|
||||
await run(dir);
|
||||
await writeFile(cacheKeyFile, cacheKey);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,14 @@
|
|||
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { reproRun } from "../../helpers/repro-run.js";
|
||||
import { buildRepro, reproRun } from "../../helpers/repro-run.js";
|
||||
|
||||
const FORGEJO_VERSION = "v1.18.3-0";
|
||||
|
||||
// returns path to statically compiled binary
|
||||
export async function buildForgejo(): Promise<string> {
|
||||
const dir = "cache/forgejo";
|
||||
await mkdir(dir, { recursive: true });
|
||||
const versionFile = join(dir, "version");
|
||||
const output = join(dir, "rootfs/forgejo");
|
||||
try {
|
||||
if ((await readFile(versionFile, "utf-8")) === FORGEJO_VERSION)
|
||||
return output;
|
||||
} catch {}
|
||||
|
||||
{
|
||||
const buildScript = join(dir, "build");
|
||||
await writeFile(
|
||||
buildScript,
|
||||
return await buildRepro(
|
||||
"forgejo",
|
||||
FORGEJO_VERSION,
|
||||
`#!/bin/sh -e
|
||||
runprint() {
|
||||
echo "==> $@"
|
||||
|
@ -33,11 +23,9 @@ cd forgejo
|
|||
|
||||
runprint env GOOS=linux GOARCH=amd64 LDFLAGS="-linkmode external -extldflags '-static' $LDFLAGS" TAGS="bindata sqlite sqlite_unlock_notify" make build
|
||||
mv gitea /forgejo
|
||||
`
|
||||
);
|
||||
await chmod(buildScript, 0o700);
|
||||
}
|
||||
await reproRun({
|
||||
`,
|
||||
(dir) =>
|
||||
reproRun({
|
||||
cwd: dir,
|
||||
command: "/src/build",
|
||||
cache: [
|
||||
|
@ -45,8 +33,7 @@ mv gitea /forgejo
|
|||
"/home/repro/go",
|
||||
"/home/repro/.npm",
|
||||
],
|
||||
});
|
||||
await writeFile(versionFile, FORGEJO_VERSION);
|
||||
|
||||
return output;
|
||||
}),
|
||||
(dir) => join(dir, "rootfs/forgejo")
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,13 @@
|
|||
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { reproRun } from "../../helpers/repro-run.js";
|
||||
import { buildRepro, reproRun } from "../../helpers/repro-run.js";
|
||||
|
||||
const LOKI_VERSION = "v2.7.3";
|
||||
|
||||
// returns path to statically compiled binary
|
||||
export async function buildLoki(): Promise<string> {
|
||||
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,
|
||||
export function buildLoki(): Promise<string> {
|
||||
return buildRepro(
|
||||
"loki",
|
||||
LOKI_VERSION,
|
||||
`#!/bin/sh -e
|
||||
runprint() {
|
||||
echo "==> $@"
|
||||
|
@ -33,11 +23,9 @@ cd loki
|
|||
|
||||
runprint make -j1 GOMOD=readonly logcli loki
|
||||
mv cmd/loki/loki /loki
|
||||
`
|
||||
);
|
||||
await chmod(buildScript, 0o700);
|
||||
}
|
||||
await reproRun({
|
||||
`,
|
||||
(dir) =>
|
||||
reproRun({
|
||||
cwd: dir,
|
||||
command: "/src/build",
|
||||
cache: [
|
||||
|
@ -45,8 +33,7 @@ mv cmd/loki/loki /loki
|
|||
"/home/repro/go",
|
||||
"/home/repro/.npm",
|
||||
],
|
||||
});
|
||||
await writeFile(versionFile, LOKI_VERSION);
|
||||
|
||||
return output;
|
||||
}),
|
||||
(dir) => join(dir, "rootfs/loki")
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue