GeoNode / geonode-project

A django template project for creating custom GeoNode projects.
http://geonode.org
77 stars 170 forks source link

Problem with geonode-mapstore-client plugin in production #521

Closed petyapetr closed 2 months ago

petyapetr commented 3 months ago

Context

I successfully scaffolded a mapstore extension for a geonode project by following the tutorial[^1]. The extension displays a message box when the map-viewer loads.

However, it only functions properly when the project is deployed locally using the ./paver_dev.sh start command[^2], which utilizes the .override_dev_env file and operates within the /opt/geonode-project/my-project-name/src directory.

[^1]: Had to fix a few npm dev dependencies to achieve that (css-minimizer-webpack-plugin and react-redux)

[^2]: or with ./manage_dev.sh runserver 0.0.0.0:8000 for that matter

Problem

When attempting to deploy the project using the provided instructions, I created the my-project-name.ini file for uwsgi and initiated the project with the command uwsgi --ini /etc/apps-enabled/my-project-name.ini.

However, the extension did not load for the map-viewer.

The Geonode portal operated normally and even served the project's static templates with customizations. Nevertheless, the map-viewer failed to incorporate the geonode-mapstore-client extension.

Going forward with instructions, I've created my-project-name.ini file for the uwsgi and started a project with uwsgi --ini /etc/apps-enabled/my-project-name.ini command.

However it didn't load my extension for the map-viewer.

Geonode portal was working as expected, even serving my project with it's static templates customized. Only map-viewer didn't have it's geonode-mapstore-client extension.

Prerequisites

petyapetr commented 2 months ago

Solved a problem, in the end it was a skill issue (and a lack of documentation).

As a frontend dev I didn't fully understand a process of deployment a Django app with uwsgi and nginx (still don't). I tried to change different Python related configs, until I figured out that static files are served by nginx.

If you'll face the same problem, know that after npm run compile command, you should go to the project directory and run ./manage_dev.sh collectstatic command. That command will move compiled static files to the folder from which they will be served to the end user. However for you to be able to see those files in production, you should also change bginx config file. Change a path for static file location to the right one, and make sure to give an nginx user right permissions.

There is one or two mentions of collectstatic command in official documentation, and none of those describe what exactly this command does. Mentions in docs are related to database migrations, which is misleading in my opinion.

Also in training documention on how to put project to production doesn't mention at all that you should change nginx config for it to able to serve static files of a project.

I strongly believe that problems with project extensions in productions, which I've described upon, should be reflected in documentation. I'm willing to provide more detailed description of my experience and help with writing those documents.

Best of luck