Skip to content

Commit

Permalink
Merge pull request #16 from Dokploy/15-failed-to-initialize-docker-sw…
Browse files Browse the repository at this point in the history
…arm-on-ubuntu-2404-during-dokploy-installation

refactor: add fallback getIp
  • Loading branch information
Siumauricio authored Dec 29, 2024
2 parents 74ca743 + b2dac5e commit 414a617
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 27 deletions.
47 changes: 38 additions & 9 deletions apps/website/public/canary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,50 @@ install_dokploy() {
docker swarm leave --force 2>/dev/null

get_ip() {
# Try to get IPv4
local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null)
local ip=""

# Try IPv4 first
# First attempt: ifconfig.io
ip=$(curl -4s --connect-timeout 5 https://ifconfig.io 2>/dev/null)

# Second attempt: icanhazip.com
if [ -z "$ip" ]; then
ip=$(curl -4s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
fi

# Third attempt: ipecho.net
if [ -z "$ip" ]; then
ip=$(curl -4s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
fi

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"
# If no IPv4, try IPv6
if [ -z "$ip" ]; then
# Try IPv6 with ifconfig.io
ip=$(curl -6s --connect-timeout 5 https://ifconfig.io 2>/dev/null)

# Try IPv6 with icanhazip.com
if [ -z "$ip" ]; then
ip=$(curl -6s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
fi

# Try IPv6 with ipecho.net
if [ -z "$ip" ]; then
ip=$(curl -6s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
fi
fi

if [ -z "$ip" ]; then
echo "Error: Could not determine server IP address automatically (neither IPv4 nor IPv6)." >&2
echo "Please set the ADVERTISE_ADDR environment variable manually." >&2
echo "Example: export ADVERTISE_ADDR=<your-server-ip>" >&2
exit 1
fi

echo "$ip"
}

advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}"
echo "Using advertise address: $advertise_addr"

docker swarm init --advertise-addr $advertise_addr

Expand Down
47 changes: 38 additions & 9 deletions apps/website/public/feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,50 @@ install_dokploy() {
docker swarm leave --force 2>/dev/null

get_ip() {
# Try to get IPv4
local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null)
local ip=""

# Try IPv4 first
# First attempt: ifconfig.io
ip=$(curl -4s --connect-timeout 5 https://ifconfig.io 2>/dev/null)

# Second attempt: icanhazip.com
if [ -z "$ip" ]; then
ip=$(curl -4s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
fi

# Third attempt: ipecho.net
if [ -z "$ip" ]; then
ip=$(curl -4s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
fi

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"
# If no IPv4, try IPv6
if [ -z "$ip" ]; then
# Try IPv6 with ifconfig.io
ip=$(curl -6s --connect-timeout 5 https://ifconfig.io 2>/dev/null)

# Try IPv6 with icanhazip.com
if [ -z "$ip" ]; then
ip=$(curl -6s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
fi

# Try IPv6 with ipecho.net
if [ -z "$ip" ]; then
ip=$(curl -6s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
fi
fi

if [ -z "$ip" ]; then
echo "Error: Could not determine server IP address automatically (neither IPv4 nor IPv6)." >&2
echo "Please set the ADVERTISE_ADDR environment variable manually." >&2
echo "Example: export ADVERTISE_ADDR=<your-server-ip>" >&2
exit 1
fi

echo "$ip"
}

advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}"
echo "Using advertise address: $advertise_addr"

docker swarm init --advertise-addr $advertise_addr

Expand Down
47 changes: 38 additions & 9 deletions apps/website/public/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,50 @@ install_dokploy() {
docker swarm leave --force 2>/dev/null

get_ip() {
# Try to get IPv4
local ipv4=$(curl -4s https://ifconfig.io 2>/dev/null)
local ip=""

# Try IPv4 first
# First attempt: ifconfig.io
ip=$(curl -4s --connect-timeout 5 https://ifconfig.io 2>/dev/null)

# Second attempt: icanhazip.com
if [ -z "$ip" ]; then
ip=$(curl -4s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
fi

# Third attempt: ipecho.net
if [ -z "$ip" ]; then
ip=$(curl -4s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
fi

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"
# If no IPv4, try IPv6
if [ -z "$ip" ]; then
# Try IPv6 with ifconfig.io
ip=$(curl -6s --connect-timeout 5 https://ifconfig.io 2>/dev/null)

# Try IPv6 with icanhazip.com
if [ -z "$ip" ]; then
ip=$(curl -6s --connect-timeout 5 https://icanhazip.com 2>/dev/null)
fi

# Try IPv6 with ipecho.net
if [ -z "$ip" ]; then
ip=$(curl -6s --connect-timeout 5 https://ipecho.net/plain 2>/dev/null)
fi
fi

if [ -z "$ip" ]; then
echo "Error: Could not determine server IP address automatically (neither IPv4 nor IPv6)." >&2
echo "Please set the ADVERTISE_ADDR environment variable manually." >&2
echo "Example: export ADVERTISE_ADDR=<your-server-ip>" >&2
exit 1
fi

echo "$ip"
}

advertise_addr="${ADVERTISE_ADDR:-$(get_ip)}"
echo "Using advertise address: $advertise_addr"

docker swarm init --advertise-addr $advertise_addr

Expand Down

0 comments on commit 414a617

Please sign in to comment.