dockersetup.py: add connectivity check

It's easy to get the proxy settings wrong and not realise until you've
got quite a long way into the process of setting things up. Thus, add a
check where we actually try to fetch various things within the container
environment and fail reasonably early if things aren't working.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-08-01 16:34:17 +12:00
parent a0763f6da8
commit b5ba406a07
3 changed files with 48 additions and 0 deletions

View File

@ -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 \

35
docker/connectivity_check.sh Executable file
View File

@ -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

View File

@ -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)