update get_local_addr in macos.
This commit is contained in:
parent
f19d76eb39
commit
d2080b95b3
|
@ -26,7 +26,7 @@ ENV SOURCE_URL= \
|
||||||
KEEP_SOURCE_FILE=yes \
|
KEEP_SOURCE_FILE=yes \
|
||||||
SERVER_CONTAINERIZED=
|
SERVER_CONTAINERIZED=
|
||||||
|
|
||||||
COPY check.sh parse.sh run.sh /app/bin/
|
COPY parse.sh run.sh /app/bin/
|
||||||
|
|
||||||
COPY --from=hub.cstcloud.cn/scalebox/base /usr/local/sbin/ /usr/local/sbin/
|
COPY --from=hub.cstcloud.cn/scalebox/base /usr/local/sbin/ /usr/local/sbin/
|
||||||
RUN mkdir -p /work/.scalebox /app/bin && echo "PATH=/app/bin:\${PATH}" >> /root/.bashrc
|
RUN mkdir -p /work/.scalebox /app/bin && echo "PATH=/app/bin:\${PATH}" >> /root/.bashrc
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -19,7 +20,10 @@ func GetLocalIP() string {
|
||||||
var cmd string
|
var cmd string
|
||||||
if localIPIndexStr == "" {
|
if localIPIndexStr == "" {
|
||||||
cmd = "hostname -i"
|
cmd = "hostname -i"
|
||||||
} else {
|
} else if runtime.GOOS == "darwin" { // macos
|
||||||
|
// 172.*.*.* are used for out-of-band Network/container network
|
||||||
|
cmd = `ifconfig|grep "inet "|grep -v 127.0.0.1|grep -v "inet 172."|head -1|cut -d ' ' -f 2`
|
||||||
|
} else { // linux
|
||||||
cmd = fmt.Sprintf("hostname -I | awk '{print $%s}'", localIPIndexStr)
|
cmd = fmt.Sprintf("hostname -I | awk '{print $%s}'", localIPIndexStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ ifeq ($(origin LOCAL_ADDR), undefined)
|
||||||
LOCAL_ADDR := $$(hostname -I| cut -d ' ' -f ${LOCAL_IP_INDEX})
|
LOCAL_ADDR := $$(hostname -I| cut -d ' ' -f ${LOCAL_IP_INDEX})
|
||||||
endif
|
endif
|
||||||
else ifeq ($(UNAME), Darwin)
|
else ifeq ($(UNAME), Darwin)
|
||||||
LOCAL_ADDR := $$(ifconfig|grep "inet "|grep -v 127.0.0.1|head -1|cut -d ' ' -f 2)
|
LOCAL_ADDR := $$(ifconfig|grep "inet "|grep -v 127.0.0.1|grep -v "inet 172."|head -1|cut -d ' ' -f 2)
|
||||||
else
|
else
|
||||||
$(info This is neither a Linux nor a macOS system)
|
$(info This is neither a Linux nor a macOS system)
|
||||||
endif
|
endif
|
||||||
|
|
Loading…
Reference in New Issue