Page MenuHomeSoftware Heritage

docker: make yarn run in the local copy of the swh-web source code
ClosedPublic

Authored by douardda on Apr 4 2022, 2:06 PM.

Details

Summary

to prevent permission issues.

Depends on D7492

Diff Detail

Repository
rDENV Development environment
Branch
master
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 28155
Build 44095: arc lint + arc unit

Event Timeline

anlambert added a subscriber: anlambert.
anlambert added inline comments.
docker/utils/pyutils.sh
34–36

Indentation is not good here, surely mixed tabs and spaces.

40

If we use a local copy of the js sources, using webpack-dev-server has no longer any interest.

When not using a local copy, there is also an issue with webpack-dev-server that infinitely reload
the webapp in the browser (it was working fine at the time).

So we should drop the use of webpack-dev-server in docker and simply compile the assets in dev mode.

You can replace the call to yarn start-dev& by yarn build-dev.

This revision now requires changes to proceed.Apr 4 2022, 2:16 PM
docker/utils/pyutils.sh
34–36

yep, some day I'll fix my emacs config to stop using tabs in bash scripts...

40

should we make the difference whether the directory is writable or not? (we make a local copy only if the source directory is not writable; not sure in which conditions it can be writable in docker however)

docker/utils/pyutils.sh
40

No, better compiling the assets in all cases. If the directory is writable but assets have not been compiled on the host, it will ensure they will be available.

fix indentation and do only call 'yarn build-dev'

as suggested by anlambert

So I made some tests today to fix the infinite reloading of the webapp in browser when overriding swh-web sources and when the source directory is writable.
Turns out the issue was coming from the use of webpack loader cache as we use production settings for the webapp in docker env.
Unfortunately, it clashes with the use of webpack-dev-server so the infinite reload.
The use of webpack-dev-server in docker was originally working as I forced the use of dev settings in that case but
it was reverted in rDENV6c4f3c5f41fc5a4f1f96b92d006cfcf82e6cffee.
Fortunately, I found a workaround to restore webpack-dev-server use (D7505).

Also the assets compilation must happen after having installed the swh-web Python package or a full install
of js dependencies will happen each time the swh-web service is started.

So I came out with the following patch to apply to the current state of the diff:

diff --git a/docker/utils/pyutils.sh b/docker/utils/pyutils.sh
index a679640..3533adb 100755
--- a/docker/utils/pyutils.sh
+++ b/docker/utils/pyutils.sh
@@ -15,12 +15,22 @@ setup_pip () {
       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
-        yarn build-dev
+        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
-      # Install package in editable mode if source directory is writable
-      pip install -e .
       popd
     done
     popd
This revision now requires changes to proceed.Apr 5 2022, 3:20 PM
docker/utils/pyutils.sh
13

I think we should print a message indicating that source dir is not writable and that we made a copy of source files.

adapt code according to anlambert's suggestion

This revision is now accepted and ready to land.Apr 6 2022, 1:50 PM