Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
elhananjair opened this issue Nov 17, 2024 · 14 comments
Closed

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

elhananjair opened this issue Nov 17, 2024 · 14 comments
Labels

Comments

@elhananjair
Copy link
Contributor

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)
4. 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

Screencast_20241117_184934.mp4
@elhananjair
Copy link
Contributor Author

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
Copy link
Collaborator

revant commented Nov 18, 2024

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

@elhananjair
Copy link
Contributor Author

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
Copy link
Collaborator

revant commented Nov 18, 2024

Try following command from backend container.

ls -1 apps > sites/apps.txt

After that try install app again.

@elhananjair
Copy link
Contributor Author

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
Copy link
Collaborator

revant commented Nov 21, 2024

checking apps.txt it contains only erpnext and frappe

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

@elhananjair
Copy link
Contributor Author

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.

@elhananjair
Copy link
Contributor Author

Hello @revant
I have tried multiple times and I still couldn't install hrms, There is no error on building process. This is probably docker package I am using. For now I am building the image using podman and installing apps through docker

@elhananjair
Copy link
Contributor Author

This issue is a duplicate of #1297 and was closed without a solution, but I am trying my best to discover the problem.

@revant
Copy link
Collaborator

revant commented Dec 4, 2024

This issue is a duplicate of #1297

Use my image, It builds properly.

source: https://gitlab.com/castlecraft/cepl-erpnext-images

images: https://gitlab.com/castlecraft/cepl-erpnext-images/container_registry/3822033

Also confirm if your env variables are picked by podman compose. It might be using default image.

If you are able to solve it document it somewhere and help others. I expected previous podman users to help.

@elhananjair
Copy link
Contributor Author

This issue is a duplicate of #1297

Use my image, It builds properly.

source: https://gitlab.com/castlecraft/cepl-erpnext-images

images: https://gitlab.com/castlecraft/cepl-erpnext-images/container_registry/3822033

Also confirm if your env variables are picked by podman compose. It might be using default image.

If you are able to solve it document it somewhere and help others. I expected previous podman users to help.

Hello there, thanks for resisting this issue,
I cloned your repo and tried to build it using Podman, but it is taking time. I will retest it and will let you know. But for the time being these are conclusions I have made

  1. Build the custom apps image with buildah - This is to ensure custom applications are added to the images.
  2. Create docker-compose.yml using podman compose, but you need to install docker from official site/repo to successfully run podman compose since it is acting as a wrapper just for docker compose.
  3. Run the containers using podman and create systemd service file to start the pod using podman pod start

That's how things are working for me right now.

@revant
Copy link
Collaborator

revant commented Dec 14, 2024

I really don't know why podman doesn't work for you. I can build and run with podman.

Here is the podman build video:

podman-build-cepl-erpnext-images.webm

Here is the podman run video:

podman-run-cepl-erpnext-images.webm

@elhananjair
Copy link
Contributor Author

Thanks a lot for taking the time to check this issue.
The problem was not on finishing up the build in my case, instead, it won't include other apps defined in apps.json while building thus bench install command is giving me an error.
I used the default frappe_docker repo for now, but I think it might be a build cache or something else which causing the issue, although I removed everything using Podman system reset.

@elhananjair
Copy link
Contributor Author

Hello @revant
It works now, the build worked fine with Podman, the best thing is the custom apps are included in the image this time. I think caches and my internet speed were the suspected causes of this issue.
Thank you for taking the time and testing everything though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants