tobybatch / kimai2

Docker containers for the kimai2 web application including docker-compose and kubernetes/helm deployment.
MIT License
181 stars 96 forks source link

[BUG] composer require symfony/sendgrid-mailer fails #563

Closed amammes closed 11 months ago

amammes commented 11 months ago

Hi, I am trying to add sendgrid support and kimai instructions say that I need to add the symfony/sendgrid-mailer package. However, "composer require symfony/sendgrid-mailer" fails with the following output:

root@d06b1d3c4ad0:/var/www/html# cd /opt/kimai
root@d06b1d3c4ad0:/opt/kimai# composer require symfony/sendgrid-mailer

In ArtifactRepository.php line 76:

  RecursiveDirectoryIterator::__construct(var/packages/): Failed to open directory: No such file or directory  

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>...]

I checked out /opt/kimai/composer.json and it has the following repository which does not exist on the file system.

"repositories": [
        {
            "type": "artifact",
            "url": "var/packages/"
        }
    ],

I am sorry but I am not experienced in php and much less with composer parameters, but I believe the repository path is incorrect in /opt/kimai/composer.json

Desktop (please complete the following information):

Server: Docker Engine - Community Engine: Version: 24.0.7 API version: 1.43 (minimum version 1.12) Go version: go1.20.10 Git commit: 311b9ff Built: Thu Oct 26 09:08:02 2023 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.25 GitCommit: d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f runc: Version: 1.1.10 GitCommit: v1.1.10-0-g18a0cb0 docker-init: Version: 0.19.0 GitCommit: de40ad0


**Command used to run the container**
docker compose up -d

**Docker compose file (with passwords redacted)**

version: '3.5' services:

mysql: image: mysql:5.7 container_name : kimai1-mysql environment:

networks: nginx-proxy-manager_default: external: true default:

amammes commented 11 months ago

Fixed by adding

"repositories": [
    {
        "type": "composer",
        "url": "https://repo.packagist.org"
    }
],
kevinpapst commented 11 months ago

You could just create the directory /opt/kimai/var/packages/

You do not need these mailer packages. They just "simplify" how to setup the MAILER DSN.

kevinpapst commented 11 months ago

@tobybatch any idea why the directory is missing? It is in git: https://github.com/kimai/kimai/tree/main/var/packages

amammes commented 11 months ago

This is what I see in my container based on image: kimai/kimai2:apache

root@71ce333c1353:/opt/kimai/var# ls -la total 24 drwxr-xr-x 5 www-data www-data 4096 Dec 4 23:08 . drwxr-xr-x 1 www-data www-data 4096 Dec 5 14:45 .. drwxr-xr-x 3 www-data www-data 4096 Dec 5 14:46 cache drwxr-xr-x 2 www-data www-data 4096 Dec 4 23:08 data -rw-r--r-- 1 www-data www-data 6 Dec 5 14:41 installed drwxr-xr-x 2 www-data www-data 4096 Dec 4 22:58 log

amammes commented 11 months ago

The kimai documentation says this, but does not give an example for Sendgrid. I tried several configs, none of them worked.

Be aware that you can achieve the same in most cases (without installing composer packages) by rewriting the MAILER_URL, e.g.:

Gmail: smtps://{username}:{password}@smtp.gmail.com:465 Sendinblue: smtps://{username}:{password}@smtp-relay.sendinblue.com:465

amammes commented 11 months ago

mkdir /opt/kimai/var/packages solved the composer require error. Thanks, all is working now with some manual intervention

tobybatch commented 11 months ago
  kimai:
    image: kimai/kimai2:apache
    container_name : kimai1-kimai
    volumes:
      - ./kimai/var:/opt/kimai/var
    ports:
      - 8022:22

Here you mount the entire var directory in to the image. This means that dir will be empty when the container starts. You want to look at bind mounts instead

https://docs.docker.com/storage/bind-mounts/

kevinpapst commented 11 months ago

Usually you shouldn't use composer inside the container anyway... But is that something for the docs?

amammes commented 11 months ago

@tobybatch thanks for the tip about the volume. You were right, I was screwing up the container by mounting var like that.

@kevinpapst you are correct about "composer require" or "composer update" from inside the container screwing up the container. The file permissions leave a broken kimai instance.

@kevinpapst you are also correct that Sendgrid doesn't need extra packages. I set it up like this and it worked fine: MAILER_URL=smtps://apikey:redacted_apikey_goes_here@smtp.sendgrid.net:465