frappe / frappe_docker

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

Couldn't install custom apps after custom image build #1515

Open elhananjair opened 5 days ago

elhananjair commented 5 days ago

Description of the issue

Greetings I recently tried to build a custom image to install custom apps (HRMS, helpdesk) everything worked fine. I was experiencing docker on Fedora 41 KDE since I had problems with Podman. The first time I tried a week ago, things were fine and I could install both hrms and helpdesk after starting the containers.

But starting from recent changes to this git or maybe frappe repo, I am getting an error while building the image, although the build process ended fine I couldn't install hrms and helpdesk while installing erpnext just works fine.

Context information (for bug reports)

I am on Fedora Workstation 41 using Docker version 27.3.1, build ce12230

Steps to reproduce the issue

  1. Followed custom apps guide here
  2. Created apps.json with the following content
    [
     {
       "url": "https://github.com/frappe/erpnext",
       "branch": "version-15"
     },
      { 
       "url": "https://github.com/frappe/hrms",
       "branch": "version-15"
     },
     { 
       "url": "https://github.com/frappe/helpdesk",
       "branch": "main"
     }
    ]

    Then generated base64 string export APPS_JSON_BASE64=$(base64 -w 0 apps.json)

  3. Building the image

     sudo docker build \
              --build-arg=FRAPPE_PATH=https://github.com/frappe/frappe \
              --build-arg=FRAPPE_BRANCH=version-15 \
              --build-arg=APPS_JSON_BASE64=$APPS_JSON_BASE64 \
              --tag=custom:15 \
              --file=images/layered/Containerfile .
    1. Using the image
      export CUSTOM_IMAGE=custom
      export CUSTOM_TAG=15
      export PULL_POLICY=never

      cp example.env .env and I edited the following parameters

      • FRAPPE_SITE_NAME_HEADER = erp
      • HTTP_PUBLISH_PORT = 8085

Created new compose file

    sudo docker compose -f compose.yaml \
         -f overrides/compose.mariadb.yaml \
         -f overrides/compose.redis.yaml \
         -f overrides/compose.noproxy.yaml \
         config > ./docker-compose.yml

Starting the containers docker compose --project-name testerp-f ./docker-compose.yml up -d

Creating site

sudo docker compose --project-name testerp exec backend bench new-site erp --mariadb-root-password 123 --admin-password 123123

Installing apps sudo docker compose -f ./docker-compose.yml --project-name testerp exec backend bench --site erp install-app erpnext sudo docker compose -f ./docker-compose.yml --project-name testerp exec backend bench --site erp install-app hrms sudo docker compose -f ./docker-compose.yml --project-name testerp exec backend bench --site erp install-app helpdesk

Observed result

erpnext installed fine helpdesk and hrms didn't installed

Expected result

both hrms and helpdesk applications should have installed without problem

Stacktrace / full error message if available

Could not find app "hrms": 
No module named 'hrms'
An error occurred while installing hrms: No module named 'hrms'
Traceback with variables (most recent call last):
  File "apps/frappe/frappe/commands/site.py", line 478, in install_app
    _install_app(app, verbose=context.verbose, force=force)
      context = {'sites': ['erp'], 'force': False, 'verbose': False, 'profile': False}
      apps = ('hrms',)
      force = False
      _install_app = <function install_app at 0x7f8024607ba0>
      filelock = <function filelock at 0x7f8024605300>
      exit_code = 0
      site = 'erp'
      app = 'hrms'
      err = ModuleNotFoundError("No module named 'hrms'")
  File "apps/frappe/frappe/installer.py", line 281, in install_app
    app_hooks = frappe.get_hooks(app_name=name)
      name = 'hrms'
      verbose = False
      set_as_patched = True
      force = False
      sync_jobs = <function sync_jobs at 0x7f8023998860>
      sync_for = <function sync_for at 0x7f8023999800>
      sync_customizations = <function sync_customizations at 0x7f8024f144a0>
      sync_fixtures = <function sync_fixtures at 0x7f8023999b20>
  File "apps/frappe/frappe/__init__.py", line 1651, in get_hooks
    hooks = _dict(_load_app_hooks(app_name))
      hook = None
      default = '_KEEP_DEFAULT_LIST'
      app_name = 'hrms'
  File "apps/frappe/frappe/utils/caching.py", line 59, in wrapper
    return_val = func(*args, **kwargs)
      args = ('hrms',)
      kwargs = {}
      args_key = ********
      func = <function _load_app_hooks at 0x7f8025e90ea0>
  File "apps/frappe/frappe/__init__.py", line 1623, in _load_app_hooks
    app_hooks = get_module(f"{app}.hooks")
      app_name = 'hrms'
      hooks = {}
      apps = ['hrms']
      app = 'hrms'
      types = <module 'types' from '/usr/local/lib/python3.11/types.py'>
  File "apps/frappe/frappe/__init__.py", line 1489, in get_module
    return importlib.import_module(modulename)
      modulename = 'hrms.hooks'
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
      name = 'hrms.hooks'
      package = None
      level = 0
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
      name = 'hrms.hooks'
      package = None
      level = 0
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
      name = 'hrms.hooks'
      import_ = <function _gcd_import at 0x7f8027233d80>
      module = <exception while printing> Traceback (most recent call last):
          File "env/lib/python3.11/site-packages/traceback_with_variables/core.py", line 222, in _to_cropped_str
            raw = print_(obj)
                  ^^^^^^^^^^^
          File "apps/frappe/frappe/utils/__init__.py", line 328, in dict_printer
            if key in v:
               ^^^^^^^^
        TypeError: argument of type 'object' is not iterable

  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
      name = 'hrms.hooks'
      import_ = <function _gcd_import at 0x7f8027233d80>
      path = None
      parent = 'hrms'
      parent_spec = None
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      f = <function _gcd_import at 0x7f8027233d80>
      args = ('hrms',)
      kwds = {}
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
      name = 'hrms'
      package = None
      level = 0
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
      name = 'hrms'
      import_ = <function _gcd_import at 0x7f8027233d80>
      module = <exception while printing> Traceback (most recent call last):
          File "env/lib/python3.11/site-packages/traceback_with_variables/core.py", line 222, in _to_cropped_str
            raw = print_(obj)
                  ^^^^^^^^^^^
          File "apps/frappe/frappe/utils/__init__.py", line 328, in dict_printer
            if key in v:
               ^^^^^^^^
        TypeError: argument of type 'object' is not iterable

  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
      name = 'hrms'
      import_ = <function _gcd_import at 0x7f8027233d80>
      path = None
      parent = ''
      parent_spec = None
      spec = None
builtins.ModuleNotFoundError: No module named 'hrms'

Additional resources on errors

Screenshot_20241115_215909

https://github.com/user-attachments/assets/47fc842a-bf75-4db5-be4e-49b732cda14a

elhananjair commented 5 days ago

EDIT: After a while, I tried the same deployment using Podman and it is working fine, I could install hrms and helpdesk. This issue seems to be happening on docker only.

revant commented 4 days ago

I don't use docker for deployment. I cannot replicate it under my k8s environment.

elhananjair commented 4 days ago

I don't use docker for deployment. I cannot replicate it under my k8s environment.

mm, I am not 100% sure but maybe SELinux is causing an issue with the building process, there is a message pop-up when I start the docker build command. It was working fine last week though without a problem. But gladly since Podman worked for me now I think I should shift to Podman or Kubernetes.

revant commented 4 days ago

Try following command from backend container.

ls -1 apps > sites/apps.txt

After that try install app again.

elhananjair commented 4 days ago

ls -1 apps > sites/apps.txt

I executed sudo docker exec -ti liyumfi_backend_1 /bin/bash to backend service and executed the command you have suggested, checking apps.txt it contains only erpnext and frappe therefore I added hrms.

image

Then I tried installing hrms (bench --site erp install-app hrms) and still the same error occurred.

revant commented 1 day ago

checking apps.txt it contains only erpnext and frappe

It means you don't have hrms in the image.

elhananjair commented 12 hours ago

checking apps.txt it contains only erpnext and frappe

It means you don't have hrms in the image.

The problem is that it doesn't include HRMS while building a custom image. As I attached a video while building the image, it will show an error and skip HRMS and the helpdesk.