digipolisgent/robo-digipolis-helpers

创建基本部署流程的助手。

安装数: 53,521

依赖: 4

建议者: 0

安全: 0

星星: 0

关注者: 12

分支: 2

公开问题: 2

类型:robo-tasks


README

Latest Stable Version Latest Unstable Version Total Downloads License

Build Status Maintainability Test Coverage

由 digipolis 使用,通用的命令/骨架用于执行环境间的部署和同步。

入门

为了让此包了解您的数据库配置,请阅读[robo-digipolis-deploy 包的文档] (https://github.com/district09/robo-digipolis-deploy#use-events-for-default-configuration)。

我们做了一些假设,其中大多数都可以被覆盖。有关所有默认值,请参阅default.properties.yml,以及有关所有可用配置选项的properties.yml 文档

默认情况下,我们假设服务器上有一个类似于 capistrano 的目录结构

├── ~/apps/[app]/current -> ~/apps/[app]/releases/20150120114500/
├── ~/apps/[app]/releases
│   ├── 20150080072500
│   ├── 20150090083000
│   ├── 20150100093500
│   ├── 20150110104000
│   └── 20150120114500

此包提供了一些命令。您可以使用 vendor/bin/robo listvendor/bin/robo help [command] 来了解它们的功能。最重要的是,这些命令遵循一个“骨架”,其中每个命令步骤都会触发一个事件,事件监听器返回一个 EventHandlerWithPriority。此包提供的默认事件监听器位于 DigipolisHelpersDefaultHooksCommands 类中。该类中的每个方法都是事件监听器,并返回一个事件处理器。此包提供的默认处理器可在 src/EventHandler/DefaultHandler 中找到。如果您想覆盖或更改命令中某个步骤的行为,您只需使用为正确的事件创建事件监听器,并让它返回您自定义的处理程序。处理器按优先级顺序执行(数字越小优先级越高),默认处理器的优先级为 999。如果您的处理器在其 handle 方法中调用 $event->stopPropagation(),则后续的处理器将不会执行。有关更多信息,请参阅可用事件列表;

properties.yml

您还需要在项目根目录中提供一个 properties.yml 文件,以便脚本知道要创建哪些符号链接,将备份放在哪里,等等。

以下是一些合理的默认设置示例

remote:
  # The application directory where your capistrano folder structure resides.
  appdir: '/home/[user]/apps/[app]'
  # The releases directory where to deploy new releases to.
  releasesdir: '${remote.appdir}/releases'
  # The root directory of a new release.
  rootdir: '${remote.releasesdir}/[time]'
  # The web directory of a new release (where e.g. your index.php file resides).
  webdir: '${remote.rootdir}/public'
  # The directory of your current release (your web root). Usually a symlink,
  # see `symlinks` below.
  currentdir: '${remote.appdir}/current'
  # The directory where your config files reside. This should get symlinked to
  # since your config files are normally not in your git repository, and shared
  # across releases. See `symlinks` below.
  configdir: '${remote.appdir}/config'
  # Your files directory that is used to store files uploaded by end-users. This
  # should get symlinked to since the uploaded files are shared across releases.
  # See `symlinks` below.
  filesdir: '${remote.appdir}/files'
  # Whether or not to create a backup (and corresponding restore task on
  # rollback during deploy.
  createbackup: true
  # The folder where to store backups that are created before running updates.
  backupsdir: '${remote.appdir}/backups'
  # The symlinks to create when deploying, in format target:link
  symlinks:
    # Symlink the webdir of the release we're creating to the current directory.
    - '${remote.webdir}:${remote.currentdir}'
    # Symlink the config file from within our config directory to the config of
    # our current release.
    - '${remote.configdir}/config.php:${remote.rootdir}/config/config.php'
  # After a successful release, older releases are removed from
  # ${remote.releasesdir}. This value determines how many past releases we
  # should keep.
  cleandir_limit: 5
  # To save some space/inodes on your server you can choose to compress the
  # older releases that are not being removed. This way they are still available
  # if you need to do a manual rollback, but don't take up as much space/inodes.
  compress_old_releases: false
  # We allow overriding settings under the `remote` key in properties.yml by
  # environment. This means we need to have a reliable way to determine which
  # environment we're currently on. We use the value of an environment variable
  # to determine the environment. This variable defaults to HOSTNAME.
  environment_env_var: HOSTNAME
  # We use an environment matcher to match the value of the environment variable
  # mentioned above, to the overrides that need to be applied (see
  # `environment_overrides` below. This needs to be a PHP callable, and defaults
  # to `\DigipolisGent\Robo\Helpers\Util\EnvironmentMatcher::regexMatch` to
  # match the value by using a regular expression.
  # `\DigipolisGent\Robo\Helpers\Util\EnvironmentMatcher::literalMatch` is also
  # available to match by a literal value. You can of course also implement your
  # own.
  environment_matcher: '\DigipolisGent\Robo\Helpers\Util\EnvironmentMatcher::regexMatch'
  # Here you can specify the overrides per evironment. This example uses the
  # default regex matcher.
  environment_overrides:
    # List your overrides here.
    # The keys will be matched against the value of `environment_env_var` via
    # `environment_matcher`.
    # The default properties use regexMatch and thus the keys here are PCRE
    # regexes.
    # The values per key can be anything set in `remote` and will override that
    # setting.
    # All matches are used (top to bottom).
    ^qa:
      cleandir_limit: 3
    ^staging:
      cleandir_limit: 2
# We use the phpseclib library to execute our ssh commands. Their default
# timeout is 10 seconds. Some tasks take longer than that, so we make the
# timeouts configurable. Below are the configurable timeouts. The values used in
# this example are the defaults, meaning that if you don't add them to your
# properties.yml, these are the values that will be used.
timeouts:
  # When we symlink a directory, but it already exists as a directory where we
  # are going to put the symlink, we mirror that directory to the target before
  # removing it and replacing it with the symlink. This is the timeout for the
  # mirroring of such a directory.
  presymlink_mirror_dir: 60
  # We provide a task for syncing database and files between
  # servers/environments. This is the timeout for the rsync command to sync the
  # files in ${remote.filesdir}.
  synctask_rsync: 1800
  # The timeout to create a backup of ${remote.filesdir}.
  backup_files: 300
  # The timeout to create a database backup.
  backup_database: 300
  # The timeout to remove a backup of both files and database (during sync, a
  # backup is created, restored on the destination and then removed from the
  # source).
  remove_backup: 300
  # The timeout to restore a files backup.
  restore_files_backup: 300
  # The timeout to restore a database backup.
  restore_db_backup: 60
  # Before a files backup is restored, the current files are removed. This is
  # the timeout for removing those files.
  pre_restore: 300
  # See ${remote.cleandir_limit}. This is the timeout for that operation.
  clean_dir: 30

如您所见,您可以使用以下表示法从 properties.yml 中引用值:${path.to.property}。还有其他可用的标记

[user]          The ssh user we used to connect to the server.
[private-key]   The path to the private key that was used to connect to the
                server.
[time]          New releases are put in a folder with the current timestamp as
                folder name. This is that timestamp.
[app]           The name of the app that is being deployed.

可用事件列表

可以使用 $event->getArgument($argumentName); 获取事件参数

digipolis:backup-remote

此事件的处理器应返回一个任务,该任务根据传递的选项在主机上创建备份。

默认处理器: BackupRemoteHandler
事件参数:

  • remoteConfig: 与我们打算创建备份的主机和应用程序相关的 RemoteConfig 对象。
  • options: 备份的选项。一个键为
    • files (bool): 是否创建文件的备份。
    • 数据(布尔值):是否创建数据库备份。
  • fileBackupConfig:文件备份的配置。一个包含键的数组
    • exclude_from_backup:需要从备份中排除的文件和/或目录。
    • file_backup_subdirs:需要备份的文件目录的子目录。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • backup_files:文件备份的超时时间(秒)。
    • backup_database:数据库备份的超时时间(秒)。

digipolis:build-task

此事件的处理程序应返回一个创建当前代码库发行版存档的任务,以上传到环境。

默认处理程序BuildTaskHandler
事件参数:

  • archiveName:应创建的存档的名称。

digipolis:clean-dirs

此事件的处理程序应返回一个任务,通过删除较旧的发行版来清理发行版目录。

默认处理程序CleanDirsHandler
事件参数:

  • remoteConfig:与将要清理发行版目录的主机和应用程序相关的RemoteConfig对象。

digipolis:clear-cache

此事件的处理程序应返回一个任务,以清除远程主机上的缓存。

默认处理程序ClearCacheHandler
事件参数:

  • remoteConfig:与将要清除缓存的主机和应用程序相关的RemoteConfig对象。

digipolis:clear-remote-opcache

此事件的处理程序应返回一个任务,以清除远程主机上的opcache。

默认处理程序ClearRemoteOpcacheHandler
事件参数:

  • remoteConfig:与将要清除opcache的主机和应用程序相关的RemoteConfig对象。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • clear_op_cache:清除opcache的超时时间(秒)。

digipolis:compress-old-release

此事件的处理程序应返回一个任务,以压缩给定应用程序的主机上的旧发行版。

默认处理程序CompressOldReleaseHandler
事件参数:

  • remoteConfig:与将要压缩旧发行版的主机和应用程序相关的RemoteConfig对象。
  • releaseToCompress:应压缩的发行版目录的路径。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • compress_old_release:压缩发行版的超时时间(秒)。

digipolis:current-project-root

此事件的处理程序应返回给定主机上给定应用程序当前项目根的路径。这意味着实际路径,而不是执行时将返回的任务。

默认处理程序CurrentProjectRootHandler
事件参数:

  • host:要获取项目根的主机。
  • user:连接到主机的SSH用户。
  • privateKeyFile:用于连接到主机的私钥的路径。
  • remoteSettings:从properties.yml中解析出的给定主机和应用程序的远程设置。

digipolis:download-backup

此事件的处理程序应返回一个任务,从主机下载应用程序的备份。

默认处理程序DownloadBackupHandler
事件参数:

  • remoteConfig:将要下载备份的主机和应用程序相关的RemoteConfig对象。
  • options: 备份的选项。一个键为
    • files (bool):是否创建了文件备份。
    • data (bool):是否创建了数据库备份。

digipolis:install

此事件的处理器应返回一个任务,该任务将在主机上执行安装脚本。

默认处理程序InstallHandler
事件参数:

  • remoteConfig:将要安装的主机和应用程序相关的RemoteConfig对象。
  • options:传递给安装任务的命令选项。
  • force:布尔值,指示是否强制安装,即使已经存在安装。

digipolis:is-site-installed

此事件的处理器应返回一个布尔值,指示主机上是否已经存在应用程序的激活安装。这意味着实际的布尔值,而不是执行时将返回该值的任务。这有助于我们确定在部署应用程序时是否应运行安装或更新脚本。

默认处理程序IsSiteInstalledHandler
事件参数:

  • remoteConfig:将要检查的主机和应用程序相关的RemoteConfig对象。

digipolis:get-local-settings

此事件的处理器应返回从properties.yml解析出的应用程序本地安装的设置。

默认处理程序LocalSettingsHandler
事件参数:

  • app:应用程序的名称。
  • timestamp:当前时间戳(有时用作路径中的令牌)。

digipolis:mirror-dir

此事件的处理器应返回一个任务,该任务将从一个目录镜像(文件、符号链接、子目录等)到另一个目录。

默认处理程序MirrorDirHandler
事件参数:

  • dir:要镜像的目录。
  • destination:镜像目录的目标路径。

digipolis:post-symlink

此事件的处理器应返回一个任务,该任务将在远程主机上创建从properties.yml解析出的符号链接之后执行。

默认处理程序PostSymlinkHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • post_symlink:后符号链接任务的秒数超时。

digipolis:pre-local-sync-files

此事件的处理器应返回一个任务,该任务应在从远程安装同步文件到本地安装之前执行。

默认处理程序PreLocalSyncFilesHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • localSettings:从properties.yml解析出的应用程序本地安装的设置。

digipolis:pre-restore-backup-remote

此事件的处理器应返回一个任务,该任务应在主机上恢复备份之前执行。

默认处理程序PreRestoreBackupRemoteHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • fileBackupConfig:文件备份的配置。一个包含键的数组
    • exclude_from_backup:需要从备份中排除的文件和/或目录。
    • file_backup_subdirs:需要备份的文件目录的子目录。
  • options: 备份的选项。一个键为
    • files (bool):是否创建了文件备份。
    • data (bool):是否创建了数据库备份。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • pre_restore:预处理恢复任务的秒数超时。

digipolis:pre-symlink

此事件的处理程序应返回一个任务,该任务应在远程主机上的符号链接创建之前执行。

默认处理程序PreSymlinkHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • pre_symlink:预符号链接任务的超时时间(秒)。

digipolis:push-package

此事件的处理程序应返回一个任务,将发布存档推送到主机。

默认处理程序PushPackageHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • archiveName:要推送的存档名称。

digipolis:realpath

此事件的处理程序应返回给定路径的 realpath。这意味着实际路径,而不是执行时将返回它的任务。默认处理程序支持将 ~(波浪号)替换为用户的家目录。

默认处理程序RealpathHandler
事件参数:

  • path:要获取其实际路径的路径。

digipolis:get-remote-settings

此事件的处理程序应返回从 properties.yml 解析出的应用远程安装的设置。这意味着实际设置,而不是执行时将返回它的任务。

默认处理程序RemoteSettingsHandler
事件参数:

  • servers:应用所在的服务器数组(可以是单个,也可以是用于负载均衡设置的多个)。
  • user:连接到服务器的SSH用户。
  • privateKeyFile:连接到服务器的私钥路径。
  • app:应用程序的名称。
  • timestamp:当前时间戳(有时用作路径中的令牌)。

digipolis:remote-switch-previous

此事件的处理程序应返回一个任务,将 current 符号链接切换到上一个版本(主要用于失败发布的回滚)。

默认处理程序RemoteSwitchPreviousHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。

digipolis:remote-symlink

此事件的处理程序应返回一个任务,将创建在 properties.yml 中定义的符号链接。

默认处理程序RemoteSymlinkPreviousHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。

digipolis:remove-backup-remote

此事件的处理程序应返回一个任务,从主机中删除备份。

默认处理程序RemoveBackupRemoteHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • options: 备份的选项。一个键为
    • files (bool):是否创建了文件备份。
    • data (bool):是否创建了数据库备份。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • remove_backup:预符号链接任务的超时时间(秒)。

digipolis:remove-failed-release

此事件的处理程序应返回一个任务,从主机中删除失败的发布。

默认处理程序RemoveFailedReleaseHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • releaseDir:要删除的发布目录。

digipolis:remove-local-backup

此事件的处理程序应返回一个任务,从您的本地计算机中删除备份。

默认处理程序RemoveLocalBackupHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • options: 备份的选项。一个键为
    • files (bool):是否创建了文件备份。
    • data (bool):是否创建了数据库备份。
  • fileBackupConfig:文件备份的配置。一个包含键的数组
    • exclude_from_backup:需要从备份中排除的文件和/或目录。
    • file_backup_subdirs:需要备份的文件目录的子目录。

digipolis:restore-backup-db-local

此事件的处理程序应返回一个任务,在您的本地计算机上恢复数据库备份。

默认处理程序RestoreBackupDbLocalHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • localSettings:从properties.yml解析出的应用程序本地安装的设置。

digipolis:restore-backup-files-local

此事件的处理程序应返回一个任务,在您的本地计算机上恢复文件备份。

默认处理程序RestoreBackupFilesLocalHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • localSettings:从properties.yml解析出的应用程序本地安装的设置。

digipolis:restore-backup-remote

此事件的处理程序应返回一个任务,在主机上恢复备份。

默认处理器RestoreBackupRemoteHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • options: 备份的选项。一个键为
    • files (bool): 是否创建文件的备份。
    • 数据(布尔值):是否创建数据库备份。
  • fileBackupConfig:文件备份的配置。一个包含键的数组
    • exclude_from_backup:需要从备份中排除的文件和/或目录。
    • file_backup_subdirs:需要备份的文件目录的子目录。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • restore_files_backup:文件备份的超时时间(秒)。
    • restore_db_backup:数据库备份的超时时间(秒)。

digipolis:rsync-files-between-hosts

此事件的处理器应返回一个任务,用于在两个主机之间同步文件。

默认处理器RsyncFilesBetweenHostsHandler
事件参数:

  • sourceRemoteConfig:与源主机和应用程序相关的RemoteConfig对象。
  • destinationRemoteConfig:与目标主机和应用程序相关的RemoteConfig对象。
  • fileBackupConfig:文件备份的配置。一个包含键的数组
    • exclude_from_backup:需要从备份中排除的文件和/或目录。
    • file_backup_subdirs:需要备份的文件目录的子目录。
  • timeouts:相关任务的SSH超时。一个包含键的数组
    • synctask_rsync:rsync的超时时间(秒)。

digipolis:rsync-files-to-local

此事件的处理器应返回一个任务,用于将文件同步到您的本地机器。

默认处理器RsyncFilesToLocalHandler
事件参数:

  • remoteConfig:与主机和应用程序相关的RemoteConfig对象。
  • localSettings:从properties.yml解析出的应用程序本地安装的设置。
  • directory:要同步的位于 $remoteSettings['filesdir'] 下的子目录。
    • fileBackupConfig:文件备份的配置。一个包含键的数组
    • exclude_from_backup:需要从备份中排除的文件和/或目录。
    • file_backup_subdirs:需要备份的文件目录的子目录。

digipolis:switch-previous

此事件的处理器应返回一个任务,将 current 符链接切换到上一个版本(主要用于失败发布的回滚)。与(digipolis:remote-switch-previous)[#digipolisremote-switch-previous] 事件的不同之处在于,这将直接在主机上执行,因此不需要SSH连接,而(digipolis:remote-switch-previous)[#digipolisremote-switch-previous] 将从您的部署服务器或您的本地机器执行,因此需要与主机建立SSH连接。

默认处理器SwitchPreviousHandler
事件参数:

  • releasesDir:包含所有发布版本的目录。
  • currentSymlink:指向您的 current 符链接的路径。

digipolis:timeout-setting

此事件的处理器应返回给定类型的超时设置(秒)。这意味着实际的设置,而不是在执行时返回该设置的任务。

默认处理器TimeoutSettingHandler
事件参数:

  • type:要获取的超时设置类型。请参阅其他事件的超时事件参数。

digipolis:update

此事件的处理器应返回一个任务,在主机上执行更新脚本。

默认处理器UpdateHandler
事件参数:

  • remoteConfig:与我们要更新的主机和应用程序相关的RemoteConfig对象。
  • options:从命令传递给更新任务的选项。
  • force:布尔值,指示是否强制安装,即使已经存在安装。

digipolis:upload-backup

此事件的处理器应返回一个任务,将应用程序的备份上传到主机。

默认处理器UploadBackupHandler
事件参数:

  • remoteConfig:将要下载备份的主机和应用程序相关的RemoteConfig对象。
  • options: 备份的选项。一个键为
    • files (bool):是否创建了文件备份。
    • data (bool):是否创建了数据库备份。