invoiceninja / dockerfiles

Docker files for Invoice Ninja
https://hub.docker.com/r/invoiceninja/invoiceninja
GNU General Public License v2.0
383 stars 249 forks source link

Container ignores DB_TYPE #525

Open Sapp00 opened 12 months ago

Sapp00 commented 12 months ago

Setup information Docker, deployed on Kubernetes using Custom Deployment

Describe the bug The container starts, but after a long time it crashes saying that the MySQL Server is gone while I set the environment variable to use Postgres. When I jump into the container, the Environment Variable shows:

~ $ echo $DB_TYPE
pgsql 

Somehow this variable is being ignored.

To reproduce Steps to reproduce the behavior:

  1. Deploy the invoice ninja container, set environment variables as described in the following.
  2. Have a PostgreSQL running (14.x in my case)
  3. Wait for the logs

Expected behavior It should connect to the postgres.

Screenshots/logs

% k logs -f invoice-ninja-deployment-6b67498675-rhcrg
2023-07-12T08:18:44Z [INFO] [Entrypoint]: Initialising Invoice Ninja...

   INFO  Configuration cached successfully.

   INFO  Caching the framework bootstrap files.

  config .......................................................... 190ms DONE
  routes .......................................................... 432ms DONE

   INFO  Discovering packages.

  imdhemy/laravel-purchases ............................................. DONE
  intervention/image .................................................... DONE
  invoiceninja/inspector ................................................ DONE
  laravel/slack-notification-channel .................................... DONE
  laravel/socialite ..................................................... DONE
  laravel/tinker ........................................................ DONE
  laravel/ui ............................................................ DONE
  livewire/livewire ..................................................... DONE
  nesbot/carbon ......................................................... DONE
  nunomaduro/termwind ................................................... DONE
  nwidart/laravel-modules ............................................... DONE
  sentry/sentry-laravel ................................................. DONE
  socialiteproviders/manager ............................................ DONE
  spatie/laravel-data ................................................... DONE
  turbo124/beacon ....................................................... DONE
  webpatser/laravel-countries ........................................... DONE

In Connection.php line 760:

  SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: select * from infor
  mation_schema.tables where table_schema = invoice and table_name = accounts
   and table_type = 'BASE TABLE')

In Connector.php line 70:

  SQLSTATE[HY000] [2006] MySQL server has gone away

In Connector.php line 70:

  PDO::__construct(): Error while reading greeting packet. PID=55

Docker/Kubernetes/Helm:

Additional context I execute it without root privileges - do I need to specify gid/uid? It at least doesnt show any privilege issues.

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: invoice-ninja-deployment
  labels:
    app: invoice-ninja
spec:
  replicas: 1
  selector:
    matchLabels:
      app: invoice-ninja
  template:
    metadata:
      labels:
        app: invoice-ninja
    spec:
      containers:
        - name: invoice-ninja
          image: invoiceninja/invoiceninja:5.6
          volumeMounts:
            - mountPath: "/var/app/public"
              name: invoice-ninja-public-pv
            - mountPath: "/var/app/storage"
              name: invoice-ninja-storage-pv
          env:
            - name: APP_ENV
              value: production
            - name: APP_DEBUG
              value: '0'
            - name: APP_URL
              value: invoice.local
            - name: APP_CIPHER
              value: 'AES-256-CBC'
            - name: DB_TYPE
              value: pgsql
            - name: DB_HOST
              value: invoice-rw.postgres.svc.cluster.local
            - name: DB_STRICT
              value: 'false'
            - name: DB_DATABASE
              value: invoice
            - name: DB_PORT
              value: '5432'
            - name: DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: invoice-secret
                  key: username
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: invoice-secret
                  key: password
            - name: APP_KEY
              valueFrom:
                secretKeyRef:
                  name: invoice-app-secret
                  key: app-key
      volumes:
        - name: invoice-ninja-public-pv
          persistentVolumeClaim:
            claimName: invoice-ninja-public-claim
        - name: invoice-ninja-storage-pv
          persistentVolumeClaim:
            claimName: invoice-ninja-storage-claim
Sapp00 commented 12 months ago

Okay, actually just some documentation is outdated. It should be DB_CONNECTION and not DB_TYPE to define the database type. Furthermore, this PR is needed to get it running. Afterwards, there are still errors:

SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "enabled_expense_tax_r ates" cannot be cast automatically to type integer HINT: You might need to specify "USING enabled_expense_tax_rates::integer" . (SQL: ALTER TABLE companies ALTER enabled_expense_tax_rates TYPE INT)

There is a fork where this issue has been "fixed": patch file. It is out of date and also rather hacky than clean.