Skip to content

Commit 93d99c2

Browse files
NathanFlurryMasterPtato
authored andcommitted
chore: a mess of merging everything together
1 parent df03c38 commit 93d99c2

File tree

274 files changed

+14320
-4105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+14320
-4105
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/packages/ci-manager/src/build-store.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { BuildInfo, BuildEvent, Status } from "./types";
21
import { randomUUID } from "crypto";
2+
import { dirname, join } from "path";
33
import { mkdir, rm } from "fs/promises";
4-
import { join, dirname } from "path";
54
import { createNanoEvents } from "nanoevents";
5+
import type { BuildEvent, BuildInfo, Status } from "./types";
66

77
export class BuildStore {
88
private builds = new Map<string, BuildInfo>();
@@ -12,7 +12,7 @@ export class BuildStore {
1212
"status-change": (buildId: string, status: Status) => void;
1313
}>();
1414

15-
constructor(tempDir: string = "/tmp/ci-builds") {
15+
constructor(tempDir = "/tmp/ci-builds") {
1616
this.tempDir = tempDir;
1717
}
1818

@@ -25,7 +25,7 @@ export class BuildStore {
2525
dockerfilePath: string,
2626
environmentId: string,
2727
buildArgs: Record<string, string>,
28-
buildTarget: string | undefined
28+
buildTarget: string | undefined,
2929
): string {
3030
const id = randomUUID();
3131
const contextPath = join(this.tempDir, id, "context.tar.gz");
@@ -94,7 +94,7 @@ export class BuildStore {
9494
}
9595
}
9696

97-
getContextPath(id: string): string | undefined{
97+
getContextPath(id: string): string | undefined {
9898
return this.builds.get(id)?.contextPath;
9999
}
100100

cloud/packages/ci-manager/src/common.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ interface KanikoArguments {
1212
}
1313

1414
// SAFETY: buildArgs keys never have equal signs or spaces
15-
function convertBuildArgsToArgs(
16-
buildArgs: Record<string, string>,
17-
): string[] {
15+
function convertBuildArgsToArgs(buildArgs: Record<string, string>): string[] {
1816
return Object.entries(buildArgs).flatMap(([key, value]) => [
1917
`--build-arg`,
2018
`${key}=${value}`,
@@ -34,11 +32,11 @@ export function serializeKanikoArguments(args: KanikoArguments): string {
3432
"--no-push",
3533
"--single-snapshot",
3634
"--verbosity=info",
37-
].map(arg => {
35+
].map((arg) => {
3836
// Args should never contain UNIT_SEP_CHAR, but we can
3937
// escape it if they do.
40-
return arg.replaceAll(UNIT_SEP_CHAR, "\\" + UNIT_SEP_CHAR)
38+
return arg.replaceAll(UNIT_SEP_CHAR, "\\" + UNIT_SEP_CHAR);
4139
});
4240

4341
return preparedArgs.join(UNIT_SEP_CHAR);
44-
}
42+
}

cloud/packages/ci-manager/src/executors/docker.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawn } from "node:child_process";
2-
import { BuildStore } from "../build-store";
3-
import { serializeKanikoArguments, UNIT_SEP_CHAR } from "../common";
2+
import type { BuildStore } from "../build-store";
3+
import { serializeKanikoArguments } from "../common";
44

55
export async function runDockerBuild(
66
buildStore: BuildStore,
@@ -20,16 +20,14 @@ export async function runDockerBuild(
2020
"--rm",
2121
"--network=host",
2222
"-e",
23-
`KANIKO_ARGS=${
24-
serializeKanikoArguments({
25-
contextUrl,
26-
outputUrl,
27-
destination: `${buildId}:latest`,
28-
dockerfilePath: build.dockerfilePath,
29-
buildArgs: build.buildArgs,
30-
buildTarget: build.buildTarget,
31-
})
32-
}`,
23+
`KANIKO_ARGS=${serializeKanikoArguments({
24+
contextUrl,
25+
outputUrl,
26+
destination: `${buildId}:latest`,
27+
dockerfilePath: build.dockerfilePath,
28+
buildArgs: build.buildArgs,
29+
buildTarget: build.buildTarget,
30+
})}`,
3331
"ci-runner",
3432
];
3533

@@ -40,12 +38,12 @@ export async function runDockerBuild(
4038

4139
buildStore.updateStatus(buildId, {
4240
type: "running",
43-
data: { docker: {} }
41+
data: { docker: {} },
4442
});
4543

4644
return new Promise<void>((resolve, reject) => {
4745
const dockerProcess = spawn("docker", kanikoArgs, {
48-
stdio: ["pipe", "pipe", "pipe"]
46+
stdio: ["pipe", "pipe", "pipe"],
4947
});
5048

5149
buildStore.setContainerProcess(buildId, dockerProcess);
@@ -71,7 +69,10 @@ export async function runDockerBuild(
7169
});
7270

7371
dockerProcess.on("close", (code) => {
74-
buildStore.addLog(buildId, `Docker process closed with exit code: ${code}`);
72+
buildStore.addLog(
73+
buildId,
74+
`Docker process closed with exit code: ${code}`,
75+
);
7576
buildStore.updateStatus(buildId, { type: "finishing", data: {} });
7677

7778
if (code === 0) {
@@ -90,7 +91,10 @@ export async function runDockerBuild(
9091
});
9192

9293
dockerProcess.on("error", (error) => {
93-
buildStore.addLog(buildId, `Docker process error: ${error.message}`);
94+
buildStore.addLog(
95+
buildId,
96+
`Docker process error: ${error.message}`,
97+
);
9498
buildStore.updateStatus(buildId, {
9599
type: "failure",
96100
data: { reason: `Failed to start kaniko: ${error.message}` },
@@ -99,5 +103,3 @@ export async function runDockerBuild(
99103
});
100104
});
101105
}
102-
103-

cloud/packages/ci-manager/src/executors/rivet.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RivetClient } from "@rivet-gg/api";
2-
import { BuildStore } from "../build-store";
2+
import type { BuildStore } from "../build-store";
33
import { serializeKanikoArguments } from "../common";
44

55
export async function runRivetBuild(
@@ -57,7 +57,7 @@ export async function runRivetBuild(
5757
dockerfilePath: build.dockerfilePath,
5858
buildArgs: build.buildArgs,
5959
buildTarget: build.buildTarget,
60-
})
60+
}),
6161
},
6262
},
6363
network: {
@@ -81,8 +81,8 @@ export async function runRivetBuild(
8181
buildStore.updateStatus(buildId, {
8282
type: "running",
8383
data: {
84-
rivet: { actorId }
85-
}
84+
rivet: { actorId },
85+
},
8686
});
8787

8888
await pollActorStatus(

cloud/packages/ci-manager/src/kaniko-runner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { BuildStore } from "./build-store";
2-
import { mkdir } from "node:fs/promises";
31
import { existsSync } from "node:fs";
2+
import { mkdir } from "node:fs/promises";
43
import { dirname } from "node:path";
4+
import type { BuildStore } from "./build-store";
55
import { runDockerBuild } from "./executors/docker";
66
import { runRivetBuild } from "./executors/rivet";
77

@@ -20,8 +20,8 @@ export async function runKanikoBuild(
2020
buildStore.updateStatus(buildId, {
2121
type: "running",
2222
data: {
23-
noRunner: {}
24-
}
23+
noRunner: {},
24+
},
2525
});
2626

2727
const executionMode = process.env.KANIKO_EXECUTION_MODE || "docker";

cloud/packages/ci-manager/src/oci-converter.ts

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { execSync } from "child_process";
2-
import { mkdir, rm, writeFile, readFile, readdir, stat } from "fs/promises";
3-
import { join, dirname } from "path";
4-
import { createReadStream, createWriteStream } from "fs";
5-
import { pipeline } from "stream/promises";
2+
import { join } from "path";
3+
import { mkdir, readFile, rm, writeFile } from "fs/promises";
64
import * as tar from "tar";
75

86
export interface OCIConversionResult {
@@ -12,14 +10,14 @@ export interface OCIConversionResult {
1210

1311
export async function convertDockerTarToOCIBundle(
1412
dockerTarPath: string,
15-
tempDir: string = "/tmp/oci-conversion"
13+
tempDir = "/tmp/oci-conversion",
1614
): Promise<OCIConversionResult> {
1715
const conversionId = Math.random().toString(36).substring(7);
1816
const workDir = join(tempDir, conversionId);
19-
17+
2018
try {
2119
await mkdir(workDir, { recursive: true });
22-
20+
2321
const dockerImagePath = join(workDir, "docker-image.tar");
2422
const ociImagePath = join(workDir, "oci-image");
2523
const ociBundlePath = join(workDir, "oci-bundle");
@@ -30,54 +28,71 @@ export async function convertDockerTarToOCIBundle(
3028
await writeFile(dockerImagePath, dockerTarData);
3129

3230
// Convert Docker image to OCI image using skopeo
33-
console.log(`Converting Docker image to OCI image: ${dockerImagePath} -> ${ociImagePath}`);
34-
execSync(`skopeo copy docker-archive:${dockerImagePath} oci:${ociImagePath}:default`, {
35-
stdio: "pipe"
36-
});
31+
console.log(
32+
`Converting Docker image to OCI image: ${dockerImagePath} -> ${ociImagePath}`,
33+
);
34+
execSync(
35+
`skopeo copy docker-archive:${dockerImagePath} oci:${ociImagePath}:default`,
36+
{
37+
stdio: "pipe",
38+
},
39+
);
3740

3841
// Convert OCI image to OCI bundle using umoci
39-
console.log(`Converting OCI image to OCI bundle: ${ociImagePath} -> ${ociBundlePath}`);
40-
execSync(`umoci unpack --rootless --image ${ociImagePath}:default ${ociBundlePath}`, {
41-
stdio: "pipe"
42-
});
42+
console.log(
43+
`Converting OCI image to OCI bundle: ${ociImagePath} -> ${ociBundlePath}`,
44+
);
45+
execSync(
46+
`umoci unpack --rootless --image ${ociImagePath}:default ${ociBundlePath}`,
47+
{
48+
stdio: "pipe",
49+
},
50+
);
4351

4452
// Create tar from OCI bundle
45-
console.log(`Creating tar from OCI bundle: ${ociBundlePath} -> ${bundleTarPath}`);
53+
console.log(
54+
`Creating tar from OCI bundle: ${ociBundlePath} -> ${bundleTarPath}`,
55+
);
4656
await tar.create(
4757
{
4858
file: bundleTarPath,
4959
cwd: ociBundlePath,
5060
},
51-
["."]
61+
["."],
5262
);
5363

5464
// Clean up intermediate files
5565
await Promise.all([
5666
rm(dockerImagePath, { force: true }),
5767
rm(ociImagePath, { recursive: true, force: true }),
58-
rm(ociBundlePath, { recursive: true, force: true })
68+
rm(ociBundlePath, { recursive: true, force: true }),
5969
]);
6070

6171
const cleanup = async () => {
6272
try {
6373
await rm(workDir, { recursive: true, force: true });
6474
} catch (error) {
65-
console.warn(`Failed to cleanup OCI conversion directory ${workDir}:`, error);
75+
console.warn(
76+
`Failed to cleanup OCI conversion directory ${workDir}:`,
77+
error,
78+
);
6679
}
6780
};
6881

6982
return {
7083
bundleTarPath,
71-
cleanup
84+
cleanup,
7285
};
7386
} catch (error) {
7487
// Cleanup on error
7588
try {
7689
await rm(workDir, { recursive: true, force: true });
7790
} catch (cleanupError) {
78-
console.warn(`Failed to cleanup after error in ${workDir}:`, cleanupError);
91+
console.warn(
92+
`Failed to cleanup after error in ${workDir}:`,
93+
cleanupError,
94+
);
7995
}
8096
throw new Error(`OCI conversion failed: ${error}`);
8197
}
8298
}
83-

cloud/packages/ci-manager/src/rivet-uploader.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
import { statSync } from "fs";
12
import { RivetClient } from "@rivet-gg/api";
2-
import { warn } from "console";
3-
import { createReadStream, statSync } from "fs";
4-
import { readFile } from "fs/promises";
53

64
export interface RivetUploadConfig {
75
token: string;
@@ -113,7 +111,7 @@ export async function uploadOCIBundleToRivet(
113111
async function uploadChunkWithRetry(
114112
url: string,
115113
buffer: Buffer,
116-
maxRetries: number = 3,
114+
maxRetries = 3,
117115
): Promise<void> {
118116
let lastError: Error | null = null;
119117

@@ -232,4 +230,3 @@ async function patchBuildTags(
232230
// Don't throw here to avoid failing the entire upload process
233231
}
234232
}
235-

0 commit comments

Comments
 (0)