Skip to content

Add config option to ignore view cache timestamps #55536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025

Conversation

pizkaz
Copy link
Contributor

@pizkaz pizkaz commented Apr 24, 2025

When running in a read-only filesystem container with views pre-cached at build time, Laravel checks if the cached view's timestamp is older than the source's to decide when to recompile. This is fine as long as we do not make OCI image builds reproducible.
If we do however, the timestamps match (because timestamps of all files are set to 01.01.1970), so Laravel recompiles the view, tries to write to a read-only filesystem and the container crashes.

This patch introduces a new config option view.ignore_cache_timestamps which does exactly what the name suggests.

This renders #55450 and #55517 obsolete, at least for the scenario described above.

@pizkaz pizkaz force-pushed the impr/ignore-view-cache-timestamps branch 5 times, most recently from 87d75ca to 471cb52 Compare April 24, 2025 11:33
@pizkaz
Copy link
Contributor Author

pizkaz commented Apr 24, 2025

Hmm, why does my unit test fail? Even better: How can I run phpunit locally to debug it?
Patching docker-compose.yml like this

 version: '3'
 services:
+  phpunit:
+    image: php:8.3-alpine
+    environment:
+      DB_PORT: 3306
+      DB_USERNAME: root
+      DYNAMODB_CACHE_TABLE: laravel_dynamodb_test
+      DYNAMODB_ENDPOINT: "http://localhost:8888"
+      AWS_ACCESS_KEY_ID: randomKey
+      AWS_SECRET_ACCESS_KEY: randomSecret
+    entrypoint: >
+      sh -exc '
+        mkdir -p /opt/laravel/framework;
+        cd /opt/laravel/framework;
+        apk add --no-cache composer php83-dom php83-fileinfo php83-ftp php83-gmp php83-session php83-simplexml php83-tokenizer php83-xml php83-xmlwriter;
+        composer config version "12.x-dev"
+        composer install;
+        exec "$@"
+      ' "$@"
+    command: vendor/bin/phpunit --display-deprecation --fail-on-deprecation
+    volumes:
+      - .:/opt/laravel/framework
   dynamodb:
     image: amazon/dynamodb-local:2.0.0
     ports:

and running it gives me:

phpunit-1    | + exec vendor/bin/phpunit --display-deprecation --fail-on-deprecation
phpunit-1    |
phpunit-1    |
phpunit-1    | An error occurred inside PHPUnit.
phpunit-1    |
phpunit-1    | Message:  Undefined constant PDO::MYSQL_ATTR_SSL_CA
phpunit-1    | Location: /opt/laravel/framework/tests/Database/DatabaseMariaDbSchemaStateTest.php:66
phpunit-1    |
phpunit-1    | #0 /opt/laravel/framework/vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php(157): Database\DatabaseMariaDbSchemaStateTest::provider()
phpunit-1    | #1 /opt/laravel/framework/vendor/phpunit/phpunit/src/Metadata/Api/DataProvider.php(53): PHPUnit\Metadata\Api\DataProvider->dataProvidedByMethods('Database\\Databa...', 'provider', Object(PHPUnit\Metadata\MetadataCollection))
phpunit-1    | #2 /opt/laravel/framework/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(47): PHPUnit\Metadata\Api\DataProvider->providedData('Database\\Databa...', 'testConnectionS...')
phpunit-1    | #3 /opt/laravel/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(503): PHPUnit\Framework\TestBuilder->build(Object(ReflectionClass), 'testConnectionS...', Array)
phpunit-1    | #4 /opt/laravel/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(109): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod), Array)
phpunit-1    | #5 /opt/laravel/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(203): PHPUnit\Framework\TestSuite::fromClassReflector(Object(ReflectionClass), Array)
phpunit-1    | #6 /opt/laravel/framework/vendor/phpunit/phpunit/src/Framework/TestSuite.php(224): PHPUnit\Framework\TestSuite->addTestSuite(Object(ReflectionClass), Array)
phpunit-1    | #7 /opt/laravel/framework/vendor/phpunit/phpunit/src/TextUI/Configuration/Xml/TestSuiteMapper.php(105): PHPUnit\Framework\TestSuite->addTestFile('/opt/laravel/fr...', Array)
phpunit-1    | #8 /opt/laravel/framework/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(75): PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper->map('/opt/laravel/fr...', Object(PHPUnit\TextUI\Configuration\TestSuiteCollection), '', '')
phpunit-1    | #9 /opt/laravel/framework/vendor/phpunit/phpunit/src/TextUI/Application.php(418): PHPUnit\TextUI\Configuration\TestSuiteBuilder->build(Object(PHPUnit\TextUI\Configuration\Configuration))
phpunit-1    | #10 /opt/laravel/framework/vendor/phpunit/phpunit/src/TextUI/Application.php(181): PHPUnit\TextUI\Application->buildTestSuite(Object(PHPUnit\TextUI\Configuration\Configuration))
phpunit-1    | #11 /opt/laravel/framework/vendor/phpunit/phpunit/phpunit(104): PHPUnit\TextUI\Application->run(Array)
phpunit-1    | #12 /opt/laravel/framework/vendor/bin/phpunit(122): include('/opt/laravel/fr...')
phpunit-1    | #13 {main}
phpunit-1 exited with code 255

Surely there is a less painful way to run unit tests locally. 😄 What am I missing?
The Contribution Guide does not say anything about unit testing.

@pizkaz pizkaz force-pushed the impr/ignore-view-cache-timestamps branch from 471cb52 to 191271a Compare April 24, 2025 12:08
@pizkaz
Copy link
Contributor Author

pizkaz commented Apr 24, 2025

Got it. I copied a faulty constructor call. That poses the question why the test I copied and adapted is working. 🤔

@pizkaz pizkaz force-pushed the impr/ignore-view-cache-timestamps branch from a282a0f to a17289c Compare April 24, 2025 12:34
@pizkaz
Copy link
Contributor Author

pizkaz commented Apr 24, 2025

Fixed. \o/

@taylorotwell taylorotwell merged commit 5dea84f into laravel:12.x Apr 24, 2025
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants