Files
dokploy/apps/dokploy/server/api/services/registry.ts
Mauricio Siu 5280c861e8 Feat/monorepo (#292)
* feat(create-turbo): apply official-starter transform

* refactor: move folder

* wip: monorepo

* feat: add builf

* refactor: add pr

* update

* add .env

* refactor: update build

* refactor: update build docker

* refactor: add progress plain

* refactor: remove node pty

* refactor: remove

* remove

* refactor: update

* refacotr: uopdate

* refactor: add remix app

* add env

* refactor: add pnpm start

* refactor: remove

* refactor: remove folders

* refactor: remove .dockerfile

* chore: update biome

* test

* choe: add husky

* remove .docker folder

* feat: add docs website

* refactor: add husky

* chore(version): bump version

* refactor: add new changes

* refactor: update circle path

* refactor: update

* refactor: update

* refactor: update dockerfile

* refactor: update dockerfile

* refactor: update command

* refactor: update

* refactor: update dockerfile

* refactor: add tsx

* refactor: update dockerfile

* refactor: add deps

* refactor: up[date

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: yuodate

* refactor: remove

* refactor: uncomment

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: updare

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: imprt

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: remove

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: change path

* refactor: update

* refactor: update

* refactor: upoadte

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: add

* refactor: update

* refactor: update

* refactor: add

* refactor: update

* refactor: remove

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: removed

* refactor: update

* refactor: update

* refactor: update

* refactor: add config

* refactor: update

* refactor: add

* refactor: update

* refactor: update

* refactor: remove

* refactor: update

* refactor: remove

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: add docs

* refactor: update

* refactor: add website

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: add ignore builds

* refactor: update

* refactor: update

* refactor: add

* refactor: update

* refactor: update

* refactor: remove needs

* refactor: update

* refactor: update

* refactor: add config

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: remove

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: add

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: upodate

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update

* refactor: update package json

* refactor: add biome

* refactor: add sponsors

* refactor: update

* refactor: update

* refactor: remove

* refactor: update

* refactor: update

* refactor: update

* refactor: update scripts

* refactor: remove

* refactor: update

* refactor: remove

---------

Co-authored-by: Turbobot <turbobot@vercel.com>
2024-07-29 23:08:23 -06:00

125 lines
3.0 KiB
TypeScript

import { db } from "@/server/db";
import { type apiCreateRegistry, registry } from "@/server/db/schema";
import { initializeRegistry } from "@/server/setup/registry-setup";
import { removeService } from "@/server/utils/docker/utils";
import { execAsync } from "@/server/utils/process/execAsync";
import {
manageRegistry,
removeSelfHostedRegistry,
} from "@/server/utils/traefik/registry";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
import { findAdmin } from "./admin";
export type Registry = typeof registry.$inferSelect;
export const createRegistry = async (input: typeof apiCreateRegistry._type) => {
const admin = await findAdmin();
return await db.transaction(async (tx) => {
const newRegistry = await tx
.insert(registry)
.values({
...input,
adminId: admin.adminId,
})
.returning()
.then((value) => value[0]);
if (!newRegistry) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error input: Inserting registry",
});
}
if (newRegistry.registryType === "cloud") {
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) => {
try {
const response = await db
.delete(registry)
.where(eq(registry.registryId, registryId))
.returning()
.then((res) => res[0]);
if (!response) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Registry not found",
});
}
if (response.registryType === "selfHosted") {
await removeSelfHostedRegistry();
await removeService("dokploy-registry");
}
await execAsync(`docker logout ${response.registryUrl}`);
return response;
} catch (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error to remove this registry",
cause: error,
});
}
};
export const updateRegistry = async (
registryId: string,
registryData: Partial<Registry>,
) => {
try {
const response = await db
.update(registry)
.set({
...registryData,
})
.where(eq(registry.registryId, registryId))
.returning()
.then((res) => res[0]);
if (response?.registryType === "selfHosted") {
await manageRegistry(response);
await initializeRegistry(response.username, response.password);
}
return response;
} catch (error) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error to update this registry",
});
}
};
export const findRegistryById = async (registryId: string) => {
const registryResponse = await db.query.registry.findFirst({
where: eq(registry.registryId, registryId),
columns: {
password: false,
},
});
if (!registryResponse) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Registry not found",
});
}
return registryResponse;
};
export const findAllRegistry = async () => {
const registryResponse = await db.query.registry.findMany();
return registryResponse;
};