blueways/deployer-recipes

blueways 部署食谱

2.4.3 2024-05-10 08:09 UTC

README

此存储库包含基于sourcebroker/deployer-extended-typo3构建的第三方食谱。此包为常见的TYPO3基本扩展安装设置默认的部署者值。

此README包含配置TYPO3基本扩展以简化部署的示例。

1. 安装

composer require blueways/deployer-recipes

2. 修改 composer.json

您必须向您的 `composer.json` 添加一些行,以便动态读取Conf变量,并在每次部署时添加到扩展的符号链接。

  {
   "extra": {
      "helhum/dotenv-connector": {
         "env-file": ".env",
         "adapter": "Helhum\\DotEnvConnector\\Adapter\\SymfonyDotEnv"
      }
   },
   "scripts": {
      "typo3-cms-scripts": [
         "ln -sfn ../../../ public/typo3conf/ext/bw_myext"
      ],
      "post-autoload-dump": [
         "@typo3-cms-scripts"
      ]
   }
}

3. 创建 deploy.php

在您的项目根目录中创建一个 `deploy.php`。这是一个用于部署到Mittwald主机的简单配置文件。

<?php

namespace Deployer;

require_once(__DIR__ . '/vendor/blueways/deployer-recipes/autoload.php');

set('repository', 'git@bitbucket.org:blueways/bw_myext.git');

host('staging')
    ->set('hostname','p590044.mittwaldserver.info')
    ->set('labels', ['stage' => 'testing'])
    ->set('remote_user','p590044')
    ->set('branch', 'master')
    ->set('public_urls', ['https://staging.myext.de'])
    ->set('http_user', 'p590044')
    ->set('writable_mode', 'chmod')
    ->set('bin/composer', '/usr/local/bin/composer')
    ->set('bin/php', '/usr/local/bin/php')
    ->set('deploy_path', '/home/www/p590044/html/typo3-staging');

host('local')
     ->set('hostname','local')
    ->set('deploy_path', getcwd());

4. 创建 AdditinalConfiguration.php

此文件添加到 public/typo3conf/,以便从环境变量解析TYPO3_CONF_VARs。

5. 创建 .env

将此.env文件放在您的项目根目录中。它包含典型的ddev设置,这些设置将通过AdditionalConfiguration.php设置。这些设置覆盖了TYPO3的生产设置。

6. 添加文件到git

要放入git的文件

  • 
    
  • 
    
  • 
    
  • 
    
  • 
    
  • 
    

确保这些文件不与您的 .gitignore 匹配。要添加被排除的文件(如public目录内的文件),您可以使用以下命令

git add -f public/typo3conf/LocalConfiguration.php

6. (可选)配置您的deployer命令

请确保在ddev容器中运行`dep命令,例如,向您的~/.bashrc~/.zshrc`添加别名

alias dep="ddev exec vendor/bin/dep"

7. 准备主机机器

准备输入数据库凭据和配置域名。

要创建远程主机上的文件夹结构和配置,请运行

dep deploy:prepare:typo3 staging

遵循向导。如果有错误(例如主机上缺少软件),请修复问题并重新运行命令。

现在将域路径(在`public_urls`中配置的)更改为工作目录。路径由向导打印出来。激活SSL。

8. 部署

现在您可以使用以下命令创建您的第一个部署

dep deploy-fast staging

9. 导入数据库或从头开始

您基本上完成了。现在您可以选择是否要导入您现有的本地数据库

dep db:push staging

或者通过添加管理员用户从头开始

dep config:createadmin staging

10. 配置远程实例

如果您通过Install Tool配置远程TYPO3安装,请确保将更改添加到git存储库。要下载对LocalConfiguration.php所做的更改,请使用以下命令

dep config:pull staging

如果这些更改破坏了您的本地安装,只需在您的本地.env文件中覆盖设置即可。

默认值

此包为各种设置设置默认值。

设置
web_pathpublic/
file_backup_packagesfileadmin, uploads(排除 _processed__temp_
file_backup_keep1

食谱

  • db:backup:rsync
  • file:backup:rsync
  • config:pull
  • slack:notify
  • deploy:prepare:typo3
  • deploy-fast
  • file:backup

db:backup:rsync

将数据库备份通过rsync同步到远程主机。

file:backup:rsync

将文件备份通过rsync同步到远程主机

设置默认值
backup_storage_db_keep10
backup_storage_file_keep3

config:pull

从远程实例下载到本地实例的LocalConfiguration.php

slack:notify

在生产部署时通知Slack频道。

包含多个slack配置以删除废弃的仓库(将来可能会更改)。要添加webhook到您的slack频道,请访问此页面并点击“添加到Slack”。

deploy:prepare:typo3

配置主机机器以部署TYPO3基础扩展

  • 可以将SSH密钥添加到远程机器
  • 检查软件依赖项
  • 添加git仓库的rsa指纹
  • 检查正确的仓库访问权限
  • 交互式创建带有数据库凭据的远程.env文件
  • 为域名配置创建所需的文件夹结构

deploy-fast

不幸的是,此包必须覆盖sourcebroker/deployer-extended-typo3中的deploy-fast任务。这样做是为了改变命令顺序,以防止初始部署时发生异常。

希望这将在将来改变。讨论可以在这里找到。

file:backup

此配方覆盖了sourcebroker/deployer-extended中的file:backup命令和file_backup_path变量,因为它无法创建本地备份,这对于我们的rsync是必需的。

此更改的pull request仍然开放

示例

自动备份

  1. deployer.php中添加备份主机

     host('hidrive')
         ->hostname('username@hidrive.strato.com')
         ->set('deploy_path', '/home/backup/projectX')
         ->roles('backup_storage');
    
  2. bitbucket-pipeline.yml中添加自定义流水线

     definitions:
       steps:
         - step: &checkout-master
             name: Checkout master branch
             image: atlassian/default-image:2
             artifacts:
               - .git/**
             script:
               - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
               - git fetch origin
               - git checkout master
         - step: &install-deployer
             name: Install deployer
             image: composer:latest
             caches:
               - composer
             artifacts:
               - vendor/**
               - public/**
               - .env
             script:
               - composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs
        
     pipelines:
       custom:
         backup:
           - step: *checkout-master
           - step: *install-deployer
           - step:
               image: drud/ddev-webserver:v1.17.6
               name: Backup database and rsync to HiDrive
               script:
                 - phpdismod xdebug
                 - ./vendor/bin/dep db:backup production --no-interaction
                 - ./vendor/bin/dep db:backup:rsync production --no-interaction
                 - ./vendor/bin/dep file:backup production --no-interaction
                 - ./vendor/bin/dep file:backup:rsync production --no-interaction
    
  3. 注册新的调度器

    pipeline example