dunglas / symfony-docker

A Docker-based installer and runtime for Symfony. Install: download and `docker compose up`.
https://dunglas.dev/2021/12/symfonys-new-native-docker-support-symfony-world/
2.59k stars 771 forks source link

Docker cache issue #216

Closed vasilvestre closed 11 months ago

vasilvestre commented 2 years ago

Today as I deployed, I had a problem with a dependency during cache warmup after upgrading to 6.0. Our dependency was updated in the source code but some layer issues made our service unusable until I stopped and remove the docker container. The production deployment guide may specify to use --no-cache in order to avoid this issue maybe? Otherwise, --force-recreate, I'm not sure as I solved it without docker-compose

Vandersteen commented 1 year ago

I've had the same issue. This was after installing a new dependency and 'redeploying' to prod. I'm starting to believe that this line is the culprit:

https://github.com/dunglas/symfony-docker/blob/9e5544753c1cad48f5e082e8b07f13b57b746744/Dockerfile#L99

The dependency was installed correctly, but the cached 'classmap' was out of wack.

I had to 'delete' the image and rebuild in order to fix it

In the 'version' I have, there is also a 'var' volume in the docker-compose.yml Which is not the same as the volume defined in the dockerfile.

One is 'known' at build time, while the other at 'run' time. (Which would explain why the var / vendor was out of wack)

For me, the solution would be to move the composer install / ... steps in the entrypoint

(See <----)

services:
  php:
    build:
      context: .
      target: symfony_php
      args:
        SYMFONY_VERSION: ${SYMFONY_VERSION:-}
        SKELETON: ${SKELETON:-symfony/skeleton}
        STABILITY: ${STABILITY:-stable}
    depends_on:
      - database
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
      - vendor:/srv/app/vendor <------
      - var:/srv/app/var <-------
...
...
...
volumes:
  php_socket:
  caddy_data:
  caddy_config:
###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###

###> doctrine/doctrine-bundle ###
  db-data:
###< doctrine/doctrine-bundle ###
  vendor: <------
  var: <-------

I think this was added in our repo for performance problems on windows / mac (and or it was there in previous versions of this repo). Haven't checked the latter

momen573 commented 1 year ago

Hello I have this issue when runing docker => CANCELED [app_caddy_builder 2/2] RUN xcaddy build --with github.com/dunglas/mercure --with github.com/dunglas/mercure/caddy -- 120.2s

ishu202 commented 1 year ago

Hello I have this issue when runing docker => CANCELED [app_caddy_builder 2/2] RUN xcaddy build --with github.com/dunglas/mercure --with github.com/dunglas/mercure/caddy -- 120.2s

I am assuming you are using older version of the Dockerfile. below snippet should work. `FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder

RUN xcaddy build \ --with github.com/dunglas/mercure/caddy \ --with github.com/dunglas/vulcain/caddy

FROM caddy:${CADDY_VERSION} AS symfony_caddy

WORKDIR /srv/app`

maxhelias commented 11 months ago

I've added a note about it here : https://github.com/dunglas/symfony-docker/pull/518