tiredofit / docker-freescout

Dockerized web based help desk and shared inbox
MIT License
228 stars 93 forks source link

PostgreSQL Database Setup is completely omitted on first run #111

Open theAkito opened 1 year ago

theAkito commented 1 year ago

Basically https://github.com/tiredofit/docker-freescout/issues/59, but much worse.

On Postgres, it does not only not create the database, it does not do anything. Nothing. It successfully connects to the database, however it does not create the freescout user, it does not create the freescout database and even when I craft all those manually, it still does not fill the database with initial content.

Example

production.ERROR: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "jobs" does not exist
LINE 1: select * from "jobs" where "queue" = $1 and (("reserved_at" ...
                      ^ (SQL: select * from "jobs" where "queue" = emails and (("reserved_at" is null and "available_at" <= 1676248436) or ("reserved_at" <= 1676248346)) order by "id" asc limit 1 for update) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42P01): SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"jobs\" does not exist
LINE 1: select * from \"jobs\" where \"queue\" = $1 and ((\"reserved_at\" ...
                      ^ (SQL: select * from \"jobs\" where \"queue\" = emails and ((\"reserved_at\" is null and \"available_at\" <= 1676248436) or (\"reserved_at\" <= 1676248346)) order by \"id\" asc limit 1 for update) at /www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, Doctrine\\DBAL\\Driver\\PDO\\Exception(code: 42P01): SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"jobs\" does not exist
LINE 1: select * from \"jobs\" where \"queue\" = $1 and ((\"reserved_at\" ...
                      ^ at /www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 42P01): SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"jobs\" does not exist
LINE 1: select * from \"jobs\" where \"queue\" = $1 and ((\"reserved_at\" ...
                      ^ at /www/html/overrides/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:115)
[stacktrace]
#0 /www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\\Database\\Connection->runQueryCallback('select * from \"...', Array, Object(Closure))
#1 /www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php(333): Illuminate\\Database\\Connection->run('select * from \"...', Array, Object(Closure))
#2 /www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1719): Illuminate\\Database\\Connection->select('select * from \"...', Array, false)
#3 /www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1704): Illuminate\\Database\\Query\\Builder->runSelect()
#4 /www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(77): Illuminate\\Database\\Query\\Builder->get(Array)
#5 /www/html/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(225): Illuminate\\Database\\Query\\Builder->first()
#6 /www/html/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php(197): Illuminate\\Queue\\DatabaseQueue->getNextAvailableJob('emails')
#7 /www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(244): Illuminate\\Queue\\DatabaseQueue->pop('emails')
#8 /www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(105): Illuminate\\Queue\\Worker->getNextJob(Object(Illuminate\\Queue\\DatabaseQueue), 'emails')
#9 /www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\\Queue\\Worker->daemon('database', 'emails,default,...', Object(Illuminate\\Queue\\WorkerOptions))
#10 /www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(85): Illuminate\\Queue\\Console\\WorkCommand->runWorker('database', 'emails,default,...')
#11 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#12 /www/html/overrides/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#13 /www/html/overrides/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#14 /www/html/overrides/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#15 /www/html/overrides/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#16 /www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#17 /www/html/vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#18 /www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#19 /www/html/vendor/symfony/console/Application.php(992): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 /www/html/vendor/symfony/console/Application.php(255): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 /www/html/vendor/symfony/console/Application.php(148): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 /www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#23 /www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 /www/html/artisan(62): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#25 {main}
"}
tiredofit commented 1 year ago

Database creation routines are left up to the database container I believe. I don't know enough about the Freescout code to tell if it's attempting to create the database, but my experience says no.

I can see about throwing a halt error if the database population command fails, it would take some investigation to see if it did, otherwise start to trap the output and look for specific failure strings.

theAkito commented 1 year ago

Database creation routines are left up to the database container I believe.

I thought so, which is why I was suprised to see this, as I'm using your PostgreSQL image, which is used in many scenarios. So, I assumed, that the fault cannot lie in the container made from that image.

Though, I also saw that there are a lot of custom users involved in the whole stack & now I'm starting to wonder, whether it fails to deal with a permission error on initialisation.

Okay, checked it now & all the files in /var/lib/postgresql/data are set to 70:70.

I can see about throwing a halt error if the database population command fails, it would take some investigation to see if it did, otherwise start to trap the output and look for specific failure strings.

Which log are you referring to, exactly?

tiredofit commented 1 year ago

I thought so, which is why I was suprised to see this, as I'm using your PostgreSQL image, which is used in many scenarios. So, I assumed, that the fault cannot lie in the container made from that image.

I rebuilt that image in the past month and added a whole bunch of functionality to the 15 branch. It definitely should auto create a database with settings that look similar to this:

freescout-db:
    image: tiredofit/postgres:15
    container_name: freescout-db
    volumes:
      - ./db:/var/lib/postgresql
    environment:
      - TIMEZONE=America/Vancouver
      - CONTAINER_NAME=freescout-db
      - CONTAINER_ENABLE_MONITORING=FALSE

      - SUPERUSER_PASS=superduper

      - DB01_NAME=freescout
      - DB01_USER=freescout
      - DB01_PASS=password
    networks:
      - services
    restart: always

Though, I also saw that there are a lot of custom users involved in the whole stack & now I'm starting to wonder, whether it fails to deal with a permission error on initialisation.

Postgres 70, Nginx 80, and a whole lot more - It's messy, I agree, however they can be changed. I haven't had a problem and I run this stack and more after wrapping my head around it and it just works hands off.

I can see about throwing a halt error if the database population command fails, it would take some investigation to see if it did, otherwise start to trap the output and look for specific failure strings.

Which log are you referring to, exactly?

I'm executing this to populate the database (line 229 of cont-init.d/30-freescout) silent just hides the output, which you could change to show by setting SHOW_OUTPUT=TRUE as an environment variable.. If you were inside the container you could execute the sudo ... command and hack away at it to get the database populated, restarting the container after that should proceed, but lets not get too far ahead of ourselves quite yet.

There's also a log which is what you may be seeing in /www/freescout/storage/logs/laravel.log, although it may not be active until a full installation is completed.

Want to share your docker-compose or similar stack info? I actually have never done a Postgres installation of Freescout, just happily chugging along with a few MariaDB instances but If this is widespread I would like to fix it.

theAkito commented 1 year ago

docker-compose.yml

# https://github.com/tiredofit/docker-freescout/blob/main/examples/docker-compose.yml

version: "3.9"

services:
  freescout-app:
    image: tiredofit/freescout
    container_name: freescout
    # user: "1005"
    links:
      - freescout-db
    volumes:
      ### If you want to perform customizations to the source and have access to it, then uncomment this line - This includes modules
      - /storage/freescout/html:/www/html
      # - /storage/freescout/data:/data
      - /storage/freescout/logs:/www/logs
    env_file:
      - ./freescout.env
    networks:
        - proxy-tier
    ports:
      - 127.0.0.1:53129:80
    restart: unless-stopped

  freescout-db:
    image: tiredofit/postgres
    container_name: freescout_db
    # user: "1005"
    volumes:
      - /storage/freescout/database/data:/var/lib/postgresql/data
    env_file:
      - ./freescout_db.env
    networks:
      - proxy-tier
    restart: unless-stopped

  # https://github.com/tiredofit/docker-db-backup
  freescout-db-backup:
    container_name: freescout-db-backup
    # user: "1005"
    image: tiredofit/db-backup
    links:
     - freescout-db
    volumes:
      - /storage/freescout/database/backup:/backup
    env_file:
      - ./freescout_db-backup.env
    networks:
      - proxy-tier
    restart: unless-stopped

networks:
  proxy-tier:
    name: nginx-proxy

.env Partial

# Database
CONTAINER_ENABLE_MONITORING=FALSE
CREATE_DB=TRUE
DB_TYPE=pgsql
DB_HOST=freescout_db
DB_PORT=5432
POSTGRES_DB=freescout
POSTGRES_USER=freescout
POSTGRES_PASSWORD=bla1
FREESCOUT_NAME=freescout
FREESCOUT_USER=freescout
FREESCOUT_PASS=bla1
DB01_NAME=freescout
DB01_USER=freescout
DB01_PASS=bla1
DB_NAME=freescout
DB_USER=freescout
DB_PASS=bla1
ROOT_PASS=bla2
SUPERUSER_PASS=bla3

After adding the original PostgreSQL Docker Image environment variabales prefixed with POSTGRES_, I got rid of the baby problems with not having a database created & finally I get the default database layout set up. Step accomplished!

Now, I need to know why/how the app does not add the Admin user, which I specified via environment variable, as described in this repository's descriptions.

I added the Admin user manually to the users table. Now, I'm getting These credentials do not match our records. and not error in any logs.

tiredofit commented 1 year ago

OK, moving forward!!

From the command line this is how to create a user: artisan -n freescout:create-user --role=admin --firstName="${ADMIN_FIRST_NAME}" --lastName="${ADMIN_LAST_NAME}" --email="${ADMIN_EMAIL}" --password="${ADMIN_PASS}"

theAkito commented 1 year ago

artisan -n freescout:create-user --role=admin --firstName="${ADMIN_FIRST_NAME}" --lastName="${ADMIN_LAST_NAME}" --email="${ADMIN_EMAIL}" --password="${ADMIN_PASS}"

freescout_db

Delete the user I created manually, previously.

psql -U freescout freescout
DELETE FROM users WHERE id=2;

freescout

chmod +x /www/html/artisan; /www/html/artisan -n freescout:create-user --role=admin --firstName="Admin" --lastName="Admin" --email="admin@admin.com" --password="adminpw"

Now, I can finally log in! Thank you!

Do you need any more information on this PostgreSQL based setup?

tiredofit commented 1 year ago

Excellent! I'm going to have a member of my team in future see this issue and attempt to recreate to make sure that Postgres instances are correctly supported. Glad you are on track and ready to use Freescout :)

theAkito commented 1 year ago

Thank you very much for your kind words & your great, involved & swift support. It is truly highly appreciated. Thank you very much.

If you need anything, do not hesitate to contact me via mail or something, so we do not clutter this issue.

Not sure if this issue should be closed, since someone will try to reproduce it.