From 0af532f87ee26f6db649caecb410fe38bcb691bc Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 25 Jul 2024 00:51:15 -0600 Subject: [PATCH 1/2] refactor(directories): add 600 permissions to SSH_PATH #262 --- server/setup/config-paths.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/setup/config-paths.ts b/server/setup/config-paths.ts index 2b2c262b..f609bc6c 100644 --- a/server/setup/config-paths.ts +++ b/server/setup/config-paths.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync } from "node:fs"; +import { chmodSync, existsSync, mkdirSync } from "node:fs"; import { APPLICATIONS_PATH, BASE_PATH, @@ -32,6 +32,9 @@ export const setupDirectories = () => { for (const dir of directories) { try { createDirectoryIfNotExist(dir); + if (dir === SSH_PATH) { + chmodSync(SSH_PATH, "600"); + } } catch (error) { console.log(error, " On path: ", dir); } From 9e47103131929e553528e817a2196d0ed69384ba Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 25 Jul 2024 01:48:52 -0600 Subject: [PATCH 2/2] refactor(script): make ipv4 first and format the url when is ipv6 #258 --- docker/prod.sh | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/docker/prod.sh b/docker/prod.sh index 4dc23da2..2b833340 100644 --- a/docker/prod.sh +++ b/docker/prod.sh @@ -30,11 +30,6 @@ if ss -tulnp | grep ':443 ' >/dev/null; then exit 1 fi - - - - - command_exists() { command -v "$@" > /dev/null 2>&1 } @@ -46,7 +41,25 @@ else fi docker swarm leave --force 2>/dev/null -docker swarm init; + +get_ip() { + # Try to get IPv4 + local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null) + + if [ -n "$ipv4" ]; then + echo "$ipv4" + else + # Try to get IPv6 + local ipv6=$(curl -6s https://ifconfig.io 2>/dev/null) + if [ -n "$ipv6" ]; then + echo "$ipv6" + fi + fi +} + +advertise_addr=$(get_ip) + +docker swarm init --advertise-addr $advertise_addr echo "Swarm initialized" @@ -71,19 +84,28 @@ docker service create \ --publish published=3000,target=3000,mode=host \ --update-parallelism 1 \ --update-order stop-first \ + --constraint 'node.role == manager' \ dokploy/dokploy:latest - -public_ip=$(hostname -I | awk '{print $1}') - GREEN="\033[0;32m" YELLOW="\033[1;33m" BLUE="\033[0;34m" NC="\033[0m" # No Color +format_ip_for_url() { + local ip="$1" + if echo "$ip" | grep -q ':'; then + # IPv6 + echo "[${ip}]" + else + # IPv4 + echo "${ip}" + fi +} +formatted_addr=$(format_ip_for_url "$advertise_addr") echo "" printf "${GREEN}Congratulations, Dokploy is installed!${NC}\n" printf "${BLUE}Wait 15 seconds for the server to start${NC}\n" -printf "${YELLOW}Please go to http://${public_ip}:3000${NC}\n\n" +printf "${YELLOW}Please go to http://${formatted_addr}:3000${NC}\n\n" echo ""