Class: CmdDeploy
- Includes:
- Puntfile
- Defined in:
- lib/punt/cmd/cmd_deploy.rb
Constant Summary
Constants included from Puntfile
Instance Method Summary collapse
Methods included from Puntfile
Methods inherited from Cmd
#name, #options, #setup, #summary, tag
Instance Method Details
#run(argv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/punt/cmd/cmd_deploy.rb', line 10 def run(argv) opts = parse_opts(argv) if (opts[:dry_run]) puts "Dry Run! Nothing will be deployed or modified. All commands that would cause side-effects will be printed below" end env = argv.shift ref = argv.shift env = puntfile.first.first unless env environment = puntfile[env] if env if (!environment) raise "No environment #{env} was found in the puntfile" end mode = environment["mode"] if mode != "scp" raise "No mode available for the given mode '#{mode}'" end # Some Git Stuff repo = environment["repo"] if (repo != "git") raise "No repo available for the given repository type #{repo}" end original_head = `git rev-parse --short HEAD`.strip original_branch = `git rev-parse --abbrev-ref HEAD`.strip ref = original_head unless ref ref = `git rev-parse --short --verify #{ref}`.strip ref_full = `git rev-parse --verify #{ref}`.strip # TODO: Check to see if there are any changes! Yell and complain if there are any changes puts "Deploying #{ref} to #{env}" puts "" # Checkout the code if ref != original_head if opts[:dry_run] puts "git checkout #{ref}" else `git checkout #{ref}` end end # Upload Version File scp_versionfile(ref_full, "start", environment, dry_run: opts[:dry_run] || false) if environment["files"] environment["files"].each do |key, value| scp_upload(key, value, environment, dry_run: opts[:dry_run] || false) end end scp_versionfile(ref_full, "success", environment, dry_run: opts[:dry_run] || false) # Revert to our previous checkout if ref != original_head if opts[:dry_run] puts "git checkout #{original_branch}" else `git checkout #{original_branch}` end end end |