tobybatch / kimai2

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

[BUG] 500 Error - Missing class in latest docker image (2.5.0) #562

Closed piyushpaliwal closed 6 months ago

piyushpaliwal commented 7 months ago

Describe the bug After upgrade to 2.5.0, getting presented with 500 server error and the logs show missing classes with kimai/kimai2:apache image

[2023-12-02 18:49:13] [php] WARNING: Warning: include_once(/opt/kimai/src/EventSubscriber/MenuFavoritesSubscriber.php): Failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): Warning: include_once(/opt/kimai/src/EventSubscriber/MenuFavoritesSubscriber.php): Failed to open stream: No such file or directory at /opt/kimai/var/cache/prod/Container0FYnymF/getMenuFavoritesSubscriberService.php:20)"} []

[2023-12-02 18:49:13] [php] WARNING: Warning: include_once(): Failed opening '/opt/kimai/src/EventSubscriber/MenuFavoritesSubscriber.php' for inclusion (include_path='.:/usr/local/lib/php') {"exception":"[object] (ErrorException(code: 0): Warning: include_once(): Failed opening '/opt/kimai/src/EventSubscriber/MenuFavoritesSubscriber.php' for inclusion (include_path='.:/usr/local/lib/php') at /opt/kimai/var/cache/prod/Container0FYnymF/getMenuFavoritesSubscriberService.php:20)"} []

[2023-12-02 18:49:13] [php] CRITICAL: Uncaught Error: Class "App\EventSubscriber\MenuFavoritesSubscriber" not found {"exception":"[object] (Error(code: 0): Class \"App\\EventSubscriber\\MenuFavoritesSubscriber\" not found at /opt/kimai/var/cache/prod/Container0FYnymF/getMenuFavoritesSubscriberService.php:28)"} []

[2023-12-02 18:49:13] [request] CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "MenuFavoritesSubscriber" from namespace "App\EventSubscriber". Did you forget a "use" statement for another namespace?" at /opt/kimai/var/cache/prod/Container0FYnymF/getMenuFavoritesSubscriberService.php line 28 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\ClassNotFoundError(code: 0): Attempted to load class \"MenuFavoritesSubscriber\" from namespace \"App\\EventSubscriber\".\nDid you forget a \"use\" statement for another namespace? at /opt/kimai/var/cache/prod/Container0FYnymF/getMenuFavoritesSubscriberService.php:28)"} []

To Reproduce Pull latest kimai/kimai2:apache image from docker hub and run the kimai container with it.

Desktop (please complete the following information):

Command used to run the container

Docker compose file (with passwords redacted)

version: '3.5'
services:
  sqldb:
    image: mysql:5.7
    container_name: kimai-mysql
    user: "1000:1000"
    networks:
      - proxy
    environment:
      - MYSQL_DATABASE=${KIMAI_DB_NAME}
      - MYSQL_USER=${KIMAI_MYSQL_USER}
      - MYSQL_PASSWORD=${KIMAI_MYSQL_PASSWORD}
      - MYSQL_ROOT_PASSWORD=${KIMAI_MYSQL_ROOT_PASSWORD}
    ports:
      - 3336:3306
    volumes:
      - ${HOME}/Docker/kimai-mysql:/var/lib/mysql
      - ${HOME}/Docker/kimai-sql-dump:/tmp/dumps
    command: --default-storage-engine innodb
    restart: unless-stopped
    healthcheck:
      test: mysqladmin -p${KIMAI_MYSQL_ROOT_PASSWORD} ping -h localhost
      interval: 20s
      start_period: 10s
      timeout: 10s
      retries: 3
    labels:
      - docker-volume-backup.archive-pre=/bin/sh -c 'mysqldump --single-transaction --no-tablespaces -u ${KIMAI_MYSQL_USER} -p{KIMAI_MYSQL_PASSWORD} kimai > /tmp/dumps/kimai-`date +%F_%H-%M`.sql'
  kimai:
    image: kimai/kimai2:apache
    container_name: kimai
    user: "1000:1000"
    networks:
      - proxy
    environment:
      - ADMINMAIL=${KIMAI_ADMIN_EMAIL}
      - ADMINPASS=${KIMAI_ADMIN_PASSWORD}
      - DATABASE_URL=${KIMAI_DB_CONNECTIONSTRING}
      - TRUSTED_HOSTS=nginx,localhost,127.0.0.1
      - memory_limit=512m
    ports:
      - 8001:8001
    volumes:
      - ${HOME}/Docker/kimai/kimai-public:/opt/kimai/public
      - ${HOME}/Docker/kimai/var:/opt/kimai/var
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.kimai.entrypoints=http"
      - "traefik.http.routers.kimai.rule=Host(`#`)"
      - "traefik.http.middlewares.kimai-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.kimai.middlewares=kimai-https-redirect"
      - "traefik.http.routers.kimai-secure.entrypoints=https"
      - "traefik.http.routers.kimai-secure.rule=Host(`#`)"
      - "traefik.http.routers.kimai-secure.tls=true"
      - "traefik.http.routers.kimai-secure.service=kimai"
      - "traefik.http.services.kimai.loadbalancer.server.port=8001"
      - "traefik.http.services.kimai.loadbalancer.server.scheme=http"
      - "traefik.http.services.kimai.loadbalancer.passHostHeader=true"
      - "traefik.docker.network=proxy"

  backup:
    image: offen/docker-volume-backup:latest
    container_name: kimai-backup
    networks:
      - proxy
    restart: unless-stopped
    environment:
      - BACKUP_COMPRESSION=gz
      - GZIP_PARALLELISM=10
      - BACKUP_FILENAME=kimai-backup-%Y-%m-%d.tz
      - BACKUP_CRON_EXPRESSION=0 0 * * *
      - BACKUP_RETENTION_DAYS=7
      - EXEC_FORWARD_OUTPUT=true
    volumes:
      - ${HOME}/Docker/kimai-sql-dump:/backup/kimai/kimai-sql-dump
      - ${HOME}/Docker/kimai/var:/backup/kimai/var:ro
      - ${HOME}/backups/kimai:/archive
      - /var/run/docker.sock:/var/run/docker.sock
networks:
  proxy:
    external: true
kevinpapst commented 7 months ago

Clear cache & restart.

@tobybatch why is that happening? the old cache is used on a new codebase. can we flush the cache during docker restart?

piyushpaliwal commented 7 months ago

I remember doing that but to no avail. In any case, let me try again.

Edit: Yes indeed, tried clearing the cache and it works. Feel free to close the ticket if you are discussing root cause of this somewhere else.

tobybatch commented 6 months ago

We call