mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(#125): don't add the registry if the login already exists
This commit is contained in:
parent
449a61e208
commit
eea00d28cd
@ -62,7 +62,7 @@ export const registryRouter = createTRPCRouter({
|
|||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error Registry:", error);
|
console.log("Error Registry:", error);
|
||||||
return error;
|
return false;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -9,28 +9,35 @@ import {
|
|||||||
} from "@/server/utils/traefik/registry";
|
} from "@/server/utils/traefik/registry";
|
||||||
import { removeService } from "@/server/utils/docker/utils";
|
import { removeService } from "@/server/utils/docker/utils";
|
||||||
import { initializeRegistry } from "@/server/setup/registry-setup";
|
import { initializeRegistry } from "@/server/setup/registry-setup";
|
||||||
|
import { execAsync } from "@/server/utils/process/execAsync";
|
||||||
|
|
||||||
export type Registry = typeof registry.$inferSelect;
|
export type Registry = typeof registry.$inferSelect;
|
||||||
|
|
||||||
export const createRegistry = async (input: typeof apiCreateRegistry._type) => {
|
export const createRegistry = async (input: typeof apiCreateRegistry._type) => {
|
||||||
const admin = await findAdmin();
|
const admin = await findAdmin();
|
||||||
|
|
||||||
const newRegistry = await db
|
return await db.transaction(async (tx) => {
|
||||||
.insert(registry)
|
const newRegistry = await tx
|
||||||
.values({
|
.insert(registry)
|
||||||
...input,
|
.values({
|
||||||
adminId: admin.adminId,
|
...input,
|
||||||
})
|
adminId: admin.adminId,
|
||||||
.returning()
|
})
|
||||||
.then((value) => value[0]);
|
.returning()
|
||||||
|
.then((value) => value[0]);
|
||||||
|
|
||||||
if (!newRegistry) {
|
if (!newRegistry) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Error input: Inserting registry",
|
message: "Error input: Inserting registry",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return newRegistry;
|
|
||||||
|
const loginCommand = `echo ${input.password} | docker login ${input.registryUrl} --username ${input.username} --password-stdin`;
|
||||||
|
await execAsync(loginCommand);
|
||||||
|
|
||||||
|
return newRegistry;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeRegistry = async (registryId: string) => {
|
export const removeRegistry = async (registryId: string) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user