Skip to content

Commit

Permalink
feat(compas): add 'compas init docker'
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkdev98 committed Sep 13, 2023
1 parent 5f1d65d commit 1b18b4d
Show file tree
Hide file tree
Showing 9 changed files with 902 additions and 4 deletions.
13 changes: 12 additions & 1 deletion config/compas.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,16 @@
"shortcut": "C",
"command": ["npx", "compas", "run", "types", "--script-args", "clean"]
}
]
],
"dockerContainers": {
"compas-postgres-15": {
"image": "postgres:15",
"createArguments": "-e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e PGDATA=/var/lib/postgresql/data/pgdata -v compas-postgres-15:/var/lib/postgresql/data/pgdata -p 5432:5432"
},
"compas-minio": {
"image": "minio/minio",
"createArguments": "-e MINIO_ACCESS_KEY=minio -e MINIO_SECRET_KEY=minio123 -v compas-minio:/data -p 9000:9000",
"runArguments": "server /data"
}
}
}
3 changes: 2 additions & 1 deletion docs/docs/integrations/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ following contents:
{
"dockerContainers": {
"compas-postgres-15": {
"image": "postgres:15",
"createArguments": "-e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e PGDATA=/var/lib/postgresql/data/pgdata -v compas-postgres-15:/var/lib/postgresql/data/pgdata -p 5432:5432",
"image": "postgres:15"
"runArguments": ""
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions gen/compas.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export function applyCompasStructure(generator) {
})
.default(`[]`)
.docs("Available actions for this project."),

dockerContainers: T.generic()
.keys(T.string().pattern(/[a-z-0-9]+/g))
.values({
image: T.string(),
createArguments: T.string().optional(),
runArguments: T.string().optional(),
})
.default("{}")
.docs("Docker container configuration."),
};

generator.add(
Expand Down
6 changes: 5 additions & 1 deletion packages/compas/src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ if (args.length === 0) {
if (command === "init") {
const { initCompas } = await import("../main/init/compas.js");
await initCompas(env);
} else if (command === "init docker") {
const { initDocker } = await import("../main/init/docker.js");
await initDocker(env);
} else {
// eslint-disable-next-line no-console
logger.info(`Unsupported command. Available commands:
- compas
- compas init`);
- compas init
- compas init docker`);
}
}
148 changes: 148 additions & 0 deletions packages/compas/src/generated/common/structure.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,80 @@
}
}
}
},
"dockerContainers": {
"docString": "Docker container configuration.",
"isOptional": true,
"validator": {},
"sql": {},
"type": "generic",
"defaultValue": "{}",
"keys": {
"docString": "",
"isOptional": false,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1,
"pattern": "/[a-z-0-9]+/g"
},
"sql": {},
"type": "string"
},
"values": {
"docString": "",
"isOptional": false,
"validator": {
"allowNull": false,
"strict": true
},
"sql": {},
"type": "object",
"relations": [],
"keys": {
"image": {
"docString": "",
"isOptional": false,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1
},
"sql": {},
"type": "string"
},
"createArguments": {
"docString": "",
"isOptional": true,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1
},
"sql": {},
"type": "string"
},
"runArguments": {
"docString": "",
"isOptional": true,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1
},
"sql": {},
"type": "string"
}
}
}
}
}
},
Expand Down Expand Up @@ -646,6 +720,80 @@
}
}
}
},
"dockerContainers": {
"docString": "Docker container configuration.",
"isOptional": true,
"validator": {},
"sql": {},
"type": "generic",
"defaultValue": "{}",
"keys": {
"docString": "",
"isOptional": false,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1,
"pattern": "/[a-z-0-9]+/g"
},
"sql": {},
"type": "string"
},
"values": {
"docString": "",
"isOptional": false,
"validator": {
"allowNull": false,
"strict": true
},
"sql": {},
"type": "object",
"relations": [],
"keys": {
"image": {
"docString": "",
"isOptional": false,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1
},
"sql": {},
"type": "string"
},
"createArguments": {
"docString": "",
"isOptional": true,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1
},
"sql": {},
"type": "string"
},
"runArguments": {
"docString": "",
"isOptional": true,
"validator": {
"allowNull": false,
"trim": false,
"lowerCase": false,
"upperCase": false,
"min": 1
},
"sql": {},
"type": "string"
}
}
}
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions packages/compas/src/generated/common/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export type CompasResolvedConfig = {
"shortcut": string;
"command": (string)[];
})[];

/**
* Docker container configuration.
*/
"dockerContainers": { [key: string]: {
"image": string;
"createArguments"?: string|undefined;
"runArguments"?: string|undefined;
}};
};

export type CompasCache = {
Expand Down Expand Up @@ -122,6 +131,15 @@ export type CompasResolvedConfigInput = {
"shortcut": string;
"command": (string)[];
})[]|undefined;

/**
* Docker container configuration.
*/
"dockerContainers"?: { [key: string]: {
"image": string;
"createArguments"?: string|undefined;
"runArguments"?: string|undefined;
}}|undefined;
};

export type CompasCacheInput = {
Expand Down Expand Up @@ -207,6 +225,15 @@ export type CompasConfig = {
"shortcut": string;
"command": (string)[];
})[];

/**
* Docker container configuration.
*/
"dockerContainers": { [key: string]: {
"image": string;
"createArguments"?: string|undefined;
"runArguments"?: string|undefined;
}};
};

export type CompasConfigInput = {
Expand Down Expand Up @@ -251,6 +278,15 @@ export type CompasConfigInput = {
"shortcut": string;
"command": (string)[];
})[]|undefined;

/**
* Docker container configuration.
*/
"dockerContainers"?: { [key: string]: {
"image": string;
"createArguments"?: string|undefined;
"runArguments"?: string|undefined;
}}|undefined;
};


Loading

0 comments on commit 1b18b4d

Please sign in to comment.