Compare commits

..

No commits in common. "9570f18efadd4647dad2e4ff39b3301df0ac70fb" and "50eaace71369a428c07498282bf539326e22d337" have entirely different histories.

6 changed files with 12 additions and 69 deletions

View file

@ -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"

View file

@ -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"
sudo /usr/local/bin/deploy-gameservers-control

5
.gitignore vendored
View file

@ -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/

View file

@ -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"
```

View file

@ -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 };

View file

@ -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"]
);
});