develop #2

Merged
shinuwa merged 3 commits from develop into main 2026-06-12 19:31:57 +00:00
6 changed files with 69 additions and 12 deletions

View file

@ -16,16 +16,20 @@ SESSION_TTL_HOURS=12
# Profils de lancement SSH. # Profils de lancement SSH.
# Chaque serveur dans storage/servers.json reference un profil via startProfile. # Chaque serveur dans storage/servers.json reference un profil via startProfile.
# Exemple: "startProfile": "GAME_1" utilise GAME_1_SSH_TARGET, GAME_1_SSH_PORT et GAME_1_START_COMMAND. # Exemple: "startProfile": "GAME_1" utilise GAME_1_SSH_TARGET, GAME_1_SSH_PORT,
# GAME_1_SSH_KEY_FILE et GAME_1_START_COMMAND.
# La cible peut etre un alias SSH, un hostname, une IP, ou user@host. # La cible peut etre un alias SSH, un hostname, une IP, ou user@host.
# Exemples: # Exemples:
# GAME_1_SSH_TARGET=game-server # GAME_1_SSH_TARGET=game-server
# GAME_1_SSH_PORT=2222 # 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=user@192.0.2.10
GAME_1_SSH_TARGET=game-server-1 GAME_1_SSH_TARGET=game-server-1
GAME_1_SSH_PORT= GAME_1_SSH_PORT=
GAME_1_SSH_KEY_FILE=
GAME_1_START_COMMAND="bash /opt/game-server-1/start.sh" GAME_1_START_COMMAND="bash /opt/game-server-1/start.sh"
GAME_2_SSH_TARGET=game-server-2 GAME_2_SSH_TARGET=game-server-2
GAME_2_SSH_PORT= GAME_2_SSH_PORT=
GAME_2_SSH_KEY_FILE=
GAME_2_START_COMMAND="bash /opt/game-server-2/start.sh" GAME_2_START_COMMAND="bash /opt/game-server-2/start.sh"

View file

@ -12,4 +12,15 @@ jobs:
steps: steps:
- name: Deploy on WebApps - name: Deploy on WebApps
run: | run: |
sudo /usr/local/bin/deploy-gameservers-control 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"

5
.gitignore vendored
View file

@ -1,7 +1,4 @@
node_modules/ node_modules/
.env .env
npm-debug.log* npm-debug.log*
storage/groups.json storage/
storage/launch-logs.json
storage/server-images.json
storage/server-images/

View file

@ -18,6 +18,7 @@ Variables utiles:
- `SESSION_TTL_HOURS`: duree des sessions, defaut `12`. - `SESSION_TTL_HOURS`: duree des sessions, defaut `12`.
- `*_SSH_TARGET`: cible SSH du profil de lancement, alias SSH ou `user@host`. - `*_SSH_TARGET`: cible SSH du profil de lancement, alias SSH ou `user@host`.
- `*_SSH_PORT`: port SSH optionnel. Vide par defaut. - `*_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. - `*_START_COMMAND`: commande distante executee sur la cible SSH.
Pour changer le port, modifier `.env`: Pour changer le port, modifier `.env`:
@ -31,6 +32,7 @@ Exemple de lancement distant via SSH:
```env ```env
GAME_1_SSH_TARGET=user@192.0.2.10 GAME_1_SSH_TARGET=user@192.0.2.10
GAME_1_SSH_PORT=2222 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" GAME_1_START_COMMAND="bash /opt/game-server-1/start.sh"
``` ```

View file

@ -20,6 +20,7 @@ async function launchServer(server) {
const target = process.env[`${profile}_SSH_TARGET`]; const target = process.env[`${profile}_SSH_TARGET`];
const port = process.env[`${profile}_SSH_PORT`]; const port = process.env[`${profile}_SSH_PORT`];
const keyFile = process.env[`${profile}_SSH_KEY_FILE`];
const command = process.env[`${profile}_START_COMMAND`]; const command = process.env[`${profile}_START_COMMAND`];
if (!target || !command) { if (!target || !command) {
@ -28,11 +29,7 @@ async function launchServer(server) {
throw error; throw error;
} }
const args = []; const args = buildSshArgs({ target, port, keyFile, command });
if (port) {
args.push("-p", port);
}
args.push(target, command);
return execFileAsync("ssh", args, { return execFileAsync("ssh", args, {
timeout: 60_000, timeout: 60_000,
@ -40,9 +37,21 @@ 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) { function getStartProfile(server) {
if (server.startProfile) return server.startProfile; if (server.startProfile) return server.startProfile;
return ""; return "";
} }
export { getStartProfile, launchServer }; export { buildSshArgs, getStartProfile, launchServer };

View file

@ -0,0 +1,34 @@
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"]
);
});