Skip to content
This repository was archived by the owner on Nov 15, 2018. It is now read-only.

Commit 96094f4

Browse files
committed
Initial commit
0 parents  commit 96094f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2018
-0
lines changed

LICENSE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Licensed under the Apache License, Version 2.0 (the "License");
2+
you may not use this file except in compliance with the License.
3+
You may obtain a copy of the License at
4+
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
OpenShift Binary Deployment Solution
2+
====================================
3+
This is an external solution to allow deploying binary artifacts to OpenShift applications without the need to use git. It consists of a single command line script called "deploy" that performs the following actions:
4+
5+
## Prepare
6+
Downloads the binary artifact from an external location and prepares it for deployment using this tooling. The prepare action invokes a script called `user_prepare` that is responsible for downloading the artifact to a temporary location (e.g. /tmp/somefile.tgz) and reporting the file's location and sha1 checksum back to the prepare action.
7+
8+
Currently, `user_prepare` must be colocated with the scripts in the gear directory. A sample user_prepare script is provided.
9+
10+
When this action finishes, it returns the sha1 checksum to the user, who must then use that to identify which artifact to distribute and activate.
11+
12+
## Distribute
13+
Distributes the binary artifact to all child gears.
14+
15+
## Activate
16+
Activates (deploys) the binary artifact to the head gear and all child gears. Deployments using this process are placed in
17+
18+
`app-root/runtime/deployments/[datetime]`
19+
20+
The existing app-root/runtime/repo directory is moved aside and is now a symlink to `app-root/runtime/deployments/[datetime]/repo`.

cli/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'commander', '~> 4.1.3'
4+
gem 'rest-client'
5+
gem 'json'
6+
gem 'parallel'
7+
gem 'net-ssh'

cli/Gemfile.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
commander (4.1.3)
5+
highline (~> 1.6.11)
6+
highline (1.6.16)
7+
json (1.7.7)
8+
mime-types (1.22)
9+
net-ssh (2.5.2)
10+
parallel (0.6.4)
11+
rest-client (1.6.7)
12+
mime-types (>= 1.16)
13+
14+
PLATFORMS
15+
ruby
16+
17+
DEPENDENCIES
18+
commander (~> 4.1.3)
19+
json
20+
net-ssh
21+
parallel
22+
rest-client

cli/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Requirements:
2+
3+
- bundler
4+
- make
5+
- gcc

cli/deploy

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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

Comments
 (0)