mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(traefik): improve migration and removal of Traefik services
- Update Traefik service detection and removal logic in server and traefik setup - Use Docker service and container inspection methods for more robust service management - Add graceful migration and removal of existing Traefik services - Simplify image pulling and service removal process
This commit is contained in:
@@ -543,7 +543,14 @@ export const installRClone = () => `
|
|||||||
export const createTraefikInstance = () => {
|
export const createTraefikInstance = () => {
|
||||||
const command = `
|
const command = `
|
||||||
# Check if dokpyloy-traefik exists
|
# Check if dokpyloy-traefik exists
|
||||||
if docker ps -a --format '{{.Names}}' | grep -q '^dokploy-traefik$'; then
|
if docker service inspect dokploy-traefik > /dev/null 2>&1; then
|
||||||
|
echo "Migrating Traefik to Standalone..."
|
||||||
|
docker service rm dokploy-traefik
|
||||||
|
sleep 7
|
||||||
|
echo "Traefik migrated to Standalone ✅"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if docker inspect dokploy-traefik > /dev/null 2>&1; then
|
||||||
echo "Traefik already exists ✅"
|
echo "Traefik already exists ✅"
|
||||||
else
|
else
|
||||||
# Create the dokploy-traefik container
|
# Create the dokploy-traefik container
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ import path from "node:path";
|
|||||||
import type { ContainerCreateOptions } from "dockerode";
|
import type { ContainerCreateOptions } from "dockerode";
|
||||||
import { dump } from "js-yaml";
|
import { dump } from "js-yaml";
|
||||||
import { paths } from "../constants";
|
import { paths } from "../constants";
|
||||||
import { pullImage, pullRemoteImage } from "../utils/docker/utils";
|
|
||||||
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
import { getRemoteDocker } from "../utils/servers/remote-docker";
|
||||||
import type { FileConfig } from "../utils/traefik/file-types";
|
import type { FileConfig } from "../utils/traefik/file-types";
|
||||||
import type { MainTraefikConfig } from "../utils/traefik/types";
|
import type { MainTraefikConfig } from "../utils/traefik/types";
|
||||||
import { execAsync, execAsyncRemote } from "../utils/process/execAsync";
|
|
||||||
|
|
||||||
export const TRAEFIK_SSL_PORT =
|
export const TRAEFIK_SSL_PORT =
|
||||||
Number.parseInt(process.env.TRAEFIK_SSL_PORT!, 10) || 443;
|
Number.parseInt(process.env.TRAEFIK_SSL_PORT!, 10) || 443;
|
||||||
@@ -90,19 +88,11 @@ export const initializeTraefik = async ({
|
|||||||
|
|
||||||
const docker = await getRemoteDocker(serverId);
|
const docker = await getRemoteDocker(serverId);
|
||||||
try {
|
try {
|
||||||
if (serverId) {
|
try {
|
||||||
await pullRemoteImage(imageName, serverId);
|
const service = docker.getService("dokploy-traefik");
|
||||||
} else {
|
await service?.remove({ force: true });
|
||||||
await pullImage(imageName);
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
}
|
} catch (_) {}
|
||||||
|
|
||||||
// remove dokploy-service if it exists
|
|
||||||
const command = "docker service rm dokploy-service > /dev/null 2>&1";
|
|
||||||
if (serverId) {
|
|
||||||
await execAsyncRemote(command, serverId);
|
|
||||||
} else {
|
|
||||||
await execAsync(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
const container = docker.getContainer(containerName);
|
const container = docker.getContainer(containerName);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user