|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require 'rubygems' |
| 4 | +require 'commander/import' |
| 5 | +require 'rest_client' |
| 6 | +require 'json' |
| 7 | + |
| 8 | +$:.unshift File.join(File.dirname(__FILE__), 'lib') |
| 9 | +require 'deployer' |
| 10 | + |
| 11 | +program :version, '0.0.1' |
| 12 | +program :description, 'Deploys binaries to OpenShift' |
| 13 | + |
| 14 | +global_option '-s', '--server SERVER' |
| 15 | +global_option '-u', '--user USER' |
| 16 | +global_option '-p', '--password PASSWORD' |
| 17 | +global_option '-T', '--threads THREADS', Integer |
| 18 | + |
| 19 | +$default_user = $default_server = nil |
| 20 | + |
| 21 | +# try to load default user and server from the openshift config |
| 22 | +config_file = File.join(File.expand_path('~'), '.openshift', 'express.conf') |
| 23 | +if File.exist?(config_file) |
| 24 | + File.open(config_file, 'r').each do |line| |
| 25 | + next if line =~ /^#/ |
| 26 | + key, value = line.chomp.split('=') |
| 27 | + |
| 28 | + if key == 'default_rhlogin' |
| 29 | + $default_user = value |
| 30 | + elsif key == 'libra_server' |
| 31 | + $default_server = value |
| 32 | + end |
| 33 | + end |
| 34 | +end |
| 35 | + |
| 36 | +command :init do |c| |
| 37 | + c.syntax = 'deploy init <app> [options]' |
| 38 | + c.summary = 'Initializes an OpenShift application for binary (non-git) deployments' |
| 39 | + c.action do |args, options| |
| 40 | + OpenShift::Deployment::CLI::Deployer.new(args, options).init_head_gear |
| 41 | + end |
| 42 | +end |
| 43 | + |
| 44 | +command :'status' do |c| |
| 45 | + c.syntax = 'deploy status <app> [options]' |
| 46 | + c.summary = 'Displays the status of all gears for an OpenShift application' |
| 47 | + c.description = 'Displays the SSH URL, currently deployed version & checksum, and state of each gear' |
| 48 | + c.action do |args, options| |
| 49 | + OpenShift::Deployment::CLI::Deployer.new(args, options).status |
| 50 | + end |
| 51 | +end |
| 52 | + |
| 53 | +command :partition do |c| |
| 54 | + c.syntax = 'deploy partition <app> [options]' |
| 55 | + c.summary = 'Divides an OpenShift application\'s gears into multiple partitions for use with the activate command' |
| 56 | + c.description = <<EOF |
| 57 | +Divides an OpenShift application\'s gears into multiple partitions for use with the activate command. |
| 58 | +
|
| 59 | +The partitions will be written to individual files of the format <app>-<partition #>-<total # of partitions>. These files should be passed to the 'activate' command using the --gears option. |
| 60 | +EOF |
| 61 | + #c.option '--percents PERCENTS', Array |
| 62 | + c.option '--counts COUNTS', Array, '# of gears in each partition, separated by comma. If sum of counts < total # of gears, 1 additional partition will be created with the remaining gears' |
| 63 | + c.option '-o', '--output-dir OUTPUT_DIR' |
| 64 | + c.example 'Divide into partitions of 5, 10, and 20 gears each.', 'deploy partition app --counts=5,10,20 --output-dir=partitions' |
| 65 | + c.action do |args, options| |
| 66 | + OpenShift::Deployment::CLI::Deployer.new(args, options).partition |
| 67 | + end |
| 68 | +end |
| 69 | + |
| 70 | +command :prepare do |c| |
| 71 | + c.syntax = 'deploy prepare <app> <user_prepare options> [options]' |
| 72 | + c.summary = 'Prepares a binary artifact on the head gear of an OpenShift application' |
| 73 | + c.description = <<EOF |
| 74 | +Prepares a binary artifact on the head gear of an OpenShift application. |
| 75 | +
|
| 76 | +<user_prepare options> will be passed to the user_prepare script, which must download an artifact, store it (e.g. in /tmp), and echo '<path> <sha1>'. |
| 77 | +
|
| 78 | +The 'prepare' action will display the checksum for the artifact, which must be passed to the 'distribute' and 'activate' actions. |
| 79 | +EOF |
| 80 | + c.action do |args, options| |
| 81 | + OpenShift::Deployment::CLI::Deployer.new(args, options).prepare |
| 82 | + end |
| 83 | +end |
| 84 | + |
| 85 | +command :distribute do |c| |
| 86 | + c.syntax = 'deploy distribute <app> <checksum> [options]' |
| 87 | + c.summary = 'Distributes the artifact indicated by <checksum> to all gears of <app>.' |
| 88 | + c.description = 'Distributes the artifact indicated by <checksum> to all gears of <app>.' |
| 89 | + c.action do |args, options| |
| 90 | + OpenShift::Deployment::CLI::Deployer.new(args, options).distribute |
| 91 | + end |
| 92 | +end |
| 93 | + |
| 94 | +command :artifacts do |c| |
| 95 | + c.syntax = 'deploy artifacts <app> [options]' |
| 96 | + c.summary = 'Displays all artifacts that have been distributed to an OpenShift application\'s gears' |
| 97 | + c.description = 'Displays all artifacts that have been distributed to an OpenShift application\'s gears' |
| 98 | + c.action do |args, options| |
| 99 | + OpenShift::Deployment::CLI::Deployer.new(args, options).artifacts |
| 100 | + end |
| 101 | +end |
| 102 | + |
| 103 | +command :deployments do |c| |
| 104 | + c.syntax = 'deploy deployments <app> [options]' |
| 105 | + c.summary = 'Displays all deployments' |
| 106 | + c.description = c.summary |
| 107 | + c.action do |args, options| |
| 108 | + OpenShift::Deployment::CLI::Deployer.new(args, options).deployments |
| 109 | + end |
| 110 | +end |
| 111 | + |
| 112 | +command :activate do |c| |
| 113 | + c.syntax = 'deploy activate <app> <checksum> [options]' |
| 114 | + c.summary = 'Activates the artifact indicated by <checksum> to the specified gears, or all gears for an OpenShift application' |
| 115 | + c.description = c.summary |
| 116 | + c.example 'Activate all gears', 'deploy activate myapp b62479e0531c49dfe5d7fc7b5d8957d14106781d' |
| 117 | + c.example 'Activate a subset of gears using a file created by the \'partition\' action', 'deploy activate myapp b62479e0531c49dfe5d7fc7b5d8957d14106781d --gears myapp-1-4' |
| 118 | + c.example 'Perform a dry run', 'deploy activate myapp b62479e0531c49dfe5d7fc7b5d8957d14106781d --gears myapp-1-4 --dry-run' |
| 119 | + c.option '-n', '--dry-run' |
| 120 | + c.option '-g', '--gears FILE' |
| 121 | + c.action do |args, options| |
| 122 | + OpenShift::Deployment::CLI::Deployer.new(args, options).activate |
| 123 | + end |
| 124 | +end |
| 125 | + |
| 126 | +command :rollback do |c| |
| 127 | + c.syntax = 'deploy rollback <app> [options]' |
| 128 | + c.summary = 'Activates the previous deployment' |
| 129 | + c.description = c.summary |
| 130 | + c.example 'Rollback all gears', 'deploy rollback myapp' |
| 131 | + c.example 'Rollback a subset of gears', 'deploy rollback myapp --gears myapp-1-4' |
| 132 | + c.example 'Perform a dry run', 'deploy rollback myapp --dry-run' |
| 133 | + c.option '-n', '--dry-run' |
| 134 | + c.option '-g', '--gears FILE' |
| 135 | + c.action do |args, options| |
| 136 | + OpenShift::Deployment::CLI::Deployer.new(args, options).rollback |
| 137 | + end |
| 138 | +end |
0 commit comments