mirror of
https://github.com/LukeHagar/dokploy.git
synced 2025-12-06 04:19:37 +00:00
* feat(WIP): compose implementation * feat: add volumes, networks, services name hash generate * feat: add compose config test unique * feat: add tests for each unique config * feat: implement lodash for docker compose parsing * feat: add tests for generating compose file * refactor: implement logs docker compose * refactor: composeFile set not empty * feat: implement providers for compose deployments * feat: add Files volumes to compose * feat: add stop compose button * refactor: change strategie of building compose * feat: create .env file in composepath * refactor: simplify git and github function * chore: update deps * refactor: update migrations and add badge to recognize compose type * chore: update lock yaml * refactor: use code editor * feat: add monitoring for app types * refactor: reset stats on change appName * refactor: add option to clean monitoring folder * feat: show current command that will run * feat: add prefix * fix: add missing types * refactor: add docker provider and expose by default as false * refactor: customize error page * refactor: unified deployments to be a single one * feat: add vitest to ci/cd * revert: back to initial version * refactor: add maxconcurrency vitest * refactor: add pool forks to vitest * feat: add pocketbase template * fix: update path resolution compose * removed * feat: add template pocketbase * feat: add pocketbase template * feat: add support button * feat: add plausible template * feat: add calcom template * feat: add version to each template * feat: add code editor to enviroment variables and swarm settings json * refactor: add loader when download the image * fix: use base64 to generate keys plausible * feat: add recognized domain names by enviroment compose * refactor: show alert to redeploy in each card advanced tab * refactor: add validation to prevent create compose if not have permissions * chore: add templates section to contributing * chore: add example contributing
376 lines
6.3 KiB
TypeScript
376 lines
6.3 KiB
TypeScript
import {
|
|
addPrefixToAllServiceNames,
|
|
addPrefixToServiceNames,
|
|
} from "@/server/utils/docker/compose/service";
|
|
import type { ComposeSpecification } from "@/server/utils/docker/types";
|
|
import { load } from "js-yaml";
|
|
import { expect, test } from "vitest";
|
|
|
|
const composeFileCombinedAllCases = `
|
|
version: "3.8"
|
|
|
|
services:
|
|
web:
|
|
image: nginx:latest
|
|
container_name: web_container
|
|
links:
|
|
- api
|
|
depends_on:
|
|
- api
|
|
extends: base_service
|
|
|
|
api:
|
|
image: myapi:latest
|
|
depends_on:
|
|
db:
|
|
condition: service_healthy
|
|
volumes_from:
|
|
- db
|
|
|
|
db:
|
|
image: postgres:latest
|
|
|
|
base_service:
|
|
image: base:latest
|
|
|
|
networks:
|
|
default:
|
|
driver: bridge
|
|
`;
|
|
|
|
const expectedComposeFile = load(`
|
|
version: "3.8"
|
|
|
|
services:
|
|
web-testhash:
|
|
image: nginx:latest
|
|
container_name: web_container-testhash
|
|
links:
|
|
- api-testhash
|
|
depends_on:
|
|
- api-testhash
|
|
extends: base_service-testhash
|
|
|
|
api-testhash:
|
|
image: myapi:latest
|
|
depends_on:
|
|
db-testhash:
|
|
condition: service_healthy
|
|
volumes_from:
|
|
- db-testhash
|
|
|
|
db-testhash:
|
|
image: postgres:latest
|
|
|
|
base_service-testhash:
|
|
image: base:latest
|
|
|
|
networks:
|
|
default:
|
|
driver: bridge
|
|
`);
|
|
|
|
test("Add prefix to all service names in compose file", () => {
|
|
const composeData = load(composeFileCombinedAllCases) as ComposeSpecification;
|
|
|
|
const prefix = "testhash";
|
|
|
|
if (!composeData.services) {
|
|
return;
|
|
}
|
|
const updatedComposeData = addPrefixToServiceNames(
|
|
composeData.services,
|
|
prefix,
|
|
);
|
|
const actualComposeData = { ...composeData, services: updatedComposeData };
|
|
|
|
expect(actualComposeData).toEqual(expectedComposeFile);
|
|
});
|
|
|
|
const composeFile1 = `
|
|
version: "3.8"
|
|
|
|
services:
|
|
web:
|
|
image: nginx:latest
|
|
container_name: web_container
|
|
depends_on:
|
|
- app
|
|
networks:
|
|
- frontend
|
|
volumes_from:
|
|
- data
|
|
links:
|
|
- db
|
|
extends:
|
|
service: base_service
|
|
|
|
app:
|
|
image: node:14
|
|
networks:
|
|
- backend
|
|
- frontend
|
|
|
|
db:
|
|
image: postgres:13
|
|
networks:
|
|
- backend
|
|
|
|
data:
|
|
image: busybox
|
|
volumes:
|
|
- /data
|
|
|
|
base_service:
|
|
image: base:latest
|
|
|
|
networks:
|
|
frontend:
|
|
driver: bridge
|
|
backend:
|
|
driver: bridge
|
|
`;
|
|
|
|
const expectedComposeFile1 = load(`
|
|
version: "3.8"
|
|
|
|
services:
|
|
web-testhash:
|
|
image: nginx:latest
|
|
container_name: web_container-testhash
|
|
depends_on:
|
|
- app-testhash
|
|
networks:
|
|
- frontend
|
|
volumes_from:
|
|
- data-testhash
|
|
links:
|
|
- db-testhash
|
|
extends:
|
|
service: base_service-testhash
|
|
|
|
app-testhash:
|
|
image: node:14
|
|
networks:
|
|
- backend
|
|
- frontend
|
|
|
|
db-testhash:
|
|
image: postgres:13
|
|
networks:
|
|
- backend
|
|
|
|
data-testhash:
|
|
image: busybox
|
|
volumes:
|
|
- /data
|
|
|
|
base_service-testhash:
|
|
image: base:latest
|
|
|
|
networks:
|
|
frontend:
|
|
driver: bridge
|
|
backend:
|
|
driver: bridge
|
|
`) as ComposeSpecification;
|
|
|
|
test("Add prefix to all service names in compose file 1", () => {
|
|
const composeData = load(composeFile1) as ComposeSpecification;
|
|
const prefix = "testhash";
|
|
|
|
const updatedComposeData = addPrefixToAllServiceNames(composeData, prefix);
|
|
|
|
expect(updatedComposeData).toEqual(expectedComposeFile1);
|
|
});
|
|
|
|
const composeFile2 = `
|
|
version: "3.8"
|
|
|
|
services:
|
|
frontend:
|
|
image: nginx:latest
|
|
depends_on:
|
|
- backend
|
|
networks:
|
|
- public
|
|
volumes_from:
|
|
- logs
|
|
links:
|
|
- cache
|
|
extends:
|
|
service: shared_service
|
|
|
|
backend:
|
|
image: node:14
|
|
networks:
|
|
- private
|
|
- public
|
|
|
|
cache:
|
|
image: redis:latest
|
|
networks:
|
|
- private
|
|
|
|
logs:
|
|
image: busybox
|
|
volumes:
|
|
- /logs
|
|
|
|
shared_service:
|
|
image: shared:latest
|
|
|
|
networks:
|
|
public:
|
|
driver: bridge
|
|
private:
|
|
driver: bridge
|
|
`;
|
|
|
|
const expectedComposeFile2 = load(`
|
|
version: "3.8"
|
|
|
|
services:
|
|
frontend-testhash:
|
|
image: nginx:latest
|
|
depends_on:
|
|
- backend-testhash
|
|
networks:
|
|
- public
|
|
volumes_from:
|
|
- logs-testhash
|
|
links:
|
|
- cache-testhash
|
|
extends:
|
|
service: shared_service-testhash
|
|
|
|
backend-testhash:
|
|
image: node:14
|
|
networks:
|
|
- private
|
|
- public
|
|
|
|
cache-testhash:
|
|
image: redis:latest
|
|
networks:
|
|
- private
|
|
|
|
logs-testhash:
|
|
image: busybox
|
|
volumes:
|
|
- /logs
|
|
|
|
shared_service-testhash:
|
|
image: shared:latest
|
|
|
|
networks:
|
|
public:
|
|
driver: bridge
|
|
private:
|
|
driver: bridge
|
|
`) as ComposeSpecification;
|
|
|
|
test("Add prefix to all service names in compose file 2", () => {
|
|
const composeData = load(composeFile2) as ComposeSpecification;
|
|
const prefix = "testhash";
|
|
|
|
const updatedComposeData = addPrefixToAllServiceNames(composeData, prefix);
|
|
|
|
expect(updatedComposeData).toEqual(expectedComposeFile2);
|
|
});
|
|
|
|
const composeFile3 = `
|
|
version: "3.8"
|
|
|
|
services:
|
|
service_a:
|
|
image: service_a:latest
|
|
depends_on:
|
|
- service_b
|
|
networks:
|
|
- net_a
|
|
volumes_from:
|
|
- data_volume
|
|
links:
|
|
- service_c
|
|
extends:
|
|
service: common_service
|
|
|
|
service_b:
|
|
image: service_b:latest
|
|
networks:
|
|
- net_b
|
|
- net_a
|
|
|
|
service_c:
|
|
image: service_c:latest
|
|
networks:
|
|
- net_b
|
|
|
|
data_volume:
|
|
image: busybox
|
|
volumes:
|
|
- /data
|
|
|
|
common_service:
|
|
image: common:latest
|
|
|
|
networks:
|
|
net_a:
|
|
driver: bridge
|
|
net_b:
|
|
driver: bridge
|
|
`;
|
|
|
|
const expectedComposeFile3 = load(`
|
|
version: "3.8"
|
|
|
|
services:
|
|
service_a-testhash:
|
|
image: service_a:latest
|
|
depends_on:
|
|
- service_b-testhash
|
|
networks:
|
|
- net_a
|
|
volumes_from:
|
|
- data_volume-testhash
|
|
links:
|
|
- service_c-testhash
|
|
extends:
|
|
service: common_service-testhash
|
|
|
|
service_b-testhash:
|
|
image: service_b:latest
|
|
networks:
|
|
- net_b
|
|
- net_a
|
|
|
|
service_c-testhash:
|
|
image: service_c:latest
|
|
networks:
|
|
- net_b
|
|
|
|
data_volume-testhash:
|
|
image: busybox
|
|
volumes:
|
|
- /data
|
|
|
|
common_service-testhash:
|
|
image: common:latest
|
|
|
|
networks:
|
|
net_a:
|
|
driver: bridge
|
|
net_b:
|
|
driver: bridge
|
|
`) as ComposeSpecification;
|
|
|
|
test("Add prefix to all service names in compose file 3", () => {
|
|
const composeData = load(composeFile3) as ComposeSpecification;
|
|
const prefix = "testhash";
|
|
|
|
const updatedComposeData = addPrefixToAllServiceNames(composeData, prefix);
|
|
|
|
expect(updatedComposeData).toEqual(expectedComposeFile3);
|
|
});
|