Skip to content

Commit

Permalink
Merge branch 'main' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Mar 10, 2025
2 parents acc8ce8 + f159dc1 commit 8df2b20
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/setup/server-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export const createTraefikInstance = () => {
if docker service inspect dokploy-traefik > /dev/null 2>&1; then
echo "Migrating Traefik to Standalone..."
docker service rm dokploy-traefik
sleep 7
sleep 8
echo "Traefik migrated to Standalone ✅"
fi
Expand Down
47 changes: 40 additions & 7 deletions packages/server/src/setup/traefik-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,26 @@ export const initializeTraefik = async ({
try {
const service = docker.getService("dokploy-traefik");
await service?.remove({ force: true });
await new Promise((resolve) => setTimeout(resolve, 5000));
} catch (_) {}

let attempts = 0;
const maxAttempts = 5;
while (attempts < maxAttempts) {
try {
await docker.listServices({
filters: { name: ["dokploy-traefik"] },
});
console.log("Waiting for service cleanup...");
await new Promise((resolve) => setTimeout(resolve, 5000));
attempts++;
} catch (e) {
break;
}
}
} catch (err) {
console.log("No existing service to remove");
}

// Then try to remove any existing container
const container = docker.getContainer(containerName);
try {
const inspect = await container.inspect();
Expand All @@ -103,15 +120,31 @@ export const initializeTraefik = async ({
}

await container.remove({ force: true });
await new Promise((resolve) => setTimeout(resolve, 5000));
} catch (error) {
console.log(error);
console.log("No existing container to remove");
}

await docker.createContainer(settings);
const newContainer = docker.getContainer(containerName);
await newContainer.start();
// Create and start the new container
try {
await docker.createContainer(settings);
const newContainer = docker.getContainer(containerName);
await newContainer.start();
console.log("Traefik container started successfully");
} catch (error: any) {
if (error?.json?.message?.includes("port is already allocated")) {
console.log("Ports still in use, waiting longer for cleanup...");
await new Promise((resolve) => setTimeout(resolve, 10000));
// Try one more time
await docker.createContainer(settings);
const newContainer = docker.getContainer(containerName);
await newContainer.start();
console.log("Traefik container started successfully after retry");
}
}
} catch (error) {
console.log(error);
console.error("Failed to initialize Traefik:", error);
throw error;
}
};

Expand Down

0 comments on commit 8df2b20

Please sign in to comment.