diff --git a/Dockerfile b/Dockerfile index b86f000..a719ae0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,7 @@ COPY docker/settings.py /opt/layerindex/settings.py COPY docker/refreshlayers.sh /opt/refreshlayers.sh COPY docker/updatelayers.sh /opt/updatelayers.sh COPY docker/migrate.sh /opt/migrate.sh +COPY docker/connectivity_check.sh /opt/connectivity_check.sh RUN mkdir /opt/workdir \ && adduser --system --uid=500 layers \ diff --git a/docker/connectivity_check.sh b/docker/connectivity_check.sh new file mode 100755 index 0000000..59b26b8 --- /dev/null +++ b/docker/connectivity_check.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# Run a few connectivity checks +echo "Checking external connectivity..." + +CCTEMP=`mktemp -d` +cd $CCTEMP || exit 1 + +cleanup_tmp() { + cd /tmp + rm -rf $CCTEMP +} + +HTTP_TEST_URL="http://example.com" +if ! wget -q $HTTP_TEST_URL ; then + echo "ERROR: failed to fetch $HTTP_TEST_URL" + cleanup_tmp + exit 1 +fi + +HTTPS_TEST_URL="https://google.com" +if ! wget -q $HTTPS_TEST_URL ; then + echo "ERROR: failed to fetch $HTTPS_TEST_URL" + cleanup_tmp + exit 1 +fi + +GIT_TEST_REPO="git://git.yoctoproject.org/meta-layerindex-test" +if ! git clone -q $GIT_TEST_REPO ; then + echo "ERROR: failed to clone $GIT_TEST_REPO" + cleanup_tmp + exit 1 +fi + +cleanup_tmp diff --git a/dockersetup.py b/dockersetup.py index 37f3f17..299d3f9 100755 --- a/dockersetup.py +++ b/dockersetup.py @@ -56,6 +56,7 @@ def get_args(): parser.add_argument('--letsencrypt', action="store_true", default=False, help='Use Let\'s Encrypt for HTTPS') parser.add_argument('--no-migrate', action="store_true", default=False, help='Skip running database migrations') parser.add_argument('--no-admin-user', action="store_true", default=False, help='Skip adding admin user') + parser.add_argument('--no-connectivity', action="store_true", default=False, help='Skip checking external network connectivity') args = parser.parse_args() @@ -488,6 +489,13 @@ def edit_options_file(project_name): f.write('project_name=%s\n' % project_name) +def check_connectivity(): + return_code = subprocess.call(['docker-compose', 'run', '--rm', 'layersapp', '/opt/connectivity_check.sh'], shell=False) + if return_code != 0: + print("Connectivity check failed - if you are behind a proxy, please check that you have correctly specified the proxy settings on the command line (see --help for details)") + sys.exit(1) + + def generatepasswords(passwordlength): return ''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@%^&*-_+') for i in range(passwordlength)]) @@ -648,6 +656,10 @@ if return_code != 0: print("docker-compose up failed") sys.exit(1) +if not (args.update or args.no_connectivity): + ## Run connectivity check + check_connectivity() + # Get real project name (if only there were a reasonable way to do this... ugh) real_project_name = '' output = subprocess.check_output(['docker-compose', 'ps', '-q'], shell=False)