mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-09-12 11:40:27 +05:00
chore: automate git worktree setup (shared node_modules, per-worktree dev port)
This commit is contained in:
parent
d675db10bb
commit
8be1e68fe1
19
.claude/settings.json
Normal file
19
.claude/settings.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"worktree": {
|
||||
"baseRef": "fresh",
|
||||
"symlinkDirectories": ["node_modules"]
|
||||
},
|
||||
"hooks": {
|
||||
"PostToolUse": [
|
||||
{
|
||||
"matcher": "EnterWorktree",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "\"$CLAUDE_PROJECT_DIR/scripts/assign-worktree-port.sh\""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
2
.worktreeinclude
Normal file
2
.worktreeinclude
Normal file
@ -0,0 +1,2 @@
|
||||
.env
|
||||
.env.local
|
||||
22
scripts/assign-worktree-port.sh
Executable file
22
scripts/assign-worktree-port.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PAYLOAD=$(cat)
|
||||
WORKTREE_PATH=$(echo "$PAYLOAD" | jq -r '.tool_response.worktreePath // empty')
|
||||
|
||||
if [ -z "$WORKTREE_PATH" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ENV_FILE="$WORKTREE_PATH/apps/dokploy/.env"
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
FREE_PORT=$(node "$CLAUDE_PROJECT_DIR/scripts/find-free-port.mjs")
|
||||
|
||||
sed -i.bak "s/^PORT=.*/PORT=$FREE_PORT/" "$ENV_FILE"
|
||||
sed -i.bak -E "s#^(BETTER_AUTH_URL=https?://[^:/]+):[0-9]+#\1:$FREE_PORT#" "$ENV_FILE"
|
||||
rm -f "$ENV_FILE.bak"
|
||||
|
||||
echo "Worktree $WORKTREE_PATH -> dokploy dev PORT=$FREE_PORT"
|
||||
23
scripts/find-free-port.mjs
Normal file
23
scripts/find-free-port.mjs
Normal file
@ -0,0 +1,23 @@
|
||||
import { createServer } from "node:net";
|
||||
|
||||
function isFree(port) {
|
||||
return new Promise((resolve) => {
|
||||
const server = createServer();
|
||||
server.once("error", () => resolve(false));
|
||||
server.listen(port, "0.0.0.0", () => {
|
||||
server.close(() => resolve(true));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function findFreePort(start) {
|
||||
let port = start;
|
||||
while (!(await isFree(port))) {
|
||||
port++;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
const start = Number.parseInt(process.argv[2] || process.env.PORT || "3000", 10);
|
||||
const port = await findFreePort(start);
|
||||
process.stdout.write(String(port));
|
||||
Loading…
Reference in New Issue
Block a user