diff --git a/.dockerignore b/.dockerignore index 63855c1d..776b9a12 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,6 +11,7 @@ runtime JetBrainsMono-字体 node_modules vendor +bootstrap/cache/* .caiwu-build public/js public/css/app.css diff --git a/scripts/deploy-from-workstation.ps1 b/scripts/deploy-from-workstation.ps1 index 0021d8c2..8c547b09 100644 --- a/scripts/deploy-from-workstation.ps1 +++ b/scripts/deploy-from-workstation.ps1 @@ -346,6 +346,11 @@ try { . } '本机镜像构建失败。服务器未发生任何变更。' + # 在无网络、无生产配置的临时容器中引导 Laravel,拦截开发包缓存混入镜像。 + Invoke-Native { + docker run --rm --network none --user www-data --entrypoint php $fullImage artisan --version + } '发布镜像无法引导 Laravel。服务器未发生任何变更。' + $previousShaOutput = @(& ssh -i $keyFullPath -o BatchMode=yes -o StrictHostKeyChecking=accept-new $sshTarget "cat '$RemotePath/.deployed-sha' 2>/dev/null || true") $previousSha = ($previousShaOutput -join "`n").Trim() if ($LASTEXITCODE -ne 0) { diff --git a/tests/Unit/Deployment/ProductionBuildCachePolicyTest.php b/tests/Unit/Deployment/ProductionBuildCachePolicyTest.php index 4a27d66b..b07dfcca 100644 --- a/tests/Unit/Deployment/ProductionBuildCachePolicyTest.php +++ b/tests/Unit/Deployment/ProductionBuildCachePolicyTest.php @@ -6,6 +6,17 @@ use Tests\TestCase; class ProductionBuildCachePolicyTest extends TestCase { + public function testReleaseExcludesLocalBootstrapCachesAndBootsBeforeProductionAccess(): void + { + $ignore = file_get_contents(base_path('.dockerignore')); + $this->assertContains('bootstrap/cache/*', preg_split('/\R/', $ignore)); + $script = file_get_contents(base_path('scripts/deploy-from-workstation.ps1')); + $smoke = strpos($script, 'docker run --rm --network none --user www-data --entrypoint php $fullImage artisan --version'); + $remote = strpos($script, '$previousShaOutput ='); + $this->assertNotFalse($smoke); + $this->assertLessThan($remote, $smoke); + } + public function testProductionDockerfilePinsBaseImagesAndRetriesExternalDownloads(): void { $dockerfile = file_get_contents(base_path('deploy/Dockerfile'));