From 14b41acfd14cd2ff9964cbe8a3a655c8d1da3434 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 5 May 2024 04:04:41 -0600 Subject: [PATCH 1/5] CircleCI Commit --- .circleci/config.yml | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 000000000..b499fd1ac --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,45 @@ +# This config was automatically generated from your source code +# Stacks detected: cicd:github-actions:.github/workflows,deps:node:. +version: 2.1 +orbs: + node: circleci/node@5 +jobs: + build-node: + # Build node project + executor: node/default + steps: + - checkout + - node/install-packages: + cache-path: ~/project/node_modules + override-ci-command: npm install + - run: + command: npm run build + - run: + name: Create the ~/artifacts directory if it doesn't exist + command: mkdir -p ~/artifacts + # Copy output to artifacts dir + - run: + name: Copy artifacts + command: cp -R build dist public .output .next .docusaurus ~/artifacts 2>/dev/null || true + - store_artifacts: + path: ~/artifacts + destination: node-build + deploy: + # This is an example deploy job, not actually used by the workflow + docker: + - image: cimg/base:stable + steps: + # Replace this with steps to deploy to users + - run: + name: deploy + command: '#e.g. ./deploy.sh' + - run: + name: found github actions config + command: ':' +workflows: + build: + jobs: + - build-node + # - deploy: + # requires: + # - build-node From fc590cec389a3a7b2beb5e5a14077fe97060a9be Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 5 May 2024 04:24:57 -0600 Subject: [PATCH 2/5] feat: add circle ci --- .circleci/config.yml | 66 +++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b499fd1ac..1e65f81b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,45 +1,43 @@ -# This config was automatically generated from your source code -# Stacks detected: cicd:github-actions:.github/workflows,deps:node:. version: 2.1 -orbs: - node: circleci/node@5 -jobs: - build-node: - # Build node project - executor: node/default +commands: + setup: steps: - checkout - - node/install-packages: - cache-path: ~/project/node_modules - override-ci-command: npm install - run: - command: npm run build + 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: Create the ~/artifacts directory if it doesn't exist - command: mkdir -p ~/artifacts - # Copy output to artifacts dir + name: Check versions + command: | + qemu-aarch64-static --version + update-binfmts --version - run: - name: Copy artifacts - command: cp -R build dist public .output .next .docusaurus ~/artifacts 2>/dev/null || true - - store_artifacts: - path: ~/artifacts - destination: node-build - deploy: - # This is an example deploy job, not actually used by the workflow - docker: - - image: cimg/base:stable + 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: - # Replace this with steps to deploy to users + - setup - run: - name: deploy - command: '#e.g. ./deploy.sh' + name: Login to Docker Hub + command: | + docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_TOKEN - run: - name: found github actions config - command: ':' + name: Build multiarch docker image and push + command: | + DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/arm64,linux/amd64 -t test . workflows: - build: + build-and-deploy: jobs: - - build-node - # - deploy: - # requires: - # - build-node + - build: + context: + - DOCKER_HUB \ No newline at end of file From 6c2c78f1beaca4b31ef8e86a14daca79579456a7 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 5 May 2024 04:29:03 -0600 Subject: [PATCH 3/5] refactor: add cp for env --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1e65f81b0..9811d94d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,6 +31,10 @@ jobs: 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: | From c11b09b4784cef42d798828285380c3f56861862 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 5 May 2024 12:40:03 -0600 Subject: [PATCH 4/5] refactor: add platform arm only --- docker/build.sh | 8 ++++---- server/queues/queueSetup.ts | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) 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/server/queues/queueSetup.ts b/server/queues/queueSetup.ts index 44b8f464a..b33b64aff 100644 --- a/server/queues/queueSetup.ts +++ b/server/queues/queueSetup.ts @@ -7,20 +7,21 @@ export const redisConfig: ConnectionOptions = { // 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 }; From 4cbd395dc6f4a05d39fd5fadf54581aaa3848ef8 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 5 May 2024 13:04:59 -0600 Subject: [PATCH 5/5] test: comment bullmq to prevent errors --- .circleci/config.yml | 5 ++- pages/api/deploy/[refreshToken].ts | 18 ++++---- server/api/routers/application.ts | 64 ++++++++++++++-------------- server/queues/deployments-queue.ts | 68 +++++++++++++++--------------- server/queues/queueSetup.ts | 21 +++++---- server/server.ts | 4 +- 6 files changed, 90 insertions(+), 90 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9811d94d9..bf2f469d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,10 +38,11 @@ jobs: - run: name: Build multiarch docker image and push command: | - DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform linux/arm64,linux/amd64 -t test . + 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 + - DOCKER_HUB + \ No newline at end of file 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 b33b64aff..301d3c9fc 100644 --- a/server/queues/queueSetup.ts +++ b/server/queues/queueSetup.ts @@ -1,14 +1,13 @@ -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(); @@ -24,4 +23,4 @@ const myQueue = new Queue("deployments", { // } // }); -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); }