diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..bf2f469d9 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,48 @@ +version: 2.1 +commands: + setup: + steps: + - checkout + - run: + name: Setup buildx and qemu + command: | + sudo apt-get update + sudo apt-get install -y qemu-user-static + sudo apt-get install -y binfmt-support + - run: + name: Check versions + command: | + qemu-aarch64-static --version + update-binfmts --version + - run: + name: Create builder + command: | + export DOCKER_CLI_EXPERIMENTAL=enabled + docker buildx create --name arm-builder + docker buildx use arm-builder + docker buildx inspect --bootstrap +jobs: + build: + machine: + image: ubuntu-2004:202010-01 + steps: + - setup + - run: + name: Login to Docker Hub + command: | + docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN + - run: + name: env + command: | + cp .env.production.example .env.production + - run: + name: Build multiarch docker image and push + command: | + DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/arm64 -t test . +workflows: + build-and-deploy: + jobs: + - build: + context: + - DOCKER_HUB + \ No newline at end of file diff --git a/docker/build.sh b/docker/build.sh index ef38fa4fa..6a484e865 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -10,8 +10,8 @@ else TAG="$VERSION" fi -BUILDER=$(docker buildx create --use) +# BUILDER=$(docker buildx create --use) -docker buildx build --platform linux/amd64,linux/arm64 --pull --rm -t "dokploy/dokploy:${TAG}" -f 'Dockerfile' . - -docker buildx rm $BUILDER +docker buildx build --platform linux/arm64 --pull --rm -t "dokploy/dokploy:${TAG}" -f 'Dockerfile' . +# +# docker buildx rm $BUILDER diff --git a/pages/api/deploy/[refreshToken].ts b/pages/api/deploy/[refreshToken].ts index 5f88decdc..6cada2946 100644 --- a/pages/api/deploy/[refreshToken].ts +++ b/pages/api/deploy/[refreshToken].ts @@ -2,7 +2,7 @@ import { updateApplicationStatus } from "@/server/api/services/application"; import { db } from "@/server/db"; import { applications } from "@/server/db/schema"; import type { DeploymentJob } from "@/server/queues/deployments-queue"; -import { myQueue } from "@/server/queues/queueSetup"; +// import { myQueue } from "@/server/queues/queueSetup"; import { eq } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; @@ -60,14 +60,14 @@ export default async function handler( titleLog: deploymentTitle, type: "deploy", }; - await myQueue.add( - "deployments", - { ...jobData }, - { - removeOnComplete: true, - removeOnFail: true, - }, - ); + // await myQueue.add( + // "deployments", + // { ...jobData }, + // { + // removeOnComplete: true, + // removeOnFail: true, + // }, + // ); } catch (error) { res.status(400).json({ message: "Error To Deploy Application", error }); return; diff --git a/server/api/routers/application.ts b/server/api/routers/application.ts index 304d04498..8502b153a 100644 --- a/server/api/routers/application.ts +++ b/server/api/routers/application.ts @@ -13,11 +13,11 @@ import { apiUpdateApplication, applications, } from "@/server/db/schema/application"; -import { - cleanQueuesByApplication, - type DeploymentJob, -} from "@/server/queues/deployments-queue"; -import { myQueue } from "@/server/queues/queueSetup"; +// import { +// // cleanQueuesByApplication, +// type DeploymentJob, +// } from "@/server/queues/deployments-queue"; +// import { myQueue } from "@/server/queues/queueSetup"; import { removeService, startService, @@ -156,19 +156,19 @@ export const applicationRouter = createTRPCRouter({ redeploy: protectedProcedure .input(apiFindOneApplication) .mutation(async ({ input }) => { - const jobData: DeploymentJob = { - applicationId: input.applicationId, - titleLog: "Rebuild deployment", - type: "redeploy", - }; - await myQueue.add( - "deployments", - { ...jobData }, - { - removeOnComplete: true, - removeOnFail: true, - }, - ); + // const jobData: DeploymentJob = { + // applicationId: input.applicationId, + // titleLog: "Rebuild deployment", + // type: "redeploy", + // }; + // await myQueue.add( + // "deployments", + // { ...jobData }, + // { + // removeOnComplete: true, + // removeOnFail: true, + // }, + // ); }), saveEnvironment: protectedProcedure .input(apiSaveEnvironmentVariables) @@ -287,25 +287,25 @@ export const applicationRouter = createTRPCRouter({ deploy: protectedProcedure .input(apiFindOneApplication) .mutation(async ({ input }) => { - const jobData: DeploymentJob = { - applicationId: input.applicationId, - titleLog: "Manual deployment", - type: "deploy", - }; - await myQueue.add( - "deployments", - { ...jobData }, - { - removeOnComplete: true, - removeOnFail: true, - }, - ); + // const jobData: DeploymentJob = { + // applicationId: input.applicationId, + // titleLog: "Manual deployment", + // type: "deploy", + // }; + // await myQueue.add( + // "deployments", + // { ...jobData }, + // { + // removeOnComplete: true, + // removeOnFail: true, + // }, + // ); }), cleanQueues: protectedProcedure .input(apiFindOneApplication) .mutation(async ({ input }) => { - await cleanQueuesByApplication(input.applicationId); + // await cleanQueuesByApplication(input.applicationId); }), readTraefikConfig: protectedProcedure diff --git a/server/queues/deployments-queue.ts b/server/queues/deployments-queue.ts index 655297d80..6cb01a5f8 100644 --- a/server/queues/deployments-queue.ts +++ b/server/queues/deployments-queue.ts @@ -3,7 +3,7 @@ import { deployApplication, rebuildApplication, } from "../api/services/application"; -import { myQueue, redisConfig } from "./queueSetup"; +// import { myQueue, redisConfig } from "./queueSetup"; interface DeployJob { applicationId: string; @@ -13,38 +13,38 @@ interface DeployJob { export type DeploymentJob = DeployJob; -export const deploymentWorker = new Worker( - "deployments", - async (job: Job) => { - try { - if (job.data.type === "redeploy") { - await rebuildApplication({ - applicationId: job.data.applicationId, - titleLog: job.data.titleLog, - }); - } else if (job.data.type === "deploy") { - await deployApplication({ - applicationId: job.data.applicationId, - titleLog: job.data.titleLog, - }); - } - } catch (error) { - console.log("Error", error); - } - }, - { - autorun: false, - connection: redisConfig, - }, -); +// export const deploymentWorker = new Worker( +// "deployments", +// async (job: Job) => { +// try { +// if (job.data.type === "redeploy") { +// await rebuildApplication({ +// applicationId: job.data.applicationId, +// titleLog: job.data.titleLog, +// }); +// } else if (job.data.type === "deploy") { +// await deployApplication({ +// applicationId: job.data.applicationId, +// titleLog: job.data.titleLog, +// }); +// } +// } catch (error) { +// console.log("Error", error); +// } +// }, +// { +// autorun: false, +// connection: redisConfig, +// }, +// ); -export const cleanQueuesByApplication = async (applicationId: string) => { - const jobs = await myQueue.getJobs(["waiting", "delayed"]); +// export const cleanQueuesByApplication = async (applicationId: string) => { +// const jobs = await myQueue.getJobs(["waiting", "delayed"]); - for (const job of jobs) { - if (job.data.applicationId === applicationId) { - await job.remove(); - console.log(`Removed job ${job.id} for application ${applicationId}`); - } - } -}; +// for (const job of jobs) { +// if (job.data.applicationId === applicationId) { +// await job.remove(); +// console.log(`Removed job ${job.id} for application ${applicationId}`); +// } +// } +// }; diff --git a/server/queues/queueSetup.ts b/server/queues/queueSetup.ts index 44b8f464a..301d3c9fc 100644 --- a/server/queues/queueSetup.ts +++ b/server/queues/queueSetup.ts @@ -1,26 +1,26 @@ -import { Queue, type ConnectionOptions } from "bullmq"; +// import { Queue, type ConnectionOptions } from "bullmq"; -export const redisConfig: ConnectionOptions = { - host: process.env.NODE_ENV === "production" ? "dokploy-redis" : "127.0.0.1", - port: 6379, -}; -// TODO: maybe add a options to clean the queue to the times -const myQueue = new Queue("deployments", { - connection: redisConfig, -}); +// export const redisConfig: ConnectionOptions = { +// host: process.env.NODE_ENV === "production" ? "dokploy-redis" : "127.0.0.1", +// port: 6379, +// }; +// // TODO: maybe add a options to clean the queue to the times +// const myQueue = new Queue("deployments", { +// connection: redisConfig, +// }); -process.on("SIGTERM", () => { - myQueue.close(); - process.exit(0); -}); +// process.on("SIGTERM", () => { +// myQueue.close(); +// process.exit(0); +// }); -myQueue.on("error", (error) => { - if ((error as any).code === "ECONNREFUSED") { - console.error( - "Make sure you have installed Redis and it is running.", - error, - ); - } -}); +// myQueue.on("error", (error) => { +// if ((error as any).code === "ECONNREFUSED") { +// console.error( +// "Make sure you have installed Redis and it is running.", +// error, +// ); +// } +// }); -export { myQueue }; +// export { myQueue }; diff --git a/server/server.ts b/server/server.ts index cc2bd042e..67d177079 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1,7 +1,7 @@ import http from "node:http"; import { config } from "dotenv"; import next from "next"; -import { deploymentWorker } from "./queues/deployments-queue"; +// import { deploymentWorker } from "./queues/deployments-queue"; import { initCronJobs } from "./utils/backups"; import { getPublicIpWithFallback, @@ -60,7 +60,7 @@ void app.prepare().then(async () => { } server.listen(PORT); console.log("Server Started:", PORT); - deploymentWorker.run(); + // deploymentWorker.run(); } catch (e) { console.error("Main Server Error", e); }