Swift 项目的服务器自动化部署工具。一旦设置完成,部署你的项目就和下面一样简单:
> flock deploy
Flock 会将你的项目克隆到你的服务器上,构建它,并启动应用程序(以及你想要它做的任何其他事情)。Flock 已经可以很好地与 Vapor、Zewo、Perfect 和 Kitura 一起使用。
灵感来自 Capistrano。
mint install jakeheis/Flock
git clone https://github.com/jakeheis/Flock
cd Flock
swift build -c release
mv .build/release/flock /usr/bin/local/flock
要开始使用 Flock,请运行
flock init
此命令会在当前目录中创建一个 Flock.swift
文件。命令完成后,你应该通读 Flock.swift
并遵循文件中提供的指示。
你可以通过不带参数运行 flock
来查看可用的任务。 要运行任务,只需调用 flock <task>
,例如
flock deploy # Run the deploy task
你还可以指定 Flock 应该在哪个环境中执行任务
flock deploy --env=production # Same as just running flock deploy
flock deploy --env=staging # Run the deploy task in the staging environment
请参阅 Flock.swift
中关于如何编写你自己的任务的说明。 你的任务最终将在 Server
对象上运行一些命令。 以下是一些可能的示例
try server.execute("mysql -v") // Execute a command remotely
let contents = try server.capture("cat myFile") // Execute a command remotely and capture the output
// Execute all commands in this closure within Path.currentDirectory
try server.within(Path.currentDirectory) {
try server.execute("ls")
if server.fileExists("anotherFile.txt") { // Check the existence of a file on the server
try server.execute("cat anotherFile.txt")
}
}
查看 Server.swift 以查看 Server
的所有可用方法。 另请查看 Paths.swift 以查看 server.within
调用的内置路径。
一般来说,你应该在你的服务器上创建一个专用的部署用户。 身份验证和授权 是学习如何执行此操作的绝佳资源。
为确保 deploy
任务成功,请确保
Config.deployDirectory
(默认为 /var/www)swift
可执行文件如果你计划使用 supervisord
(你可能应该这样做!),则需要考虑一些其他事项
supervisorctl
命令(有关更多信息,请参阅 在没有 root 或 sudo 的情况下,将 supervisorctl 与 linux 权限一起使用)supervisor
配置文件(默认为 /etc/supervisor/conf.d/server.conf)