Compare commits
4 commits
50eaace713
...
9570f18efa
| Author | SHA1 | Date | |
|---|---|---|---|
| 9570f18efa | |||
| 3947df9fbb | |||
| f3a8a8d757 | |||
| 225ad758ab |
6 changed files with 69 additions and 12 deletions
|
|
@ -16,16 +16,20 @@ 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 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.
|
||||
# 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"
|
||||
|
|
|
|||
|
|
@ -12,4 +12,15 @@ jobs:
|
|||
steps:
|
||||
- name: Deploy on WebApps
|
||||
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
5
.gitignore
vendored
|
|
@ -1,7 +1,4 @@
|
|||
node_modules/
|
||||
.env
|
||||
npm-debug.log*
|
||||
storage/groups.json
|
||||
storage/launch-logs.json
|
||||
storage/server-images.json
|
||||
storage/server-images/
|
||||
storage/
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ 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`:
|
||||
|
|
@ -31,6 +32,7 @@ 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"
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ 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) {
|
||||
|
|
@ -28,11 +29,7 @@ async function launchServer(server) {
|
|||
throw error;
|
||||
}
|
||||
|
||||
const args = [];
|
||||
if (port) {
|
||||
args.push("-p", port);
|
||||
}
|
||||
args.push(target, command);
|
||||
const args = buildSshArgs({ target, port, keyFile, command });
|
||||
|
||||
return execFileAsync("ssh", args, {
|
||||
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) {
|
||||
if (server.startProfile) return server.startProfile;
|
||||
return "";
|
||||
}
|
||||
|
||||
export { getStartProfile, launchServer };
|
||||
export { buildSshArgs, getStartProfile, launchServer };
|
||||
|
|
|
|||
34
test/serverLauncher.test.js
Normal file
34
test/serverLauncher.test.js
Normal 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"]
|
||||
);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue