akaunting / docker

Docker Image for Akaunting
https://github.com/akaunting/akaunting
GNU General Public License v3.0
189 stars 88 forks source link

Using Bind Mounts for akaunting-modules breaks deploys #53

Closed smacz42 closed 2 years ago

smacz42 commented 3 years ago

Hi, I have the exact same problem. Same as @MohammedAl-Mahdawi , I tried to follow the official default configuration, and obtained this compose file:

    volumes:
      - ./akaunting-data:/var/www/html/storage:Z
      - ./akaunting-modules:/var/www/html/modules:Z

I run this compose with podman-compose like this:

AKAUNTING_SETUP=true podman-compose up

And I end up with this error when the app initializes the database (I think):

Setting locale en-US
Creating database tables
Connecting to database akaunting@127.0.0.1:3306
Creating company
[2021-06-01 13:24:38] production.ERROR: Call to a member function get() on null {"exception":"[object] (Error(code: 0): Call to a member function get() on null at /var/www/html/app/Abstracts/Commands/Module.php:59)
[stacktrace]
#0 /var/www/html/overrides/akaunting/laravel-module/Commands/InstallCommand.php(48): App\\Abstracts\\Commands\\Module->createHistory('installed')
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Akaunting\\Module\\Commands\\InstallCommand->handle()
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#7 /var/www/html/vendor/symfony/console/Command/Command.php(256): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle))
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle))
#9 /var/www/html/vendor/symfony/console/Application.php(971): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#10 /var/www/html/vendor/symfony/console/Application.php(290): Symfony\\Component\\Console\\Application->doRunCommand(Object(Akaunting\\Module\\Commands\\InstallCommand), Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#11 /var/www/html/vendor/symfony/console/Application.php(166): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(184): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(263): Illuminate\\Console\\Application->call('module:install', Array, NULL)
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Foundation\\Console\\Kernel->call('module:install', Array)
#16 /var/www/html/database/seeds/Modules.php(32): Illuminate\\Support\\Facades\\Facade::__callStatic('call', Array)
#17 /var/www/html/database/seeds/Modules.php(20): Database\\Seeds\\Modules->create()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Database\\Seeds\\Modules->run()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(149): Illuminate\\Container\\Container->call(Array, Array)
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(49): Illuminate\\Database\\Seeder->__invoke(Array)
#25 /var/www/html/database/seeds/Company.php(20): Illuminate\\Database\\Seeder->call('Database\\\\Seeds\\\\...')
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Database\\Seeds\\Company->run()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#28 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#30 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(149): Illuminate\\Container\\Container->call(Array, Array)
#32 /var/www/html/app/Console/Commands/CompanySeed.php(36): Illuminate\\Database\\Seeder->__invoke()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Console\\Commands\\CompanySeed->handle()
#34 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#36 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#39 /var/www/html/vendor/symfony/console/Command/Command.php(256): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle))
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Illuminate\\Console\\OutputStyle))
#41 /var/www/html/vendor/symfony/console/Application.php(971): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#42 /var/www/html/vendor/symfony/console/Application.php(290): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\CompanySeed), Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#43 /var/www/html/vendor/symfony/console/Application.php(166): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#45 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(184): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArrayInput), Object(Symfony\\Component\\Console\\Output\\BufferedOutput))
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(263): Illuminate\\Console\\Application->call('company:seed', Array, NULL)
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Foundation\\Console\\Kernel->call('company:seed', Array)
#48 /var/www/html/app/Jobs/Common/CreateCompany.php(66): Illuminate\\Support\\Facades\\Facade::__callStatic('call', Array)
#49 /var/www/html/app/Jobs/Common/CreateCompany.php(43): App\\Jobs\\Common\\CreateCompany->callSeeds()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(29): App\\Jobs\\Common\\CreateCompany->App\\Jobs\\Common\\{closure}(Object(Illuminate\\Database\\MySqlConnection))
#51 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php(388): Illuminate\\Database\\Connection->transaction(Object(Closure))
#52 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Database\\DatabaseManager->__call('transaction', Array)
#53 /var/www/html/app/Jobs/Common/CreateCompany.php(46): Illuminate\\Support\\Facades\\Facade::__callStatic('transaction', Array)
#54 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Jobs\\Common\\CreateCompany->handle()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#56 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#58 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#59 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\\Container\\Container->call(Array)
#60 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}(Object(App\\Jobs\\Common\\CreateCompany))
#61 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(App\\Jobs\\Common\\CreateCompany))
#62 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#63 /var/www/html/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\\Bus\\Dispatcher->dispatchNow(Object(App\\Jobs\\Common\\CreateCompany), false)
#64 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(405): Illuminate\\Bus\\Dispatcher->dispatchSync(Object(App\\Jobs\\Common\\CreateCompany), NULL)
#65 /var/www/html/app/Utilities/Installer.php(241): dispatch_sync(Object(App\\Jobs\\Common\\CreateCompany))
#66 /var/www/html/app/Console/Commands/Install.php(82): App\\Utilities\\Installer::createCompany('My Company', 'my@company.com', 'en-US')
#67 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\\Console\\Commands\\Install->handle()
#68 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#69 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#70 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#71 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#72 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#73 /var/www/html/vendor/symfony/console/Command/Command.php(256): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#74 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#75 /var/www/html/vendor/symfony/console/Application.php(971): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#76 /var/www/html/vendor/symfony/console/Application.php(290): Symfony\\Component\\Console\\Application->doRunCommand(Object(App\\Console\\Commands\\Install), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#77 /var/www/html/vendor/symfony/console/Application.php(166): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#78 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#79 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#80 /var/www/html/artisan(22): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#81 {main}
"} 

In Module.php line 59:

  Call to a member function get() on null  

Originally posted by @Ezwen in https://github.com/akaunting/docker/issues/38#issuecomment-852084431

The entrypoint should be able to handle this, especially since the recommended way is to mount that directory as a volume.

A lot of what I've seen other container images do is to install the PHP app in /usr/local/src, and as the first step in the entrypoint script to rsync the files into the correct directory (/var/www/html in this case).

A workaround for now is to run the container without the volumes (you could also change the entrypoint to simply bash if you wanted), copy the files out of the container onto the host, create the bind mount directory manually, copy the files into that directory, then start up the container with the bind mountpoints as volumes. Using something like Ansible to script that simplifies the issue, but ultimately it is a workaround for a bug in the entrypoint script (albeit one that wouldn't have manifested itself if you were just using volumes).

dkebler commented 2 years ago

a bug in the entrypoint script (albeit one that wouldn't have manifested itself if you were just using volumes)."

@MohammedAl-Mahdawi is this going to be addressed as the exact issue has been identified? In my use case I prefer to mount exposed volumes on the host for backup and management.

MohammedAl-Mahdawi commented 2 years ago

Hi,

This repo is for building the official Akaunting images so please only post issues related to the official Akaunting images or the default setup of the compose files.

If you have questions or issues with your specific setup you can post your question/issue in our support channels here or on StackOverflow.

The given setups/entrypoints are just examples, we don't even recommend using Docker compose in a production environment.

There is no bug or so with the current entrypoints it is just how they work, if you think you can create another setup/entrypoint file in order to show another use case this is a community-driven project please feel free to contribute, and create a pull request, also you can create a feature request which is more than welcome by us and by the community if it will add value to the project.

Thank you for understanding!

smacz42 commented 2 years ago

Whoever else comes across this error, here is the workaround:

docker create --name akaunting-tmp akaunting/akaunting
docker cp akaunting-tmp:/var/www/html/modules/. ./akaunting_modules
docker rm akaunting-tmp

You can see this workaround in action here: https://gitlab.com/compositionalenterprises/ansible-collection-compositionalenterprises.ourcompose/-/blob/5b5fbf378bce617a5034129eacb5178d439d60e3/roles/akaunting/tasks/running.yml#L38

Here's how a project like Nextcloud does it: https://github.com/nextcloud/docker/blob/master/docker-entrypoint.sh#L93-L112

clementx2006 commented 1 year ago

hello @smacz42 - running into a similar issue and I wonder if it's related: while I was able to get the docker instance up and running using your workaround in the initial setup and subsequent runs, I am now faced with apps not being able to install producing a mkdir() no such file or directory error. The bind mount directory (for "modules") is perfectly write-enabled otherwise - can be tested using docker exec -it akaunting bash. Any suggestions what a workaround might be here? Thank you in advance!

smacz42 commented 1 year ago

I'm not sure, sorry. I'm honestly surprised to see this type of error if it's writable otherwise. I'd be interested in seeing if you could find a root cause :)

clementx2006 commented 1 year ago

Found the root cause: the app downloads the modules into storage/app/temp/temp-[random string]/* however for some reason the first temp folder was not created in the initial installation. This caused mkdir to fail when trying to make the second temp-[random string] folder. Manually made the first temp folder and everything worked.

Just in case someone also encounters the same issue in the future.