summaryrefslogtreecommitdiff
path: root/apps/docker/docker-cmd.ts
diff options
context:
space:
mode:
authorYehonal <yehonal.azeroth@gmail.com>2021-04-22 09:57:05 +0200
committerGitHub <noreply@github.com>2021-04-22 09:57:05 +0200
commit380f406248bdc1f15227a7b2f8a75b4bf922f730 (patch)
tree497bb589f7bd80073ea755f14e33505ff572353b /apps/docker/docker-cmd.ts
parent4a8faafaff2753349ea15aa602cc3816f4e42de6 (diff)
Feat(Docker/bash): docker-compose system rework (#4488)
## ⚠️ATTENTION! ⚠️ Upgrading procedure: **Database:** After this PR will be merged you need to backup your DB first (you can use the db-assembler or any mysql client to generate the dump) and restore it after. The reason is that we use now docker named volumes instead of binded ones to improve performance. **Conf & client data**: if you use the default configuration, both the etc and the data folder are now available inside the **/env/docker**. Finally, you can cleanup the /docker folder previously used by our system. ## Changes Proposed: This PR will implement the [devcontainer ](https://code.visualstudio.com/docs/remote/containers) feature for VSCode. Allowing us to develop and debug directly within the container in the same way on all OSes. * Implemented support for vscode dev-container feature by remote-extension suite * Docker performance optimizations for MacOS and non-linux hosts * Bash system improvements * Implemented first command using Deno runtime environment (typescript) and [commander.js] * Implemented wait mechanism for db_assembler * Implemented db migration command * possibility to run the authserver and worldserver with GDB using the integrated simple-restarter * Implemented docker multi-stage mechanism to use one single Dockerfile for all the services * client-data downloader now creates a placeholder to avoid downloading the same version of data files multiple times * deployment of pre-compiled docker images on [docker hub](https://hub.docker.com/u/acore), you can test them [here](https://github.com/azerothcore/acore-docker)
Diffstat (limited to 'apps/docker/docker-cmd.ts')
-rw-r--r--apps/docker/docker-cmd.ts174
1 files changed, 174 insertions, 0 deletions
diff --git a/apps/docker/docker-cmd.ts b/apps/docker/docker-cmd.ts
new file mode 100644
index 0000000000..f666ca0944
--- /dev/null
+++ b/apps/docker/docker-cmd.ts
@@ -0,0 +1,174 @@
+import { Command } from "https://cdn.depjs.com/cmd/mod.ts";
+import * as ink from "https://deno.land/x/ink/mod.ts";
+import {
+ Input,
+ Select,
+} from "https://deno.land/x/cliffy@v0.18.2/prompt/mod.ts";
+
+const program = new Command();
+
+program.name("acore.sh docker")
+ .description("Shell scripts for docker")
+ .version("1.0.0");
+
+shellCommandFactory(
+ "start:app",
+ "Startup the authserver and worldserver apps",
+ "docker-compose --profile app up",
+);
+
+shellCommandFactory(
+ "start:app:d",
+ "Startup the authserver and worldserver apps in detached mode",
+ "docker-compose --profile app up -d",
+);
+
+shellCommandFactory(
+ "start:dev",
+ "Startup the dev server",
+ "docker-compose --profile dev up",
+);
+
+shellCommandFactory(
+ "build",
+ "Build the authserver and worldserver",
+ `docker-compose run --rm ac-dev-server bash bin/acore-docker-build`,
+);
+
+shellCommandFactory(
+ "build:clean",
+ "Clean build data",
+ `docker-compose run --rm ac-dev-server bash rm -rf var/build`,
+);
+
+shellCommandFactory(
+ "client-data",
+ "Download client data inside the ac-data volume",
+ "docker-compose run --rm ac-dev-server bash acore.sh client-data",
+);
+
+shellCommandFactory(
+ "db-import",
+ "Create and upgrade the database with latest updates",
+ "docker-compose run --rm ac-dev-server bash acore.sh db-assembler import-all",
+);
+
+shellCommandFactory(
+ "dashboard [args...]",
+ "Execute acore dashboard within a running ac-dev-server",
+ "docker-compose exec ac-dev-server bash acore.sh",
+);
+
+program.command("attach [service]")
+ .description("attach to a service")
+ .action(async (service: string | undefined) => {
+ const { run } = Deno;
+
+ let command = `docker-compose ps`;
+
+ if (service) {
+ command = `${command} ${service}`;
+ }
+
+ console.log(ink.colorize(`<green>>>>>> Running: ${command}</green>`));
+
+ let cmd = command.split(" ");
+ const res = Deno.run({
+ cmd,
+ cwd: process.cwd(),
+ stdout: "piped",
+ stderr: "piped",
+ });
+
+ const output = await res.output(); // "piped" must be set
+
+ let services = new TextDecoder().decode(output).split("\n");
+
+ services.pop();
+ services = services.slice(2);
+
+ res.close(); // Don't forget to close it
+
+ let selService: string;
+ if (services.length > 1) {
+ selService = await Select.prompt({
+ message: `Select a service`,
+ options: services,
+ });
+ } else {
+ selService = services[0];
+ }
+
+ command = `docker attach ${selService.split(" ")[0]}`;
+
+ console.log(ink.colorize(`<green>>>>>> Running: ${command}</green>`));
+
+ console.log(
+ ink.colorize(
+ "<yellow>NOTE: you can detach from a container and leave it running using the CTRL-p CTRL-q key sequence.</yellow>",
+ ),
+ );
+
+ cmd = command.split(" ");
+
+ const shellCmd = run({
+ cmd,
+ cwd: process.cwd(),
+ });
+
+ await shellCmd.status();
+
+ shellCmd.close();
+ });
+
+program.command("quit").description("Close docker command").action(()=> {
+ process.exit(0)
+})
+
+// Handle it however you like
+// e.g. display usage
+while (true) {
+ if (Deno.args.length === 0) {
+ program.outputHelp();
+ const command = await Input.prompt({
+ message: "Enter the command:",
+ });
+ await program.parseAsync(command.split(" "));
+ } else {
+ await program.parseAsync(Deno.args);
+ process.exit(0)
+ }
+}
+
+
+
+function shellCommandFactory(
+ name: string,
+ description: string,
+ command: string,
+): Command {
+ return program.command(name)
+ .description(
+ `${description}. Command: \n"${ink.colorize(`<green>${command}</green>`)}"\n`,
+ )
+ .action(async (args: any[] | undefined) => {
+ const { run } = Deno;
+
+ console.log(ink.colorize(`<green>>>>>> Running: ${command}</green>`));
+
+ const cmd = command.split(" ");
+
+ if (Array.isArray(args)) {
+ cmd.push(...args);
+ }
+
+ const shellCmd = run({
+ cmd,
+ cwd: process.cwd(),
+ });
+
+ await shellCmd.status();
+
+ shellCmd.close();
+ });
+}