mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-18 03:02:56 +00:00
chore: automate git worktree setup (shared node_modules, per-worktree dev port)
This commit is contained in:
@@ -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\""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.env
|
||||||
|
.env.local
|
||||||
Executable
+22
@@ -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"
|
||||||
@@ -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));
|
||||||
Reference in New Issue
Block a user