frappe / frappe_docker

Docker images for production and development setups of the Frappe framework and ERPNext
MIT License
1.41k stars 1.32k forks source link

ERPNext upgrade makes assets fail #1353

Closed sorinpopescu closed 2 months ago

sorinpopescu commented 6 months ago

After version change and containers rebuild assets are broken

Context information (for bug reports)

Steps to reproduce the issue

  1. Install ERPNext with version v15.16.2
  2. Finish instalation and go the application
  3. Change version in .env (or docker compose) from v15.16.2 to v15.17.0
  4. Rebuild container
  5. Refresh works - because of cache - try incognito browser
  6. Application works, but all assets are broken (css / js)
  7. Running migrate or build not helping
  8. Fresh install works with database export / import but it's not the desired upgrade

Expected result: after upgrade to have a fully functional application

Stacktrace / full error message if available

![image](https://github.com/frappe/frappe_docker/assets/2951110/d70c465d-bc6b-4977-be13-788532cc1216)
aynugek commented 6 months ago

I have the same issue, however for me it's that either the browser loads old assets after running bench build or it can load js assets fine but css assets raise a 404. I'm using frappe_docker to run frappe v14.66.3 and erpnext v14.64.0.

Screenshot_20240314_115953

Screenshot_20240314_115737

aynugek commented 6 months ago

Looks like removing the container and starting it as explained here fixes the issue.

letajmal commented 4 months ago

You should not run bench build command in docker production setup. Apps will be build during docker image build, there is no need and running bench build will break your site. Deleting and redeploying the current containers will solve the issue(docker compose down && docker compose up -d)

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale. You have a week to explain why you believe this is an error.

oleynikd commented 1 month ago

@letajmal but rebuilding image with adding new or removing old apps will also break the site. It updates the sites/ directory which is mapped to a shared volume. If we remove this volume all data will be lost, if we keep it - we'll get a 500 (Internal Server Error). So how should we add/remove/update apps on a working production docker containers?

letajmal commented 1 month ago

Building a new image with the latest apps will not update anything under the sites folder.

What's happening in the docker image is they're just initialising a bench and get-app the required apps.

Once the new image is built, you just need to migrate and clear cache for the changes to rollout into your production site

it will be as follows

docker build
# Replace the image name with the latest tag in your compose file
docker compose up -d
bench migrate
bench clear cache 
oleynikd commented 1 month ago

@letajmal thank you. But what if I need to add new app? Or remove unused one?

letajmal commented 1 month ago

Remove that app from apps.json or from Dockerfile.

we are only keeping sites and logs directory as docker volumes, all the other directories are ephemeral/non persistent

The old application will get removed once you deploy the new image

You can uninstall the app from your site after that

oleynikd commented 1 month ago

@letajmal previously you said that

Building a new image with the latest apps will not update anything under the sites folder.

But information about all assets is stored in sites/assets/assets.json so after building new frappe+erpnext docker image the frontend will look for old asset files like assets/frappe/dist/css/website.bundle.BHRNN4K5.css that are listed in sites/assets/assets.json and will not find them, because those build hashes changed (as well as file contents). Please help to solve this issue.

oleynikd commented 1 month ago

So I had to start a new container (from newly built image) with shell, copy the contents of sites/assets/assets.json and sites/assets/assets-rtl.json, then go to my mapped sites/assets volume and update those files in mapped volume, then bench clear-cache && bench clear-website-cache, restarted my containers and now everything works fine.

oleynikd commented 1 month ago

By the way, the apps.json file will also never be updated because it is located in sites directory

oleynikd commented 1 month ago

@letajmal but sites/assets/assets.json and sites/apps.json are not.

letajmal commented 1 month ago

So I had to start a new container (from newly built image) with shell, copy the contents of sites/assets/assets.json and sites/assets/assets-rtl.json, then go to my mapped sites/assets volume and update those files in mapped volume, then bench clear-cache && bench clear-website-cache, restarted my containers and now everything works fine.

I am sorry if i mislead you, these files will also get updated. For an example, from the official docs

apps.txt This file contains a list of Frappe apps. An app should be listed here before it can be installed on a site. It is added automatically when bench get-app command or bench new-app command is run.

so apps.txt will get updated when the we bench get-app during a docker image build refer line 105

RUN bench init \ --frappe-branch=${FRAPPE_BRANCH} \ --frappe-path=${FRAPPE_PATH} \ --no-procfile \ --no-backups \ --skip-redis-config-generation \ --verbose \ /home/frappe/frappe-bench && \ cd /home/frappe/frappe-bench && \ bench get-app --branch=${ERPNEXT_BRANCH} --resolve-deps erpnext ${ERPNEXT_REPO} && \ echo "{}" > sites/common_site_config.json && \ find apps -mindepth 1 -path "*/.git" | xargs rm -fr

I assume all the other files you mentioned will also get updated during this step. May be someone with deep frappe framework knowledge can help us out here

Generally you should not worry about this, I have not came across any kinds of errors related to this

letajmal commented 1 month ago

image

So I had to start a new container (from newly built image) with shell, copy the contents of sites/assets/assets.json and sites/assets/assets-rtl.json, then go to my mapped sites/assets volume and update those files in mapped volume, then bench clear-cache && bench clear-website-cache, restarted my containers and now everything works fine.

these files are already present in frappe/erpnext image even before creating a new site

oleynikd commented 1 month ago

Yes, and they are moved to docker shared volume. So after building new docker image and running a new container those files will not be updated.