diff --git a/.env.example b/.env.example index 915ab3e..33c8e4b 100644 --- a/.env.example +++ b/.env.example @@ -16,20 +16,16 @@ SESSION_TTL_HOURS=12 # Profils de lancement SSH. # Chaque serveur dans storage/servers.json reference un profil via startProfile. -# Exemple: "startProfile": "GAME_1" utilise GAME_1_SSH_TARGET, GAME_1_SSH_PORT, -# GAME_1_SSH_KEY_FILE et GAME_1_START_COMMAND. +# Exemple: "startProfile": "GAME_1" utilise GAME_1_SSH_TARGET, GAME_1_SSH_PORT et GAME_1_START_COMMAND. # La cible peut etre un alias SSH, un hostname, une IP, ou user@host. # Exemples: # GAME_1_SSH_TARGET=game-server # GAME_1_SSH_PORT=2222 -# GAME_1_SSH_KEY_FILE=/home/app/.ssh/game-server-key # GAME_1_SSH_TARGET=user@192.0.2.10 GAME_1_SSH_TARGET=game-server-1 GAME_1_SSH_PORT= -GAME_1_SSH_KEY_FILE= GAME_1_START_COMMAND="bash /opt/game-server-1/start.sh" GAME_2_SSH_TARGET=game-server-2 GAME_2_SSH_PORT= -GAME_2_SSH_KEY_FILE= GAME_2_START_COMMAND="bash /opt/game-server-2/start.sh" diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 8f4828d..a3e92df 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -12,15 +12,4 @@ jobs: steps: - name: Deploy on WebApps run: | - apt-get update - apt-get install -y openssh-client - - mkdir -p ~/.ssh - cp /keys/forgejo-runner ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519 - - ssh -o StrictHostKeyChecking=no \ - -i ~/.ssh/id_ed25519 \ - -p 2911 \ - shinuwa@192.168.0.100 \ - "sudo /usr/local/bin/deploy-gameservers-control" \ No newline at end of file + sudo /usr/local/bin/deploy-gameservers-control diff --git a/.gitignore b/.gitignore index 7b5e9da..e382713 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ node_modules/ .env npm-debug.log* -storage/ +storage/groups.json +storage/launch-logs.json +storage/server-images.json +storage/server-images/ diff --git a/README.md b/README.md index 86e0454..bcbd4b2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ Variables utiles: - `SESSION_TTL_HOURS`: duree des sessions, defaut `12`. - `*_SSH_TARGET`: cible SSH du profil de lancement, alias SSH ou `user@host`. - `*_SSH_PORT`: port SSH optionnel. Vide par defaut. -- `*_SSH_KEY_FILE`: chemin optionnel vers une cle SSH privee. - `*_START_COMMAND`: commande distante executee sur la cible SSH. Pour changer le port, modifier `.env`: @@ -32,7 +31,6 @@ Exemple de lancement distant via SSH: ```env GAME_1_SSH_TARGET=user@192.0.2.10 GAME_1_SSH_PORT=2222 -GAME_1_SSH_KEY_FILE=/home/app/.ssh/game-server-key GAME_1_START_COMMAND="bash /opt/game-server-1/start.sh" ``` diff --git a/src/services/serverLauncher.js b/src/services/serverLauncher.js index 787be41..5e38032 100644 --- a/src/services/serverLauncher.js +++ b/src/services/serverLauncher.js @@ -20,7 +20,6 @@ async function launchServer(server) { const target = process.env[`${profile}_SSH_TARGET`]; const port = process.env[`${profile}_SSH_PORT`]; - const keyFile = process.env[`${profile}_SSH_KEY_FILE`]; const command = process.env[`${profile}_START_COMMAND`]; if (!target || !command) { @@ -29,7 +28,11 @@ async function launchServer(server) { throw error; } - const args = buildSshArgs({ target, port, keyFile, command }); + const args = []; + if (port) { + args.push("-p", port); + } + args.push(target, command); return execFileAsync("ssh", args, { timeout: 60_000, @@ -37,21 +40,9 @@ async function launchServer(server) { }); } -function buildSshArgs({ target, port, keyFile, command }) { - const args = []; - if (port) { - args.push("-p", port); - } - if (keyFile) { - args.push("-i", keyFile); - } - args.push(target, command); - return args; -} - function getStartProfile(server) { if (server.startProfile) return server.startProfile; return ""; } -export { buildSshArgs, getStartProfile, launchServer }; +export { getStartProfile, launchServer }; diff --git a/test/serverLauncher.test.js b/test/serverLauncher.test.js deleted file mode 100644 index 585732f..0000000 --- a/test/serverLauncher.test.js +++ /dev/null @@ -1,34 +0,0 @@ -import assert from "node:assert/strict"; -import test from "node:test"; -import { buildSshArgs } from "../src/services/serverLauncher.js"; - -test("builds ssh args with optional port and key file", () => { - assert.deepEqual( - buildSshArgs({ - target: "user@192.0.2.10", - port: "2222", - keyFile: "/home/app/.ssh/game-key", - command: "bash /opt/game/start.sh", - }), - [ - "-p", - "2222", - "-i", - "/home/app/.ssh/game-key", - "user@192.0.2.10", - "bash /opt/game/start.sh", - ] - ); -}); - -test("builds ssh args without optional port and key file", () => { - assert.deepEqual( - buildSshArgs({ - target: "game-server", - port: "", - keyFile: "", - command: "bash /opt/game/start.sh", - }), - ["game-server", "bash /opt/game/start.sh"] - ); -});