lorisleiva / laravel-docker

🐳 Generic docker image for Laravel Applications
MIT License
927 stars 313 forks source link

Incompatibility with Laravel 8 schema_dump #68

Open Synchro opened 3 years ago

Synchro commented 3 years ago

Because this image is based on Alpine, when asked to install MySQL client it actually installs MariaDB's instead. This is often a reasonable substitution, but here it's fatal.

The problem is that Laravel 8's schema dump restore process (which makes CI pipelines run so much faster) builds a command line for the mysql CLI client and uses it to import the schema. MariaDB's CLI client is incompatible with MySQL 8.0 due to lack of support for its default auth mechanism, caching_sha2_password, so unless you also want to have to reconfigure your MySQL server (meaning you can't simply enable it using services: mysql:8.0 in your CI config) you have to disable schema dump and have your tests run slowly.

The command "mysql --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --database="${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"" failed.
Exit Code: 1(General error)
Working directory: /builds/myapp
Output:
================
Error Output:
================
ERROR 1045 (28000): Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

It's only the MaraDB client that's the problem. This is tricky to fix for Alpine Linux because it does not have a real MySQL package, even though MySQL includes support for Alpine.

I've been looking through various Laravel/PHP focused images for CI, and nearly all seem to suffer this problem, so I'm hoping one will fix it!

lorisleiva commented 3 years ago

Hey 👋

Thanks for raising this.

I'm tempting to support another distribution but I love that this repo is a simple and lightweight DockerFile with the bare minimum for Laravel apps so Alpine feels like the ideal distribution to me.

I'll keep this open until — fingers crossed — a proper MySQL client becomes available for Alpine.

Thanks again. 🙂

Synchro commented 3 years ago

Thanks. I have found a workaround, but it involves downgrading the security of the mysql client connection, so it's not ideal. Add this command arg to the mysql service in your gitlab-ci.yml file:

  services:
    - name: mysql:8.0
      command: [ "--default-authentication-plugin=mysql_native_password" ]
lorisleiva commented 3 years ago

Nice, thanks for the update! Let me know if this suddenly becomes achievable without the workaround. 😊