inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.23k stars 759 forks source link

[BUG] Database error on fresh install #2454

Closed markusEmm123 closed 2 years ago

markusEmm123 commented 2 years ago

Describe the bug When running the first time in a docker container the container will immideatly stop again because the database structure is not created yet. I can't create the database structure (by running "invoke update") because the container is stopped immedeatly.

Steps to Reproduce

Steps to reproduce the behavior:

Create (new, empty) database and user according to https://inventree.readthedocs.io/en/latest/start/install/

Download docker image, in my case inventree/inventree:latest

Configure docker enviroment variables to use the newly created database.

Start docker container and see it crash after a few seconds, stating in the protocol that some tables do not exist.

Expected behavior Don't stop the docker container on initilisation errors so i can attach to the container and run "invoke update".

Deployment Method

Version Information Docker on Synology (which makes configuration for handling the behaviour a bit more cumbersome).

InvenTree-Version | 0.6.0 dev  Entwicklungsversion   | Commit-Hash | 95db82a   | Commit-Datum | 2021-12-12   | API-Version | 21   | Python-Version | 3.8.10   | Django-Version | 3.2.10

What i did to fix the situation Setup another container from that image with all the same enviroment variables and paths but /bin/sleep 600 as startup command. Then i can attatch to that container, run invoke update and invoke superuser, stop that container and start the real one.

matmair commented 2 years ago

Can not reproduce on docker in debian 11. @markusEmm123 could this be a Synology thing? Did you use the supplied docker compose file?

matmair commented 2 years ago

Did you follow the instructions here? https://inventree.readthedocs.io/en/latest/start/docker/

SchrodingersGat commented 2 years ago

Can you please provide an error log?

SchrodingersGat commented 2 years ago

@markusEmm123 if you can provide some further details?

markusEmm123 commented 2 years ago

Hi, @SchrodingersGat please exuse the late response. I just have seen that the installation is explained in much more detail under the link https://inventree.readthedocs.io/en/latest/start/docker_dev/ at the end of the page. I didn't follow that link but instead just created an empty database and the downloaded and run the docker image. So i guess it is not a bug that it didn't work.

Anyway I recreated the situation, the exact error message is "

[inventree-inventree3.csv](https://github.com/inventree/InvenTree/files/7739984/inventree-inventree3.csv) 2021-12-18 21:22:14 | stdout | MySQLdb._exceptions.ProgrammingError: (1146, "Table 'inventree2.label_stockitemlabel' doesn't exist") -- | -- | --

"

Complete error log is in the attachment (be careful, it is "upside down" unfortunately, i.e. the last entry is in the first line.

SchrodingersGat commented 2 years ago

@markusEmm123 to confirm - if you follow the installation guide, it all works OK?

markusEmm123 commented 2 years ago

Hi @SchrodingersGat, Thank you for the follow up. I actually saw the complete guide too late. But i managed to attach to the container (by changing the startup command) and then run "invoke migrate" which created the neccessary database structures. So now i got it up and running.

MrManny commented 2 years ago

I ran into the same issue. The Docker environment of my Synology NAS exhibits the exact same behavior. docker-compose is also unfortunately not supported, I wired up the containers manually following the compose file.

I will try the proposed workaround in a minute; but I would like to see if there's a way to solve this more elegantly.

matmair commented 2 years ago

@MrManny in general synology docker is not a supported deployment as there seem to be some wired issues with shared storage locations (needed for worker and server). If you get it running please report back so we maybe can add something to the docs.

Also please read the docker and deploy doc pages as there are some things that need to be configured (environment variables or/and a config file) before a migration n can run. If you use postgres or mysql you also need to create a database first.

SchrodingersGat commented 2 years ago

@afkiwers did you manage to get InvenTree running on a synology setup?

afkiwers commented 2 years ago

@SchrodingersGat yes I did. Remember like a year ago I was trying to explain to you how badly it works on Synology.

What you will have to do is to SSH into you DS and install it manually as per your instructions. The containers then will pop up in Syno's interface; but as markusEmm123 mentioned. Configuring them through that interface is not that straight forward.

I personally think that the easiest way to do it is manually through SSH.

matmair commented 2 years ago

@SchrodingersGat in general there is the option to make 'app' definitions for synology. If you are interested in that I might be able to organise some docs for that.

markusEmm123 commented 2 years ago

@MrManny I'll try to reconstruct what i did (after failing to do it via SSH). First create a database (externally, e.g. with PhpMyAdmin). I created one named inventree with only one user of the same name and all rights.

Then download the image in the synology docker application and create a new container. Here is my synology docker container configuration (unfortunately in german, i try to guess the english naming): You will of course have to set the right database credentials.

Enviroment Variables image

Volume image

Port image

so basically just set up a container as it's described in https://inventree.readthedocs.io/en/latest/start/docker/

BUT change the line startup code (the last line in "enviroment variables" in "extended settings" when "starting" a new container from the image page) to

/bin/sleep 600

which will just start the container and give you 10 minutes (600 seconds) of time. If this isn't engough, set the time to something higher. Then run the container, go to "Details", "Terminal" and "create" a new terminal session. image

There you run the following two commands from https://inventree.readthedocs.io/en/latest/start/docker_dev/

invoke update to create the database structure and invoke superuser to create the admin user.

Now you have created a working configuration for Inventree to run and can stop that container. You probably delete it but maybe it's wise to keep it if you encounter trouble and need terminal access again.

As final step create another container with the same data (same image, same "volume", same enviroment variables). You will have to change the port mapping though or the docker application of synology will complain that is already in use (if you keep the old container). But this time leave the startup code at its default value.

In my case that did the trick and i have an InvenTree server up and running for a few days.

I hope i have not made any bad mistakes that will render the system unusable in a few weeks, but maybe someone with more knowledge can comment on that.

matmair commented 2 years ago

@markusEmm123 would you be willing to test / debug a package if I tried to make one?

https://github.com/inventree/InvenTree/issues/2479

markusEmm123 commented 2 years ago

Our own synology package for Inventree? How could i say no to that;)

matmair commented 2 years ago

Our own synology package for Inventree? How could i say no to that;)

It might take a while as I will try to finish my open PRs first . What kind of architecture do you have on your synology? There seem to be plenty.

markusEmm123 commented 2 years ago

Take your time, i have a solution that works for me right now.

I have a DS218+ running, that should be a Celeron, so x86 with some Linux as operting system.

MrManny commented 2 years ago

@markusEmm123: thank you for sharing your process. I'll give it a go. And no worries, I don't mind the German. :)

@matmair: I'd be happy with a Docker deployment where the container can independently run installation/migration scripts. But I also won't say no to a Synology package 😄 Anyway. I seem to have the same NAS as Markus (i.e., Synology NAS DS218+). The NAS itself is running an Intel Celeron J3355, so the system's architecture is essentially Linux/x86 as Markus indicated. Docker (version 20.10.3-1239) had been installed through the device's own package manager and the containers have been pulled from the Docker Hub (inventree/inventree:latest and postgres:latest respectively).

matmair commented 2 years ago

@MrManny you can run migration etc. in the container itself but the datasource needs to be reachable so that container needs to start first: https://inventree.readthedocs.io/en/latest/start/docker_dev/#database-setup

Normally we let docker compose handle all the settings but it seems that synology does not support that method out of the box. The package will basically just mirror the settings in the compose file.

MrManny commented 2 years ago

@matmair: thank you. I've managed to set up InvenTree in a VM using docker-compose for now for evaluation purposes. I might just transfer the database and assorted static files (if needed) to my NAS if I continue using it. That way, I can probably evade the need to run migrations and create the initial admin account.

Outside of Synology packages, I could also see an approach where bootstrapping is done through environment variables which could be removed by the user once it's set up (and then heavily complains about it if the user doesn't unset them afterwards). That would probably be a more generic approach that might also work for other non-Synology deployment situations.

matmair commented 2 years ago

@MrManny that would def. streamline the deployment instructions. If you have any concrete suggestions please submit a PR or formulate a feature request so we can track this! I also just got a Synology DS for cheap so the package should be coming in a few weeks.