0

在一个 TYPO3 项目中,我正在工作的 Production/Staging(或 Production/Dev,或任何其他)环境受 HTTP BasicAuth(基本访问身份验证)保护。

实例通过typo3/surf部署。

  1. 在某些时候,typo3/surf 必须创建一个临时 php 文件,该文件可以访问
  2. 稍后:在切换完成并且可以通过前端访问新部署之后。

如何配置typo3/surf以在BasicAuth 受保护的环境中通过前端访问先前生成的OPcache 清除脚本?

4

1 回答 1

2

配置typo3/surf 以重置PHP OPcache 1

配置 OPcache 清除/重置脚本基本上需要四个步骤:

  1. 设置任务选项\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask
  2. \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask在早期阶段添加任务(例如package但绝对在之前transfer
  3. 设置任务选项\TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask
  4. \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask阶段后添加任务switch

以下是部署配置脚本中 onInitialize 函数2的必要片段:

为“创建脚本任务”设置任务选项:

由于“尊重 WebDirectory”补丁,脚本的路径不能手动配置,因为它会自动使用正确的 WebDirectory 路径(通过预先选项设置)。

如果您使用的是较旧的typo3/surf 版本,或者您有任何特殊要求,您可以设置选项scriptBasePath来设置生成文件的绝对路径:

# In this example, I have to set the absolute path for the resulting php file.
# Since the deployment run in GitLab CI I get the path to the root of the project's GIT
# repository via the environment variable `CI_PROJECT_DIR`. Since the path to the webDirectory
# inside the GIT repository is `<GitRepoRootFOlder>/app/web` I add it manually and concatenate
# it as final string for the option `scriptBasePath`:
$workflow->setTaskOptions(\TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, [
    'scriptBasePath' => \TYPO3\Flow\Utility\Files::concatenatePaths([getenv('CI_PROJECT_DIR'), '/app/web']),
]);

为“执行任务”设置任务选项:

此时,我们提供用户名和密码

$workflow->setTaskOptions('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask', [
    'baseUrl' => $application->getOption('baseUrl'),
    'stream_context' => [
        'http' => [
            'header' => 'Authorization: Basic '.base64_encode("username:password"),
        ],
    ],
]);

激活两个任务:

$workflow->beforeStage('transfer', \TYPO3\Surf\Task\Php\WebOpcacheResetCreateScriptTask::class, $application)
    ->afterStage('switch', \TYPO3\Surf\Task\Php\WebOpcacheResetExecuteTask::class, $application);

这个答案只显示了 OPcache 重置过程的必要部分!

另请查看官方文档中的TYPO3 CMS 部署配置示例


脚注

1 这个答案基于typo3/surf GIT branch dev-master, version 2.x

2放置上述片段的示例:

$deployment->onInitialize(function () use ($deployment, $application) {
    /** @var SimpleWorkflow $workflow */
    $workflow = $deployment->getWorkflow();

    # the mentioned snippets have to be placed next to your existing configuration

});
于 2019-02-14T09:50:01.320 回答