diff --git a/docker/services/swh-web/entrypoint.sh b/docker/services/swh-web/entrypoint.sh index b8de8bb..c828f46 100755 --- a/docker/services/swh-web/entrypoint.sh +++ b/docker/services/swh-web/entrypoint.sh @@ -1,64 +1,54 @@ #!/bin/bash set -e source /srv/softwareheritage/utils/pgsql.sh setup_pgsql -# when overriding swh-web sources only -if [[ -d /src/swh-web ]] ; then - echo "Install and compile swh-web static assets" - pushd /src/swh-web - yarn install --frozen-lockfile - # execute webpack-dev-server in background - yarn start-dev& - popd -fi - source /srv/softwareheritage/utils/pyutils.sh setup_pip case "$1" in "shell") exec bash -i ;; "cron") wait-for-it swh-web:5004 -s --timeout=0 echo "Start periodic save code now refresh statuses routine (in background)" exec sh -c 'trap exit TERM INT; while :; do (date && django-admin refresh_savecodenow_statuses \ --settings=${DJANGO_SETTINGS_MODULE} 2>&1) sleep 15 & wait ${!} done' ;; *) wait_pgsql echo "Migrating db using ${DJANGO_SETTINGS_MODULE}" django-admin migrate --settings=${DJANGO_SETTINGS_MODULE} echo "Creating Django test users" SWH_WEB_SRC_DIR=$(python3 -c "import os; from swh import web; print(os.path.dirname(web.__file__))") for create_user_script in $SWH_WEB_SRC_DIR/tests/create_test_* do cat $create_user_script | python3 -m swh.web.manage shell done echo "starting the swh-web server" if [[ -d /src/swh-web ]] ; then # run django development server when overriding swh-web sources exec django-admin runserver --nostatic --settings=${DJANGO_SETTINGS_MODULE} 0.0.0.0:5004 else # run gunicorn workers as in production otherwise exec gunicorn --bind 0.0.0.0:5004 \ --threads 2 \ --workers 2 \ --timeout 3600 \ --access-logfile '-' \ --config 'python:swh.web.gunicorn_config' \ 'django.core.wsgi:get_wsgi_application()' fi esac diff --git a/docker/utils/pyutils.sh b/docker/utils/pyutils.sh index bb3237b..f5c226a 100755 --- a/docker/utils/pyutils.sh +++ b/docker/utils/pyutils.sh @@ -1,28 +1,42 @@ #!/bin/bash - setup_pip () { echo Using pip from $(which pip) if [[ -d /src ]] ; then tmpdir=`mktemp -d` pushd /src for srcrepo in swh-* ; do - if [ -w $srcrepo ] - then - # Install package in editable mode if source directory is writable - pip install -e $srcrepo - else + if [ ! -w $srcrepo ]; then + echo "$srcrepo is read-only; install from a local copy" # Source directories might not be writeable, but building them writes # in-tree; so we're copying them to a location guaranteed to be writeable. rsync -a --chmod=+w $srcrepo $tmpdir/ --exclude "*/__pycache__/" --exclude "*/.tox/" --exclude "*/.hypothesis/" - pip install $tmpdir/$srcrepo + pushd $tmpdir/$srcrepo + else + pushd $srcrepo + fi + # Install package in editable mode if source directory is writable + pip install -e . + # swh-web special case to handle frontend assets compilation + if [ -f package.json ]; then + yarn install --frozen-lockfile + if [ ! -w . ]; then + # swh-web source directory is not writable, there is no interest to + # use webpack-dev-server as we made a copy of assets source files, + # simply compile the assets then + yarn build-dev + else + # webpack-dev-server can be used, web application will be automatically + # reloaded in the browser when modifying assets sources (js, css, ...) + yarn start-dev& + fi fi + popd done popd - rm -rf $tmpdir fi echo Installed Python packages: pip list }