Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for internet connection on make up #45

Open
ecotechie opened this issue Mar 15, 2019 · 1 comment
Open

Check for internet connection on make up #45

ecotechie opened this issue Mar 15, 2019 · 1 comment

Comments

@ecotechie
Copy link

ecotechie commented Mar 15, 2019

Is there a way to add a check on the docker.mk file to see if the there is an internet connection and not do a docker-compose pull if not connected?

I sometimes run a dev environment without internet (airplane) and this command fails. I do get around it by running docker-compose up -d, but was wondering...

@BobbyBabes
Copy link

I don't know if you're still interested in this. I took the check below from one of my Bash scripts and changed it to fit. You could stick it in a Bash script and alias it.
Variable packetLoss will contain the percentage packet loss of the ping command. For example 0 when 0% packet loss. From this example ping -qc 10 wordpress.com output:

PING wordpress.com (192.0.78.9) 56(84) bytes of data. --- wordpress.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 21ms rtt min/avg/max/mdev = 42.733/43.114/43.764/0.334 ms

PING wordpress.com (192.0.78.9) 56(84) bytes of data. --- wordpress.com ping statistics --- 10 packets transmitted, 0 received, 100% packet loss, time 117ms
#!/bin/bash

#-- Variable 'packetLoss' must be null (or > 100) before pinging. Because '0' means no packet loss.
packetLoss=
acceptablePacketLoss=0
packetLoss=$(echo $(ping -qc 10 wordpress.com) | sed -r 's|\s*.*,\s*([[:digit:]]*)% packet loss,.*ms$|\1|')
if [ "$packetLoss" -le "$acceptablePacketLoss" ]; then
  make up #-- docker-compose up -d
  return 0
else
  echo -e "Packet loss is $packetLoss%\nAcceptable packet loss is $acceptablePacketLoss%\nSkipping!"
  return 1
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants