I have a Symfony application that's containerized.
The last step of the process is to warm up the cache, so that the image can be used "as is". While the command works apparently fine, the end result is that there are two cache directories for the environment, one with the right name, and another with a tilde (~).
root@c238674823ae:/app/var/cache# ls -la
total 0
drwxr-xr-x 1 root root 16 Jan 2 11:46 .
drwxr-xr-x 1 root root 72 Jan 2 11:46 ..
drwxr-xr-x 1 root root 146 Jan 2 11:46 prod
drwxr-xr-x 1 root root 146 Jan 2 11:46 pro~
Some directories are missing within the cache directory with the "right" name, which make the application fail.
These are the Dockerfile steps where the cache is warmed up:
ENV COMPOSER_MEMORY_LIMIT=-1
RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload -o --apcu --no-dev; \
composer dump-env prod; \
chmod +x bin/console; sync;
RUN set eux; \
rm -rf var/cache/* && \
bin/console cache:clear && \
bin/console assets:install public && \
bin/console importmap:install && \
bin/console sass:build -v && \
bin/console asset-map:compile;
If I manually do rm -rf var/cache/prod && mv var/cache/pro~ var/cache/prod
, the application works normally... but I'm afraid of relying on this, since this does not seem normal or expected behavior.
If, after the application is up and running, I run bin/console cache:clear
, now the application works, but that requires us to run a command after deploying the new image, leading for a couple seconds downtime each deployment, which is undesirable.
Why doesn't the cache:clear
command finish correctly? Why, if it didn't finish correctly, exited without error?
And now something silly. If I do this (running cache:clear
twice):
RUN set eux; \
rm -rf var/cache/* && \
bin/console cache:clear && \
bin/console cache:clear && \
bin/console assets:install public && \
bin/console importmap:install && \
bin/console sass:build -v && \
bin/console asset-map:compile;
now it works, and there is a single cache directory :(
docker run -it web-api/env-prod:local ls -la var/cache
total 0
drwxr-xr-x 1 root root 8 Jan 2 12:11 .
drwxr-xr-x 1 root root 72 Jan 2 12:11 ..
drwxr-xr-x 1 root root 170 Jan 2 12:11 prod
I have a Symfony application that's containerized.
The last step of the process is to warm up the cache, so that the image can be used "as is". While the command works apparently fine, the end result is that there are two cache directories for the environment, one with the right name, and another with a tilde (~).
root@c238674823ae:/app/var/cache# ls -la
total 0
drwxr-xr-x 1 root root 16 Jan 2 11:46 .
drwxr-xr-x 1 root root 72 Jan 2 11:46 ..
drwxr-xr-x 1 root root 146 Jan 2 11:46 prod
drwxr-xr-x 1 root root 146 Jan 2 11:46 pro~
Some directories are missing within the cache directory with the "right" name, which make the application fail.
These are the Dockerfile steps where the cache is warmed up:
ENV COMPOSER_MEMORY_LIMIT=-1
RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload -o --apcu --no-dev; \
composer dump-env prod; \
chmod +x bin/console; sync;
RUN set eux; \
rm -rf var/cache/* && \
bin/console cache:clear && \
bin/console assets:install public && \
bin/console importmap:install && \
bin/console sass:build -v && \
bin/console asset-map:compile;
If I manually do rm -rf var/cache/prod && mv var/cache/pro~ var/cache/prod
, the application works normally... but I'm afraid of relying on this, since this does not seem normal or expected behavior.
If, after the application is up and running, I run bin/console cache:clear
, now the application works, but that requires us to run a command after deploying the new image, leading for a couple seconds downtime each deployment, which is undesirable.
Why doesn't the cache:clear
command finish correctly? Why, if it didn't finish correctly, exited without error?
And now something silly. If I do this (running cache:clear
twice):
RUN set eux; \
rm -rf var/cache/* && \
bin/console cache:clear && \
bin/console cache:clear && \
bin/console assets:install public && \
bin/console importmap:install && \
bin/console sass:build -v && \
bin/console asset-map:compile;
now it works, and there is a single cache directory :(
docker run -it web-api/env-prod:local ls -la var/cache
total 0
drwxr-xr-x 1 root root 8 Jan 2 12:11 .
drwxr-xr-x 1 root root 72 Jan 2 12:11 ..
drwxr-xr-x 1 root root 170 Jan 2 12:11 prod
I think you forget add php
before all the bin/console
commands:
RUN APP_ENV=prod php bin/console cache:clear --no-warmup && \
APP_ENV=prod php bin/console assets:install public && \
APP_ENV=prod php bin/console importmap:install && \
APP_ENV=prod php bin/console sass:build -v && \
APP_ENV=prod php bin/console asset-map:compile
composer dump-env
? – Julien B. Commented Jan 2 at 13:36cache:clear
will do a cache warmup unless a--no-warmup
flag is passed. since the cache directory is empty, callingcache:clear
will warm up the cache. – vudvudvud12 Commented Jan 2 at 13:38composer-dump
env, see this symfony.com/doc/current/…, but it's not really important for this question I think. can be removed for the same effect, it's there here only so the code is complete – vudvudvud12 Commented Jan 2 at 13:42rm -rf var/cache/*
? Shouldn't your folder be already empty? – Julien B. Commented Jan 2 at 13:46rm -rf
so that it's clear on the question the directory is completely empty. It's a no-op, but I was hoping to avoid follow up questions like "are you sure the directory/cache are actually empty??". ;) – vudvudvud12 Commented Jan 2 at 13:48