Skip to content

Commit

Permalink
✨(script:dev) allow to set (or guess) local IP address
Browse files Browse the repository at this point in the history
In the bin/dev script, instead of listing all interfaces with the
hostname -I command (that is not compatible with at least MacOSX) and
take the first IP address as the OPENSHIFT_DOMAIN, we now test all IP
addresses of all interfaces and set the first one with access to the
internet has the OPENSHIFT_DOMAIN.

Plus, we now allow to set the OPENSHIFT_DOMAIN IP address as a script
argument, hence, MacOSX users can now use the bin/dev script as follow:

bin/dev 192.168.1.10

(with 192.168.1.10 as their local IP address that has access to the
internet)
  • Loading branch information
jmaupetit committed Aug 29, 2018
1 parent faefbef commit a725f74
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ $ oc login --insecure-skip-tls-verify=true -u developer -p developer "${K8S_AUTH
```

As we are gentle people, we also provide a shortcut to automate running a new
cluster and login to it (GNU/Linux only for now):
cluster and login to it:

```
$ bin/dev
```bash
# Substitute 192.168.1.10 with your local IP that has access to the internet
$ bin/dev 192.168.1.10
```

Please, note that **you do not need to run** `bin/dev` if you have already
Expand Down
45 changes: 43 additions & 2 deletions bin/dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#
# Arnold's dev script
#
# Usage: bin/dev [LOCAL_IP]
#
# LOCAL_IP: the IP address of your machine that is allowed to access the
# internet (optional). If not provided, the script will try to guess
# it from all IP addresses assigned to every interfaces
# (experimental).
#
# Before running this script, please make sure that your system met the
# following requirements:
#
Expand All @@ -19,22 +26,56 @@
#
set -eo pipefail

# _get_local_ip: try to get a local IP that has access to the internet
function _get_local_ip() {

# Print debug info in a subshell's stderr
(>&2 echo "Looking for a network interface with internet access...")

# List all interface all IP addressses
for ip in $(hostname -I); do

(>&2 echo -n "==> ${ip} ... ")

# Ping google from this interface to check internet access
ping -I "${ip}" -W 1 -c 1 www.google.com &> /dev/null

if [ $? -eq 0 ]; then
echo "${ip}"
(>&2 echo "yes")
return 0
fi

(>&2 echo "no")
done

(>&2 \
echo "Error: cannot find an interface that has access to the internet." \
"Please provide your local IP address as a script argument:" \
"bin/dev 192.168.1.100" \
)
exit 1
}

# Default dev credentials
OC_USER="developer"
OC_PASSWORD="developer"

# Local IP address that will be used for the local OpenShift instance
LOCAL_IP=${1:-$(_get_local_ip)}

# _start_cluster: starts an OpenShift minimal cluster
function _start_cluster() {

OPENSHIFT_DOMAIN=$(hostname -I | awk '{print $1}')
echo "Local IP address used for OpenShift: ${LOCAL_IP}"

OPENSHIFT_DOMAIN="${LOCAL_IP}"
K8S_AUTH_HOST="https://${OPENSHIFT_DOMAIN}:8443"

oc cluster up --server-loglevel=5 --public-hostname="${OPENSHIFT_DOMAIN}"
oc login "${K8S_AUTH_HOST}" -u "${OC_USER}" -p "${OC_PASSWORD}" --insecure-skip-tls-verify=true
}


# Main entrypoint
function main() {
_start_cluster
Expand Down

0 comments on commit a725f74

Please sign in to comment.