Automated deployment of Swift projects to servers. Once set up, deploying your project is as simple as:
> flock deploy
Flock will clone your project onto your server(s), build it, and start the application (and do anything else you want it to do). Flock already works great with Vapor, Zewo, Perfect, and Kitura.
git clone https://github.com/jakeheis/Flock
cd Flock
swift build -c release
mv .build/release/flock /usr/bin/local/flock
Init
To start using Flock, run:
flock init
This command creates a Flock.swift file in the current directory. After the command completes, you should read through Flock.swift and follow the directions located throughout the file.
Tasks
Running tasks
You can see the available tasks by running flock with no arguments. To run a task, just call flock <task>, such as:
flock deploy # Run the deploy task
You can also specify the environment Flock should execute the task in:
flock deploy --env=production # Same as just running flock deploy
flock deploy --env=staging # Run the deploy task in the staging environment
Writing your own tasks
See the note in Flock.swift about how to write your own task. Your task will ultimately run some commands on a Server object. Here are some examples of what’s possible:
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")
}
}
Check out Server.swift to see all of Server‘s available methods. Also take a look at Paths.swift to see the built-in paths for your server.within calls.
Permissions
In general, you should create a dedicated deploy user on your server. Authentication & Authorisation is a great resource for learning how to do this.
To ensure the deploy task succeeds, make sure:
The deploy user has access to Config.deployDirectory (default /var/www)
The deploy user has access to the swift executable
Some additional considerations if you plan to use supervisord (which you likely should!):
Flock
Automated deployment of Swift projects to servers. Once set up, deploying your project is as simple as:
Flock will clone your project onto your server(s), build it, and start the application (and do anything else you want it to do). Flock already works great with Vapor, Zewo, Perfect, and Kitura.
Inspired by Capistrano.
Table of Contents
Installation
Mint (recommended)
Manual
Init
To start using Flock, run:
This command creates a
Flock.swiftfile in the current directory. After the command completes, you should read throughFlock.swiftand follow the directions located throughout the file.Tasks
Running tasks
You can see the available tasks by running
flockwith no arguments. To run a task, just callflock <task>, such as:You can also specify the environment Flock should execute the task in:
Writing your own tasks
See the note in
Flock.swiftabout how to write your own task. Your task will ultimately run some commands on aServerobject. Here are some examples of what’s possible:Check out Server.swift to see all of
Server‘s available methods. Also take a look at Paths.swift to see the built-in paths for yourserver.withincalls.Permissions
In general, you should create a dedicated deploy user on your server. Authentication & Authorisation is a great resource for learning how to do this.
To ensure the
deploytask succeeds, make sure:Config.deployDirectory(default /var/www)swiftexecutableSome additional considerations if you plan to use
supervisord(which you likely should!):supervisorctlcommands (see Using supervisorctl with linux permissions but without root or sudo for more info)supervisorconfig file (default /etc/supervisor/conf.d/server.conf)