desm-it / phploy
PHPloy - 支持子模块、多服务器和回滚的增量 Git (S)FTP 部署工具。
Requires
- php: ^8.0
- league/climate: ^3.0
- league/flysystem: ^3.0
- league/flysystem-ftp: ^3.0
- league/flysystem-sftp-v3: ^3.0
Requires (Dev)
- phpunit/phpunit: ^8.0
- teqneers/php-stream-wrapper-for-git: >=1.0.1 <2
- dev-desm-it
- 4.10.1
- 4.10.0
- 4.9.3
- 4.9.2
- v4.9.1
- 4.8.5
- 4.8.4
- 4.8.3
- 4.8.2
- 4.8.1
- 4.8
- 4.7.1
- 4.7
- 4.6.3
- 4.6.2
- 4.6.1
- 4.6
- 4.5
- 4.4
- 4.3.5
- 4.3.4
- 4.3.3
- 4.3.2
- 4.3.1
- 4.3
- 4.2
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.0
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.3
- 3.3.2
- 3.3.1
- v3.1.0-stable
- v3.0.19-stable
- v3.0.18-stable
- v3.0.17-stable
- v3.0.16-stable
- v3.0.15-stable
- v3.0.14-beta
- v3.0.13-beta
- v3.0.12-beta
- v3.0.11-alpha
- v3.0.10-alpha
- v3.0.9-alpha
- v3.0.8-alpha
- v3.0.7-alpha
- v3.0.6-alpha
- v3.0.5-alpha
- v3.0.4-alpha
- v3.0.3-alpha
- v3.0.2-alpha
- v3.0.0-alpha
- dev-Flysystem-v3.0-ftp
- dev-develop
- dev-master
This package is not auto-updated.
Last update: 2024-09-20 19:14:44 UTC
README
版本 4.10.1 Flysystem 更新
PHPloy 是一个增量 Git FTP 和 SFTP 部署工具。通过跟踪远程服务器(群)的状态,它只部署自上次部署以来已提交的文件。PHPloy 支持子模块、子子模块、部署到多个服务器和回滚。PHPloy 需要 PHP 7.3+ 和 Git 1.8+。
工作原理
PHPloy 在您的服务器上存储一个名为 .revision 的文件。此文件包含您已部署到该服务器的提交的哈希值。当您运行 phploy 时,它会下载该文件,并将其中包含的提交引用与您要部署的提交进行比较,以确定要上传的文件。PHPloy 还为您仓库中的每个子模块存储一个 .revision 文件。
安装
通过 Composer
如果您已在机器上安装了 composer,您可以全局拉取 PHPloy,如下所示
composer global require "desm-it/phploy"
请确保将 $HOME/.composer/vendor/bin 目录(或您的 OS 的等效目录)放在您的 $PATH 中,以便系统可以找到 PHPloy 可执行文件。
通过 Phar 存档
您可以将 PHPloy Phar 全局安装到 /usr/local/bin 目录中,或者在本地的项目目录中本地安装。为了方便使用,请将 phploy.phar 重命名为 phploy。
- 全局安装:将
phploy移动到/usr/local/bin。通过运行sudo chmod +x phploy使其可执行。 - 本地安装:将
phploy移动到您的项目目录。
使用方法
在本地使用 PHPloy 时,请使用 php 命令。
- 在终端中运行
phploy --init以创建phploy.ini文件,或手动创建一个。 - 在终端中运行
phploy以进行部署。
Windows 用户:在 Windows 上全局安装 PHPloy
phploy.ini
phploy.ini 文件包含您的项目配置。它应位于项目的根目录中。phploy.ini 从不上传到服务器。请查看下面的示例,了解所有可用选项
; This is a sample deploy.ini file. You can specify as many ; servers as you need and use normal or quickmode configuration. ; ; NOTE: If a value in the .ini file contains any non-alphanumeric ; characters it needs to be enclosed in double-quotes ("). [staging] scheme = sftp user = example ; When connecting via SFTP, you can opt for password-based authentication: pass = password ; Or private key-based authentication: privkey = 'path/to/or/contents/of/privatekey' host = staging-example.com path = /path/to/installation port = 22 ; You can specify a branch to deploy from branch = develop ; File permission set on the uploaded files/directories permissions = 0700 ; File permissions set on newly created directories directoryPerm = 0775 ; Deploy only this directory as base directory base = 'directory-name/' ; Files that should be ignored and not uploaded to your server, but still tracked in your repository exclude[] = 'src/*.scss' exclude[] = '*.ini' ; Files that are ignored by Git, but you want to send the the server include[] = 'js/scripts.min.js' include[] = 'directory-name/' ; conditional include - if source file has changed, include file include[] = 'css/style.min.css:src/style.css' ; Directories that should be copied after deploy, from->to copy[] = 'public->www' ; Directories that should be purged before deploy purge-before[] = "dist/" ; Directories that should be purged after deploy purge[] = "cache/" ; Pre- and Post-deploy hooks ; Use "DQOUTE" inside your double-quoted strings to insert a literal double quote ; Use 'QUOTE' inside your qouted strings to insert a literal quote ; For example pre-deploy[] = 'echo "that'QUOTE's nice"' to get a literal "that's". ; That workaround is based on https://php.ac.cn/manual/de/function.parse-ini-file.php#70847 pre-deploy[] = "wget http://staging-example.com/pre-deploy/test.php --spider --quiet" post-deploy[] = "wget http://staging-example.com/post-deploy/test.php --spider --quiet" ; Works only via SSH2 connection pre-deploy-remote[] = "touch .maintenance" post-deploy-remote[] = "mv cache cache2" post-deploy-remote[] = "rm .maintenance" ; You can specify a timeout for the underlying connection which might be useful for long running remote ; operations (cache clear, dependency update, etc.) timeout = 60 [production] quickmode = ftp://example:password@production-example.com:21/path/to/installation passive = true ssl = false ; You can specify a branch to deploy from branch = master ; File permission set on the uploaded files/directories permissions = 0774 ; File permissions set on newly created directories directoryPerm = 0755 ; Files that should be ignored and not uploaded to your server, but still tracked in your repository exclude[] = 'libs/*' exclude[] = 'config/*' exclude[] = 'src/*.scss' ; Files that are ignored by Git, but you want to send the the server include[] = 'js/scripts.min.js' include[] = 'js/style.min.css' include[] = 'directory-name/' purge-before[] = "dist/" purge[] = "cache/" pre-deploy[] = "wget http://staging-example.com/pre-deploy/test.php --spider --quiet" post-deploy[] = "wget http://staging-example.com/post-deploy/test.php --spider --quiet"
如果您的 phploy.ini 文件或 PHPLOY_PASS 环境变量中缺少密码,PHPloy 将会交互式地要求您输入密码。您还可以选择将用户名和密码存储在名为 .phploy 的文件中。
[staging]
user="theUser"
pass="thePassword"
[production]
user="theUser"
pass="thePassword"
此功能特别适用于您想要通过 Git 分享 phploy.ini 但又想将密码隐藏起来的情况。
您还可以使用环境变量进行部署,而无需在文件中存储您的凭证。如果这些变量不在 phploy.ini 文件中,则会使用这些变量
PHPLOY_HOST
PHPLOY_PORT
PHPLOY_PASS
PHPLOY_PATH
PHPLOY_USER
PHPLOY_PRIVKEY
这些变量可以使用以下方式使用;
$ PHPLOY_PORT="21" PHPLOY_HOST="myftphost.com" PHPLOY_USER="ftp" PHPLOY_PASS="ftp-password" PHPLOY_PATH="/home/user/public_html/example.com" phploy -s servername
或如下导出,脚本将自动使用它们
$ export PHPLOY_PORT="21"
$ export PHPLOY_HOST="myftphost.com"
$ export PHPLOY_USER="ftp"
$ export PHPLOY_PASS="ftp-password"
$ export PHPLOY_PATH="/home/user/public_html/example.com"
$ export PHPLOY_PRIVKEY="path/to/or/contents/of/privatekey"
$ phploy -s servername
多服务器
PHPloy 允许您在部署文件中配置多个服务器,并轻松地将应用程序部署到其中任何一个。
默认情况下,PHPloy 将部署到所有指定的服务器。如果您在服务器配置中有一个名为 'default' 的条目,则 PHPloy 将默认使用该服务器配置。要指定单个服务器,请运行
phploy -s servername
或
phploy --server servername
servername 是您在 phploy.ini 配置文件中指定的服务器名称。
如果您配置了 'default' 服务器,您可以通过运行以下命令将应用程序部署到所有配置的服务器:
phploy --all
共享配置(自定义默认值)
如果您指定了一个名为 * 的服务器配置,本节中配置的所有选项都将与其他服务器共享。这基本上允许您注入自定义默认值。
; The special '*' configuration is shared between all other configurations (think include) [*] exclude[] = 'src/*' include[] = "dist/app.css" ; As a result both shard1 and shard2 will have the same exclude[] and include[] "default" values [shard1] quickmode = ftp://example:password@shard1-example.com:21/path/to/installation [shard2] quickmode = ftp://example:password@shard2-example.com:21/path/to/installation
回滚
警告:当前 --rollback 选项无法正确更新您的子模块。
PHPloy 允许您在需要时回滚到早期版本。回滚非常简单。
要回滚到上一个提交,只需运行
phploy --rollback
要回滚到您想要的任何提交,运行
phploy --rollback commit-hash-goes-here
当您运行回滚时,您的工作副本中的文件将临时恢复到您正在部署的回滚版本。当部署完成后,一切都会恢复原状。
请注意,没有 --rollback 的简写形式。
列出更改的文件
PHPloy 允许您在实际上传/删除之前看到将要上传/删除的文件。只需运行
phploy -l
或者
phploy --list
更新或“同步”远程修订版本
如果您想将服务器上的 .revision 文件更新为与您的当前本地修订版本匹配,运行
phploy --sync
如果您想将其设置为以前的提交修订版本,只需指定修订版本,如下所示
phploy --sync your-revision-hash-here
在首次部署时创建部署目录
如果部署目录不存在,您可以指示 PHPloy 为您创建它
phploy --force
手动全新上传
如果您想要进行全新上传,即使您之前已经部署过,也可以使用 --fresh 参数,如下所示
phploy --fresh
子模块
支持子模块,但默认情况下已关闭,因为您不期望它们经常更改,并且您只偶尔更新它们。要运行带有子模块扫描的部署,请将 --submodules 参数添加到命令中
phploy --submodules
清除
在许多情况下,我们需要在部署后清除目录的内容。这可以通过在 phploy.ini 中指定目录来实现,如下所示
; relative to the deployment path
purge[] = "cache/"
在部署之前清除目录,请在 phploy.ini 中指定目录,如下所示
; relative to the deployment path
purge-before[] = "dist/"
钩子
PHPloy 允许您在部署前后执行命令。例如,您可以使用 wget 调用我的服务器上的脚本以执行 composer update。
; To execute before deployment
pre-deploy[] = "wget http://staging-example.com/pre-deploy/test.php --spider --quiet"
; To execute after deployment
post-deploy[] = "wget http://staging-example.com/post-deploy/test.php --spider --quiet"
日志记录
PHPloy 支持简单的活动日志记录。日志记录以以下格式保存在您的项目中的 phploy.log 文件中
2016-03-28 08:12:37+02:00 --- INFO: [SHA: 59a387c26641f731df6f0d1098aaa86cd55f4382] Deployment to server: "default" from branch "master". 2 files uploaded; 0 files deleted.
要启用日志记录,请将此添加到 phploy.ini
[production]
logger = on
贡献
贡献非常欢迎;PHPloy 因贡献者而伟大。请查看 问题。
鸣谢
版本历史
请查看 发布历史 了解详细信息。
许可
PHPloy 依据 MIT 许可证(MIT)授权。