bump: Traefik v3.5.0

This commit is contained in:
Vyacheslav Scherbinin
2025-08-13 08:23:30 +07:00
parent 9763dce045
commit 3864c50deb
2 changed files with 362 additions and 385 deletions
+8 -11
View File
@@ -1,17 +1,14 @@
import { execAsync } from "@dokploy/server"; import { execAsync } from '@dokploy/server';
import { setupDirectories } from "@dokploy/server/setup/config-paths"; import { setupDirectories } from '@dokploy/server/setup/config-paths';
import { initializePostgres } from "@dokploy/server/setup/postgres-setup"; import { initializePostgres } from '@dokploy/server/setup/postgres-setup';
import { initializeRedis } from "@dokploy/server/setup/redis-setup"; import { initializeRedis } from '@dokploy/server/setup/redis-setup';
import { import { initializeNetwork, initializeSwarm } from '@dokploy/server/setup/setup';
initializeNetwork,
initializeSwarm,
} from "@dokploy/server/setup/setup";
import { import {
createDefaultMiddlewares, createDefaultMiddlewares,
createDefaultServerTraefikConfig, createDefaultServerTraefikConfig,
createDefaultTraefikConfig, createDefaultTraefikConfig,
initializeStandaloneTraefik, initializeStandaloneTraefik,
} from "@dokploy/server/setup/traefik-setup"; } from '@dokploy/server/setup/traefik-setup';
(async () => { (async () => {
try { try {
@@ -21,11 +18,11 @@ import {
await initializeNetwork(); await initializeNetwork();
createDefaultTraefikConfig(); createDefaultTraefikConfig();
createDefaultServerTraefikConfig(); createDefaultServerTraefikConfig();
await execAsync("docker pull traefik:v3.1.2"); await execAsync('docker pull traefik:v3.5.0');
await initializeStandaloneTraefik(); await initializeStandaloneTraefik();
await initializeRedis(); await initializeRedis();
await initializePostgres(); await initializePostgres();
} catch (e) { } catch (e) {
console.error("Error in dokploy setup", e); console.error('Error in dokploy setup', e);
} }
})(); })();
+75 -95
View File
@@ -1,19 +1,16 @@
import { chmodSync, existsSync, mkdirSync, writeFileSync } from "node:fs"; import { chmodSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
import path from "node:path"; import path from 'node:path';
import type { ContainerCreateOptions, CreateServiceOptions } from "dockerode"; import type { ContainerCreateOptions, CreateServiceOptions } from 'dockerode';
import { dump } from "js-yaml"; import { dump } from 'js-yaml';
import { paths } from "../constants"; import { paths } from '../constants';
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';
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; export const TRAEFIK_PORT = Number.parseInt(process.env.TRAEFIK_PORT!, 10) || 80;
export const TRAEFIK_PORT = export const TRAEFIK_HTTP3_PORT = Number.parseInt(process.env.TRAEFIK_HTTP3_PORT!, 10) || 443;
Number.parseInt(process.env.TRAEFIK_PORT!, 10) || 80; export const TRAEFIK_VERSION = process.env.TRAEFIK_VERSION || '3.5.0';
export const TRAEFIK_HTTP3_PORT =
Number.parseInt(process.env.TRAEFIK_HTTP3_PORT!, 10) || 443;
export const TRAEFIK_VERSION = process.env.TRAEFIK_VERSION || "3.1.2";
export interface TraefikOptions { export interface TraefikOptions {
env?: string[]; env?: string[];
@@ -25,14 +22,10 @@ export interface TraefikOptions {
}[]; }[];
} }
export const initializeStandaloneTraefik = async ({ export const initializeStandaloneTraefik = async ({ env, serverId, additionalPorts = [] }: TraefikOptions = {}) => {
env,
serverId,
additionalPorts = [],
}: TraefikOptions = {}) => {
const { MAIN_TRAEFIK_PATH, DYNAMIC_TRAEFIK_PATH } = paths(!!serverId); const { MAIN_TRAEFIK_PATH, DYNAMIC_TRAEFIK_PATH } = paths(!!serverId);
const imageName = `traefik:v${TRAEFIK_VERSION}`; const imageName = `traefik:v${TRAEFIK_VERSION}`;
const containerName = "dokploy-traefik"; const containerName = 'dokploy-traefik';
const exposedPorts: Record<string, {}> = { const exposedPorts: Record<string, {}> = {
[`${TRAEFIK_PORT}/tcp`]: {}, [`${TRAEFIK_PORT}/tcp`]: {},
@@ -43,22 +36,18 @@ export const initializeStandaloneTraefik = async ({
const portBindings: Record<string, Array<{ HostPort: string }>> = { const portBindings: Record<string, Array<{ HostPort: string }>> = {
[`${TRAEFIK_PORT}/tcp`]: [{ HostPort: TRAEFIK_PORT.toString() }], [`${TRAEFIK_PORT}/tcp`]: [{ HostPort: TRAEFIK_PORT.toString() }],
[`${TRAEFIK_SSL_PORT}/tcp`]: [{ HostPort: TRAEFIK_SSL_PORT.toString() }], [`${TRAEFIK_SSL_PORT}/tcp`]: [{ HostPort: TRAEFIK_SSL_PORT.toString() }],
[`${TRAEFIK_HTTP3_PORT}/udp`]: [ [`${TRAEFIK_HTTP3_PORT}/udp`]: [{ HostPort: TRAEFIK_HTTP3_PORT.toString() }],
{ HostPort: TRAEFIK_HTTP3_PORT.toString() },
],
}; };
const enableDashboard = additionalPorts.some( const enableDashboard = additionalPorts.some((port) => port.targetPort === 8080);
(port) => port.targetPort === 8080,
);
if (enableDashboard) { if (enableDashboard) {
exposedPorts["8080/tcp"] = {}; exposedPorts['8080/tcp'] = {};
portBindings["8080/tcp"] = [{ HostPort: "8080" }]; portBindings['8080/tcp'] = [{ HostPort: '8080' }];
} }
for (const port of additionalPorts) { for (const port of additionalPorts) {
const portKey = `${port.targetPort}/${port.protocol ?? "tcp"}`; const portKey = `${port.targetPort}/${port.protocol ?? 'tcp'}`;
exposedPorts[portKey] = {}; exposedPorts[portKey] = {};
portBindings[portKey] = [{ HostPort: port.publishedPort.toString() }]; portBindings[portKey] = [{ HostPort: port.publishedPort.toString() }];
} }
@@ -68,18 +57,18 @@ export const initializeStandaloneTraefik = async ({
Image: imageName, Image: imageName,
NetworkingConfig: { NetworkingConfig: {
EndpointsConfig: { EndpointsConfig: {
"dokploy-network": {}, 'dokploy-network': {},
}, },
}, },
ExposedPorts: exposedPorts, ExposedPorts: exposedPorts,
HostConfig: { HostConfig: {
RestartPolicy: { RestartPolicy: {
Name: "always", Name: 'always',
}, },
Binds: [ Binds: [
`${MAIN_TRAEFIK_PATH}/traefik.yml:/etc/traefik/traefik.yml`, `${MAIN_TRAEFIK_PATH}/traefik.yml:/etc/traefik/traefik.yml`,
`${DYNAMIC_TRAEFIK_PATH}:/etc/dokploy/traefik/dynamic`, `${DYNAMIC_TRAEFIK_PATH}:/etc/dokploy/traefik/dynamic`,
"/var/run/docker.sock:/var/run/docker.sock", '/var/run/docker.sock:/var/run/docker.sock',
], ],
PortBindings: portBindings, PortBindings: portBindings,
}, },
@@ -96,17 +85,13 @@ export const initializeStandaloneTraefik = async ({
await docker.createContainer(settings); await docker.createContainer(settings);
const newContainer = docker.getContainer(containerName); const newContainer = docker.getContainer(containerName);
await newContainer.start(); await newContainer.start();
console.log("Traefik Started ✅"); console.log('Traefik Started ✅');
}; };
export const initializeTraefikService = async ({ export const initializeTraefikService = async ({ env, additionalPorts = [], serverId }: TraefikOptions) => {
env,
additionalPorts = [],
serverId,
}: TraefikOptions) => {
const { MAIN_TRAEFIK_PATH, DYNAMIC_TRAEFIK_PATH } = paths(!!serverId); const { MAIN_TRAEFIK_PATH, DYNAMIC_TRAEFIK_PATH } = paths(!!serverId);
const imageName = `traefik:v${TRAEFIK_VERSION}`; const imageName = `traefik:v${TRAEFIK_VERSION}`;
const appName = "dokploy-traefik"; const appName = 'dokploy-traefik';
const settings: CreateServiceOptions = { const settings: CreateServiceOptions = {
Name: appName, Name: appName,
@@ -116,25 +101,25 @@ export const initializeTraefikService = async ({
Env: env, Env: env,
Mounts: [ Mounts: [
{ {
Type: "bind", Type: 'bind',
Source: `${MAIN_TRAEFIK_PATH}/traefik.yml`, Source: `${MAIN_TRAEFIK_PATH}/traefik.yml`,
Target: "/etc/traefik/traefik.yml", Target: '/etc/traefik/traefik.yml',
}, },
{ {
Type: "bind", Type: 'bind',
Source: DYNAMIC_TRAEFIK_PATH, Source: DYNAMIC_TRAEFIK_PATH,
Target: "/etc/dokploy/traefik/dynamic", Target: '/etc/dokploy/traefik/dynamic',
}, },
{ {
Type: "bind", Type: 'bind',
Source: "/var/run/docker.sock", Source: '/var/run/docker.sock',
Target: "/var/run/docker.sock", Target: '/var/run/docker.sock',
}, },
], ],
}, },
Networks: [{ Target: "dokploy-network" }], Networks: [{ Target: 'dokploy-network' }],
Placement: { Placement: {
Constraints: ["node.role==manager"], Constraints: ['node.role==manager'],
}, },
}, },
Mode: { Mode: {
@@ -147,27 +132,27 @@ export const initializeTraefikService = async ({
{ {
TargetPort: 443, TargetPort: 443,
PublishedPort: TRAEFIK_SSL_PORT, PublishedPort: TRAEFIK_SSL_PORT,
PublishMode: "host", PublishMode: 'host',
Protocol: "tcp", Protocol: 'tcp',
}, },
{ {
TargetPort: 443, TargetPort: 443,
PublishedPort: TRAEFIK_SSL_PORT, PublishedPort: TRAEFIK_SSL_PORT,
PublishMode: "host", PublishMode: 'host',
Protocol: "udp", Protocol: 'udp',
}, },
{ {
TargetPort: 80, TargetPort: 80,
PublishedPort: TRAEFIK_PORT, PublishedPort: TRAEFIK_PORT,
PublishMode: "host", PublishMode: 'host',
Protocol: "tcp", Protocol: 'tcp',
}, },
...additionalPorts.map((port) => ({ ...additionalPorts.map((port) => ({
TargetPort: port.targetPort, TargetPort: port.targetPort,
PublishedPort: port.publishedPort, PublishedPort: port.publishedPort,
Protocol: port.protocol as "tcp" | "udp" | "sctp" | undefined, Protocol: port.protocol as 'tcp' | 'udp' | 'sctp' | undefined,
PublishMode: "host" as const, PublishMode: 'host' as const,
})), })),
], ],
}, },
@@ -185,23 +170,23 @@ export const initializeTraefikService = async ({
ForceUpdate: inspect.Spec.TaskTemplate.ForceUpdate + 1, ForceUpdate: inspect.Spec.TaskTemplate.ForceUpdate + 1,
}, },
}); });
console.log("Traefik Updated ✅"); console.log('Traefik Updated ✅');
} catch { } catch {
await docker.createService(settings); await docker.createService(settings);
console.log("Traefik Started ✅"); console.log('Traefik Started ✅');
} }
}; };
export const createDefaultServerTraefikConfig = () => { export const createDefaultServerTraefikConfig = () => {
const { DYNAMIC_TRAEFIK_PATH } = paths(); const { DYNAMIC_TRAEFIK_PATH } = paths();
const configFilePath = path.join(DYNAMIC_TRAEFIK_PATH, "dokploy.yml"); const configFilePath = path.join(DYNAMIC_TRAEFIK_PATH, 'dokploy.yml');
if (existsSync(configFilePath)) { if (existsSync(configFilePath)) {
console.log("Default traefik config already exists"); console.log('Default traefik config already exists');
return; return;
} }
const appName = "dokploy"; const appName = 'dokploy';
const serviceURLDefault = `http://${appName}:${process.env.PORT || 3000}`; const serviceURLDefault = `http://${appName}:${process.env.PORT || 3000}`;
const config: FileConfig = { const config: FileConfig = {
http: { http: {
@@ -209,7 +194,7 @@ export const createDefaultServerTraefikConfig = () => {
[`${appName}-router-app`]: { [`${appName}-router-app`]: {
rule: `Host(\`${appName}.docker.localhost\`) && PathPrefix(\`/\`)`, rule: `Host(\`${appName}.docker.localhost\`) && PathPrefix(\`/\`)`,
service: `${appName}-service-app`, service: `${appName}-service-app`,
entryPoints: ["web"], entryPoints: ['web'],
}, },
}, },
services: { services: {
@@ -225,11 +210,7 @@ export const createDefaultServerTraefikConfig = () => {
const yamlStr = dump(config); const yamlStr = dump(config);
mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true }); mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true });
writeFileSync( writeFileSync(path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`), yamlStr, 'utf8');
path.join(DYNAMIC_TRAEFIK_PATH, `${appName}.yml`),
yamlStr,
"utf8",
);
}; };
export const getDefaultTraefikConfig = () => { export const getDefaultTraefikConfig = () => {
@@ -238,11 +219,10 @@ export const getDefaultTraefikConfig = () => {
sendAnonymousUsage: false, sendAnonymousUsage: false,
}, },
providers: { providers: {
...(process.env.NODE_ENV === "development" ...(process.env.NODE_ENV === 'development'
? { ? {
docker: { docker: {
defaultRule: defaultRule: 'Host(`{{ trimPrefix `/` .Name }}.docker.localhost`)',
"Host(`{{ trimPrefix `/` .Name }}.docker.localhost`)",
}, },
} }
: { : {
@@ -253,11 +233,11 @@ export const getDefaultTraefikConfig = () => {
docker: { docker: {
exposedByDefault: false, exposedByDefault: false,
watch: true, watch: true,
network: "dokploy-network", network: 'dokploy-network',
}, },
}), }),
file: { file: {
directory: "/etc/dokploy/traefik/dynamic", directory: '/etc/dokploy/traefik/dynamic',
watch: true, watch: true,
}, },
}, },
@@ -270,10 +250,10 @@ export const getDefaultTraefikConfig = () => {
http3: { http3: {
advertisedPort: TRAEFIK_HTTP3_PORT, advertisedPort: TRAEFIK_HTTP3_PORT,
}, },
...(process.env.NODE_ENV === "production" && { ...(process.env.NODE_ENV === 'production' && {
http: { http: {
tls: { tls: {
certResolver: "letsencrypt", certResolver: 'letsencrypt',
}, },
}, },
}), }),
@@ -282,14 +262,14 @@ export const getDefaultTraefikConfig = () => {
api: { api: {
insecure: true, insecure: true,
}, },
...(process.env.NODE_ENV === "production" && { ...(process.env.NODE_ENV === 'production' && {
certificatesResolvers: { certificatesResolvers: {
letsencrypt: { letsencrypt: {
acme: { acme: {
email: "[email protected]", email: '[email protected]',
storage: "/etc/dokploy/traefik/dynamic/acme.json", storage: '/etc/dokploy/traefik/dynamic/acme.json',
httpChallenge: { httpChallenge: {
entryPoint: "web", entryPoint: 'web',
}, },
}, },
}, },
@@ -312,10 +292,10 @@ export const getDefaultServerTraefikConfig = () => {
docker: { docker: {
exposedByDefault: false, exposedByDefault: false,
watch: true, watch: true,
network: "dokploy-network", network: 'dokploy-network',
}, },
file: { file: {
directory: "/etc/dokploy/traefik/dynamic", directory: '/etc/dokploy/traefik/dynamic',
watch: true, watch: true,
}, },
}, },
@@ -330,7 +310,7 @@ export const getDefaultServerTraefikConfig = () => {
}, },
http: { http: {
tls: { tls: {
certResolver: "letsencrypt", certResolver: 'letsencrypt',
}, },
}, },
}, },
@@ -341,10 +321,10 @@ export const getDefaultServerTraefikConfig = () => {
certificatesResolvers: { certificatesResolvers: {
letsencrypt: { letsencrypt: {
acme: { acme: {
email: "[email protected]", email: '[email protected]',
storage: "/etc/dokploy/traefik/dynamic/acme.json", storage: '/etc/dokploy/traefik/dynamic/acme.json',
httpChallenge: { httpChallenge: {
entryPoint: "web", entryPoint: 'web',
}, },
}, },
}, },
@@ -358,28 +338,28 @@ export const getDefaultServerTraefikConfig = () => {
export const createDefaultTraefikConfig = () => { export const createDefaultTraefikConfig = () => {
const { MAIN_TRAEFIK_PATH, DYNAMIC_TRAEFIK_PATH } = paths(); const { MAIN_TRAEFIK_PATH, DYNAMIC_TRAEFIK_PATH } = paths();
const mainConfig = path.join(MAIN_TRAEFIK_PATH, "traefik.yml"); const mainConfig = path.join(MAIN_TRAEFIK_PATH, 'traefik.yml');
const acmeJsonPath = path.join(DYNAMIC_TRAEFIK_PATH, "acme.json"); const acmeJsonPath = path.join(DYNAMIC_TRAEFIK_PATH, 'acme.json');
if (existsSync(acmeJsonPath)) { if (existsSync(acmeJsonPath)) {
chmodSync(acmeJsonPath, "600"); chmodSync(acmeJsonPath, '600');
} }
if (existsSync(mainConfig)) { if (existsSync(mainConfig)) {
console.log("Main config already exists"); console.log('Main config already exists');
return; return;
} }
const yamlStr = getDefaultTraefikConfig(); const yamlStr = getDefaultTraefikConfig();
mkdirSync(MAIN_TRAEFIK_PATH, { recursive: true }); mkdirSync(MAIN_TRAEFIK_PATH, { recursive: true });
writeFileSync(mainConfig, yamlStr, "utf8"); writeFileSync(mainConfig, yamlStr, 'utf8');
}; };
export const getDefaultMiddlewares = () => { export const getDefaultMiddlewares = () => {
const defaultMiddlewares = { const defaultMiddlewares = {
http: { http: {
middlewares: { middlewares: {
"redirect-to-https": { 'redirect-to-https': {
redirectScheme: { redirectScheme: {
scheme: "https", scheme: 'https',
permanent: true, permanent: true,
}, },
}, },
@@ -391,12 +371,12 @@ export const getDefaultMiddlewares = () => {
}; };
export const createDefaultMiddlewares = () => { export const createDefaultMiddlewares = () => {
const { DYNAMIC_TRAEFIK_PATH } = paths(); const { DYNAMIC_TRAEFIK_PATH } = paths();
const middlewaresPath = path.join(DYNAMIC_TRAEFIK_PATH, "middlewares.yml"); const middlewaresPath = path.join(DYNAMIC_TRAEFIK_PATH, 'middlewares.yml');
if (existsSync(middlewaresPath)) { if (existsSync(middlewaresPath)) {
console.log("Default middlewares already exists"); console.log('Default middlewares already exists');
return; return;
} }
const yamlStr = getDefaultMiddlewares(); const yamlStr = getDefaultMiddlewares();
mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true }); mkdirSync(DYNAMIC_TRAEFIK_PATH, { recursive: true });
writeFileSync(middlewaresPath, yamlStr, "utf8"); writeFileSync(middlewaresPath, yamlStr, 'utf8');
}; };