SUSE / Portus

Authorization service and frontend for Docker registry (v2)
http://port.us.org/
Apache License 2.0
3k stars 472 forks source link

Database detected as empty and its tried to be setup again #1712

Closed marc0s closed 6 years ago

marc0s commented 6 years ago

Description

I'm using a docker-compose setup. Fetch portus:head and restarted my containers. portus didn't come up because it failed with something very similar to this.

Steps to reproduce

  1. pull updated portus:head
  2. restarted containers
  3. And this happened!

Findings

After some digging, I found out that init is checking if we set PORTUS_INIT_COMMAND, by default it isn't. I manually run the check_db.rb script and found out that it was sending back a DB_EMPTY, which is actually inaccurate. I manually entered into the DB and found that my data was still there.

MariaDB [portus_production]> select count(*) from users;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.01 sec)

So, I set PORTUS_INIT_COMMAND to portusctl exec "pumactl -F /srv/Portus/config/puma.rb start" (just as init runs at the end) and my container started flawlessly.

What's portus/db using to determine if the database is empty or not? I think I have run somehow the same docker-compose setup but with 2.3 instead of head once trying to find out the issue (maybe causing the issue, actually?). Might it be the source of the problem if it can modify something that portus/db will interpret as an empty database?

Please tell me if you need anything else.

Thanks!

ldperron commented 6 years ago

I got the exact same issue here after performing a pull on the docker image.

Reason: From /init, this command portusctl exec rails r /srv/Portus/bin/check_db.rb | grep DB yields DB_EMPTY if there is a single missing migration. Which was my case, I had this migration missing: 20180207145522_change_vulnerabilities_to_medium_text.rb

If I manually run: portusctl rake db:migrate (without lettings db:setup running), then check_db.rb yields DB_READY

marc0s commented 6 years ago

I miss the notification for this reply, sorry.

I got it fixed as well. Thanks.

ldperron commented 6 years ago

Actually, I would keep this bug open. We should expect init script to detect that there are missing migrations, and try to apply them on startup, instead of trying to wipe out and recreate the database.

mssola commented 6 years ago

This has been finally fixed with #1970 and https://github.com/openSUSE/docker-containers/commit/293e28998f08f83de50335c854caecb9c1597d89. The head image will contain the fix once it's done building.

Thanks everyone for the feedback :clap: