Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CircleCI Commit #49

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions pages/api/deploy/[refreshToken].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand Down
64 changes: 32 additions & 32 deletions server/api/routers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
68 changes: 34 additions & 34 deletions server/queues/deployments-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,38 +13,38 @@ interface DeployJob {

export type DeploymentJob = DeployJob;

export const deploymentWorker = new Worker(
"deployments",
async (job: Job<DeploymentJob>) => {
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<DeploymentJob>) => {
// 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}`);
// }
// }
// };
44 changes: 22 additions & 22 deletions server/queues/queueSetup.ts
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 2 additions & 2 deletions server/server.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
Loading