Skip to content

Instantly share code, notes, and snippets.

@scottymeyers
Forked from wiledal/__flightplan_deployments.md
Last active January 15, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottymeyers/507c04432c04f9c704233e93e24d887f to your computer and use it in GitHub Desktop.
Save scottymeyers/507c04432c04f9c704233e93e24d887f to your computer and use it in GitHub Desktop.
Set up your local machine and remote machine for quick deployments with Flightplan

Deploying

For easy deployments we're using flightplan, install with npm install -g flightplan.

Before deploying you need to make your computer a friend to the server.
You only need to do these steps once per machine.

We are going to be adding your public key to the remote server for passwordless SSH.
Then we are going to set up your SSH to allow for Agent Forwarding, so that your git commands are tunneled to the server.

When a step says Locally it means you should execute the command on your local machine.
When a step says Remotely it means you should execute the command on the remote server you want to deploy on.

OK LET'S GO

  1. Locally, cat ~/.ssh/id_rsa.pub, copy the output
  2. Remotely, pico ~/.ssh/authorized_keys, paste your key, save and exit
  3. (optional) Remotely, chmod 600 ~/.shh/authorized_keys, only needs to be done the first time (but it's very important, as the server might be locked completely if not done)
  4. Locally, echo "Host <HOST IP>\n ForwardAgent yes" >> ~/.ssh/config, this adds the remote IP to your forwarding agent
  5. Locally ssh-add to set up your key for agent forwarding. (NOTE: this needs to be run after each restart)

Using Flightplan for deployments

# Flightplan is a task runner for remote and local tasks
# fly <task>:<target> [--pull/--tag]
# The --pull and --tag commands have been added by us.

# Pull the latest of the current remotely checked out branch
fly deploy:staging --pull

# Reset the branch to a certain release number
# fly deploy:production --tag <tag number>
fly deploy:staging --tag 1.2.5
/*
An example flightplan
*/
var plan = require("flightplan");
var argv = require("yargs").argv;
plan.target("production", {
host: "<HOST>",
username: "root",
agent: process.env.SSH_AUTH_SOCK,
agentForward: true,
webroot: "/var/www/amazing_website"
})
plan.remote("deploy", function(remote) {
if (!argv.tag && !argv.pull) return plan.abort("No --tag, or --pull provided.");
var doContinue = remote.prompt("Are you sure you want to deploy? [y/n]");
if (doContinue.indexOf("y") === -1) return plan.abort("Cancelled deploy");
remote.with("cd " + remote.runtime.webroot, function() {
console.log(" > Fetching repo...");
if (argv.tag) {
remote.exec("git fetch --all");
remote.exec("git reset --hard " + argv.tag);
}else if (argv.pull) {
remote.exec("git pull");
}
console.log(" > Installing node modules...");
remote.exec("npm install");
console.log(" > Running preprocessors...");
remote.exec("gulp");
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment