Add a load of fallbacks and rework the docker bits
All checks were successful
Build and deploy / deploy (push) Successful in 1m58s

This commit is contained in:
2025-04-27 02:22:08 +01:00
parent 0ffaaf919d
commit 139f96f938
12 changed files with 153 additions and 140 deletions

View File

@@ -5,9 +5,17 @@
"clientKind": "git",
"useIgnoreFile": true
},
"files": { "ignoreUnknown": false, "ignore": [] },
"formatter": { "enabled": true },
"organizeImports": { "enabled": true },
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"lineWidth": 200
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {

View File

@@ -24,9 +24,7 @@ const handler = (req: NextRequest) =>
onError:
env.NODE_ENV === "development"
? ({ path, error }) => {
console.error(
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`,
);
console.error(`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`);
}
: undefined,
});

View File

@@ -16,9 +16,7 @@ const geist = Geist({
variable: "--font-geist-sans",
});
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en" className={`${geist.variable}`}>
<body>

View File

@@ -16,45 +16,34 @@ export default async function Home() {
<tr>
<th>Name</th>
<th>Image</th>
<th>Version</th>
<th>Tag</th>
<th>Short Hash</th>
<th>Version</th>
<th>Tag</th>
<th>Short Hash</th>
</tr>
</thead>
<tbody>
{list
.sort((ca, cb) => {
if (ca.Names[0] && cb.Names[0]) {
if (ca.Names[0] < cb.Names[0]) {
if (ca.containerName && cb.containerName) {
if (ca.containerName < cb.containerName) {
return -1;
}
if (ca.Names[0] > cb.Names[0]) {
if (ca.containerName > cb.containerName) {
return 1;
}
}
return 0;
})
.map((containerInfo) => {
const outdated =
containerInfo.current.version !==
containerInfo.latest.version ||
containerInfo.current.hash !==
containerInfo.latest.hash;
const outdated = containerInfo.current.hash !== containerInfo.latest.hash;
return (
<tr
key={containerInfo.Image.split(":")[0]}
className={`${outdated ? "bg-base-200" : null}`}
>
<td
className={`border-l-8 ${outdated ? "border-l-error/80" : "border-l-info/80"}`}
>
{containerInfo.Names[0]?.substring(1)}
</td>
<td>{containerInfo.Image.split(":")[0]}</td>
<td>{containerInfo.current.version}</td>
<tr key={containerInfo.containerName} className={`${outdated ? "bg-base-200" : null}`}>
<td className={`border-l-8 ${outdated ? "border-l-error/80" : "border-l-info/80"}`}>{containerInfo.containerName}</td>
<td>{containerInfo.imageName}</td>
<td>{containerInfo.current.tag}</td>
<td>{containerInfo.current.hash}</td>
<td>{containerInfo.latest.version}</td>
<td>{containerInfo.latest.tag}</td>
<td>{containerInfo.latest.hash}</td>
</tr>
);

View File

@@ -18,38 +18,46 @@ export const dockerRouter = createTRPCRouter({
// curl -fsSL -v -H "Accept: application/json" "hub.docker.com/v2/repositories/linuxserver/code-server/tags?n=25&ordering=last_updated"
return Promise.all(
const dockerInfo = await Promise.all(
containers.map(async (container) => {
const version = (
await docker.getImage(container.Image).inspect()
).RepoTags[0]?.split(":")[1];
const latest = {
version: version,
hash: "N/A",
const imageInspect = await docker.getImage(container.Image).inspect();
const imageDigest = imageInspect.RepoDigests[0];
const containerInspect = docker.getContainer(container.Id);
let imageTag = imageInspect.RepoTags[0]?.split(":")[1];
let imageName = imageDigest?.split("@")?.[0];
imageName ??= container.Image.split(":")[0] ?? undefined;
const imageHash = imageDigest?.split("@")?.[1]?.split(":")?.[1];
imageTag ??= (await containerInspect.inspect()).Config.Image.split(":")[1] ?? undefined;
const current = {
hash: imageHash?.substring(0, 12),
tag: imageTag,
};
if (version && isSemver(version)) {
latest.version = await getLatestSemverTag(container.Image);
latest.hash = await getLatestHash(
`${container.Image.split(":")[0]}:${latest.version}`,
);
} else {
latest.hash = await getLatestHash(container.Image);
let latest: {
hash?: string;
tag?: string;
} = {
hash: "",
tag: "",
};
if (imageName) {
latest = await getLatest(imageName, current.tag);
}
return {
...container,
current: {
version,
hash: (
await docker.getImage(container.Image).inspect()
).RepoDigests[0]
?.split(":")[1]
?.substring(0, 12),
},
containerName: container.Names[0]?.replace("/", ""),
imageName,
current,
latest,
};
}),
);
return dockerInfo;
}),
});
@@ -58,27 +66,58 @@ function isSemver(tag: string): boolean {
return !!semver.valid(removeV);
}
async function getLatestSemverTag(image: string): Promise<string> {
async function getLatestSemverTag(image: string, tag?: string): Promise<{ hash: string; tag?: string }> {
try {
const allTags =
await $`bin/regctl tag ls --exclude 'version.*' --exclude 'unstable.*' --exclude '.*rc.*' --exclude 'lib.*' --exclude 'release.*' --exclude 'arm.*
const latest = {
hash: "",
tag: "",
};
const allTags = await $`bin/regctl tag ls --exclude 'version.*' --exclude 'unstable.*' --exclude '.*rc.*' --exclude 'lib.*' --exclude 'release.*' --exclude 'arm.*
' --exclude 'amd.*' ${image}`.text();
const semverTags = allTags
.split("\n")
.slice(-20)
.filter((tag) => isSemver(tag));
return semver.rsort(semverTags)[0] ?? "Error";
const semverTags = allTags.split("\n").filter((tag) => isSemver(tag));
const newestTag = semver.rsort(semverTags)[0];
let imageSh = image;
if (newestTag) {
imageSh += `:${newestTag}`;
latest.tag = newestTag;
}
const latestImage = await $`bin/regctl image digest ${imageSh}`.text();
latest.hash = latestImage.split(":")?.[1]?.substring(0, 12) ?? "Error";
return latest;
} catch (ex) {
return "Error";
console.error((ex as unknown as Error).message);
return {
hash: "Error",
tag: "Error",
};
}
}
async function getLatestHash(image: string): Promise<string> {
async function getLatest(image: string, tag?: string): Promise<{ hash: string; tag?: string }> {
try {
const latestImage = await $`bin/regctl image digest ${image}`.text();
const latestHash = latestImage.split(":")?.[1];
return latestHash?.substring(0, 12) ?? "Error";
let latest: { hash: string; tag?: string } = {
hash: "",
tag: tag,
};
if (tag && isSemver(tag)) {
latest = await getLatestSemverTag(image, tag);
} else {
let imageSh = image;
if (tag) {
imageSh += `:${tag}`;
}
const latestImage = await $`bin/regctl image digest ${imageSh}`.text();
latest.hash = latestImage.split(":")?.[1]?.substring(0, 12) ?? "Error";
}
return latest;
} catch (ex) {
return "Error";
console.error((ex as unknown as Error).message);
return {
hash: "Error",
tag: "Error",
};
}
}

View File

@@ -42,8 +42,7 @@ const t = initTRPC.context<typeof createTRPCContext>().create({
...shape,
data: {
...shape.data,
zodError:
error.cause instanceof ZodError ? error.cause.flatten() : null,
zodError: error.cause instanceof ZodError ? error.cause.flatten() : null,
},
};
},

View File

@@ -5,6 +5,5 @@
}
@theme {
--font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
--font-sans: var(--font-geist-sans), ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

View File

@@ -1,7 +1,4 @@
import {
QueryClient,
defaultShouldDehydrateQuery,
} from "@tanstack/react-query";
import { QueryClient, defaultShouldDehydrateQuery } from "@tanstack/react-query";
import SuperJSON from "superjson";
export const createQueryClient = () =>
@@ -14,9 +11,7 @@ export const createQueryClient = () =>
},
dehydrate: {
serializeData: SuperJSON.serialize,
shouldDehydrateQuery: (query) =>
defaultShouldDehydrateQuery(query) ||
query.state.status === "pending",
shouldDehydrateQuery: (query) => defaultShouldDehydrateQuery(query) || query.state.status === "pending",
},
hydrate: {
deserializeData: SuperJSON.deserialize,

View File

@@ -45,9 +45,7 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
api.createClient({
links: [
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === "development" ||
(op.direction === "down" && op.result instanceof Error),
enabled: (op) => process.env.NODE_ENV === "development" || (op.direction === "down" && op.result instanceof Error),
}),
httpBatchStreamLink({
transformer: SuperJSON,

View File

@@ -24,7 +24,4 @@ const createContext = cache(async () => {
const getQueryClient = cache(createQueryClient);
const caller = createCaller(createContext);
export const { trpc: api, HydrateClient } = createHydrationHelpers<AppRouter>(
caller,
getQueryClient,
);
export const { trpc: api, HydrateClient } = createHydrationHelpers<AppRouter>(caller, getQueryClient);

View File

@@ -30,13 +30,6 @@
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.js",
".next/types/**/*.ts"
],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.js", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}