redis-cf-plugin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/ChangeLog.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +122 -0
- data/Rakefile +43 -0
- data/bosh_release/.final_builds/jobs/redis/index.yml +7 -0
- data/bosh_release/.final_builds/packages/redis/index.yml +7 -0
- data/bosh_release/config/.gitkeep +0 -0
- data/bosh_release/config/final.yml +10 -0
- data/bosh_release/jobs/.gitkeep +0 -0
- data/bosh_release/packages/.gitkeep +0 -0
- data/bosh_release/releases/index.yml +4 -0
- data/bosh_release/releases/redis-1.yml +20 -0
- data/bosh_release/src/.gitkeep +0 -0
- data/bosh_release/templates/aws/sample_deployment_file.yml +16 -0
- data/bosh_release/templates/aws/single_vm.yml.erb +107 -0
- data/bosh_release/templates/aws/spec +13 -0
- data/bosh_release/templates/openstack/sample_deployment_file.yml +16 -0
- data/bosh_release/templates/openstack/single_vm.yml.erb +107 -0
- data/lib/redis-cf-plugin/plugin.rb +175 -0
- data/redis-cf-plugin.gemspec +23 -0
- metadata +138 -0
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
bosh_release/.final_builds/jobs/*/*.tgz
|
19
|
+
bosh_release/.final_builds/packages/*/*.tgz
|
20
|
+
bosh_release/releases/*.tgz
|
21
|
+
deployments
|
data/ChangeLog.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
|
4
|
+
## v0.1
|
5
|
+
|
6
|
+
Initial release! The initial commands offered are:
|
7
|
+
|
8
|
+
cf create-redis Create a Redis service deployed upon target bosh
|
9
|
+
cf show-redis-uri Show the redis URI for connection via bosh DNS
|
10
|
+
cf bind-redis-env-var APP Bind current Redis service URI to current app via env variable
|
11
|
+
cf delete-redis Delete current Redis service
|
12
|
+
|
13
|
+
The redis service URI uses bosh DNS. As such it must be deployed into the same bosh being used for Cloud Foundry.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dr Nic Williams
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Dedicate Redis services for your Cloud Foundry
|
2
|
+
|
3
|
+
Keep your Cloud Foundry services simple - run one service per server and delegate the creation and deletion to BOSH.
|
4
|
+
|
5
|
+
This is a simple `cf` CLI plugin to create and delete dedicated redis services, and bind them into existing Cloud Foundry applications.
|
6
|
+
|
7
|
+
Example create/bind/delete scenario:
|
8
|
+
|
9
|
+
```
|
10
|
+
$ cf prepare-redis
|
11
|
+
$ cf create-redis
|
12
|
+
$ cf bind-redis-env-var myapp
|
13
|
+
$ cf delete-redis
|
14
|
+
```
|
15
|
+
|
16
|
+
The redis servers are run outside of the Cloud Foundry deployment and are bound to Cloud Foundry applications via environment variables (until the new Service Connector is supported). It is currently
|
17
|
+
|
18
|
+
## Requirements
|
19
|
+
|
20
|
+
You must use the same BOSH for deploying redis as you use to deploy Cloud Foundry (unless your DNS is configured to be shared across the two BOSH).
|
21
|
+
|
22
|
+
It is also requried that you have login access to the same BOSH being used to deploy your Cloud Foundry.
|
23
|
+
|
24
|
+
Confirm this by running:
|
25
|
+
|
26
|
+
```
|
27
|
+
$ bosh status
|
28
|
+
$ bosh deployments
|
29
|
+
```
|
30
|
+
|
31
|
+
The former will confirm you are targeting a bosh. The latter will display the deployments. One of which should be your Cloud Foundry.
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
Install via RubyGems:
|
36
|
+
|
37
|
+
```
|
38
|
+
$ gem install bosh_cli "~> 1.5.0.pre" --source https://s3.amazonaws.com/bosh-jenkins-gems/
|
39
|
+
$ gem install redis-cf-plugin
|
40
|
+
```
|
41
|
+
|
42
|
+
The `bosh_cli` gem is currently only available from S3, rather than RubyGem itself. So it needs to be installed first.
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
Each time you install the latest `redis-cf-plugin` you will want to re-upload the latest available redis release to your bosh. If no newer release is available then nothing good nor bad will occur.
|
47
|
+
|
48
|
+
```
|
49
|
+
$ cf prepare-redis
|
50
|
+
Uploading new redis release to bosh...
|
51
|
+
```
|
52
|
+
|
53
|
+
To create/provision a new redis service you run the following command. By default, it will select the smallest known instance size.
|
54
|
+
|
55
|
+
```
|
56
|
+
$ cf create-redis myapp-redis
|
57
|
+
$ cf create-redis myapp-redis --size small
|
58
|
+
$ cf create-redis myapp-redis --size medium
|
59
|
+
$ cf create-redis myapp-redis --size large
|
60
|
+
$ cf create-redis myapp-redis --size xlarge
|
61
|
+
```
|
62
|
+
|
63
|
+
To see the list of available instance sizes or to edit the list of available instance size, see the section "Customizing" below.
|
64
|
+
|
65
|
+
To bind the redis service to an existing Cloud Foundry application (regardless if its running or not) via a simple URI passed as an environment variable, you run the following command. By default, the environment variable is `$REDIS_URI`.
|
66
|
+
|
67
|
+
```
|
68
|
+
$ cf bind-redis-env-var myapp-redis myapp
|
69
|
+
$ cf bind-redis-env-var myapp-redis myapp --env-var REDISTOGO
|
70
|
+
```
|
71
|
+
|
72
|
+
Currently there is no way to load the redis service into Cloud Foundry as a "provisioned service instance". This will be implemented soon (in association with the Service Connector API).
|
73
|
+
|
74
|
+
## Customizing
|
75
|
+
|
76
|
+
TODO - how to show available instance sizes
|
77
|
+
TODO - how to edit available instance sizes (via the bosh deployment file templates)
|
78
|
+
|
79
|
+
## Releasing new plugin gem versions
|
80
|
+
|
81
|
+
There are three reasons to release new versions of this plugin.
|
82
|
+
|
83
|
+
1. Package the latest [redis-boshrelease](https://github.com/cloudfoundry-community/redis-boshrelease) bosh release (which describes how the redis service is implemented)
|
84
|
+
2. New features or bug fixes to the plugin
|
85
|
+
3. Fix regressions caused by newer versions of the `cf` CLI or newer Cloud Foundry releases
|
86
|
+
|
87
|
+
To package the latest "final release" of the redis bosh release into this source repository, run the following command:
|
88
|
+
|
89
|
+
```
|
90
|
+
$ cd /path/to/releases
|
91
|
+
$ git clone https://github.com/cloudfoundry-community/redis-boshrelease.git
|
92
|
+
$ cd -
|
93
|
+
$ rake bosh:release:import[/path/to/releases/redis-boshrelease]
|
94
|
+
# for zsh shell quotes are required around rake arguments:
|
95
|
+
$ rake bosh:release:import'[/path/to/releases/redis-boshrelease]'
|
96
|
+
```
|
97
|
+
|
98
|
+
Note: only the latest "final release" will be packaged. See https://github.com/cloudfoundry-community/redis-boshrelease#readme for information on creating new bosh releases.
|
99
|
+
|
100
|
+
To install and test the plugin:
|
101
|
+
|
102
|
+
```
|
103
|
+
$ rake install
|
104
|
+
$ cf
|
105
|
+
```
|
106
|
+
|
107
|
+
To release a new version of the plugin as a RubyGem:
|
108
|
+
|
109
|
+
1. Edit `redis-cf-plugin.gemspec` to update the major or minor or patch version.
|
110
|
+
2. Run the release command:
|
111
|
+
|
112
|
+
```
|
113
|
+
$ rake release
|
114
|
+
```
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
1. Fork it
|
119
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
120
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
121
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
122
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
bosh_release = "redis-boshrelease"
|
4
|
+
target_bosh_release_path = File.expand_path("../bosh_release", __FILE__)
|
5
|
+
|
6
|
+
namespace :bosh do
|
7
|
+
namespace :release do
|
8
|
+
desc "Import latest #{bosh_release}"
|
9
|
+
task :import, :path do |t, args|
|
10
|
+
source_bosh_release = File.expand_path(args[:path])
|
11
|
+
unless File.directory?(source_bosh_release)
|
12
|
+
$stderr.puts "Please pass path to source bosh release"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
sh "rm -rf #{target_bosh_release_path}"
|
17
|
+
|
18
|
+
# required directories to pass bosh_cli validations
|
19
|
+
%w[config jobs packages src].each do |dir|
|
20
|
+
sh "mkdir -p #{target_bosh_release_path}/#{dir}"
|
21
|
+
sh "touch #{target_bosh_release_path}/#{dir}/.gitkeep"
|
22
|
+
end
|
23
|
+
|
24
|
+
chdir(target_bosh_release_path) do
|
25
|
+
sh "cp -R #{source_bosh_release}/releases #{target_bosh_release_path}"
|
26
|
+
sh "cp -R #{source_bosh_release}/templates #{target_bosh_release_path}"
|
27
|
+
|
28
|
+
sh "cp -R #{source_bosh_release}/.final_builds #{target_bosh_release_path}"
|
29
|
+
sh "cp -R #{source_bosh_release}/config/final.yml #{target_bosh_release_path}/config"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Remove any large temporary tgz from internal bosh_release"
|
34
|
+
task :clean do
|
35
|
+
chdir(target_bosh_release_path) do
|
36
|
+
sh "ls .final_builds/**/*.tgz | xargs rm; true"
|
37
|
+
sh "ls releases/**/*.tgz | xargs rm; true"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :release => "bosh:release:clean"
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
blobstore:
|
3
|
+
provider: s3
|
4
|
+
options:
|
5
|
+
bucket_name: redis-boshrelease
|
6
|
+
access_key_id: AKIAJPWUHOHV42IMTNQQ
|
7
|
+
secret_access_key: e3uIA4EnWpb9zy1YtWREr/0moGcEdky+2wLfprqb
|
8
|
+
encryption_key: cloudfoundry-community
|
9
|
+
min_cli_version: 1.5.0.pre.699
|
10
|
+
final_name: redis
|
File without changes
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
packages:
|
3
|
+
- name: redis
|
4
|
+
version: 1
|
5
|
+
sha1: !binary |-
|
6
|
+
OGJlZjUyYzQ2ZmRlNWI5ZWMwYzliYzVkY2I2YjQ2MjYxYmYzYTEwOA==
|
7
|
+
fingerprint: !binary |-
|
8
|
+
MDY3Y2QwMjVmNjFlZjAxNjI1NzFhYTg2NTQwYTE1OGMwOWE3YzM2Ng==
|
9
|
+
dependencies: []
|
10
|
+
jobs:
|
11
|
+
- name: redis
|
12
|
+
version: 1
|
13
|
+
fingerprint: !binary |-
|
14
|
+
ODk5Mzk1NzViM2ZkZGZlYjc4ZTk0NjNiNmI2Y2E5MDY3ZTczMDI2Zg==
|
15
|
+
sha1: !binary |-
|
16
|
+
MmRmNzYwY2I0ZGJiODdhYzE0YTBiZGMwYzBhNTU5OTc2NWViMzU2Mg==
|
17
|
+
commit_hash: 59e77715
|
18
|
+
uncommitted_changes: true
|
19
|
+
name: redis
|
20
|
+
version: 1
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Then target that deployment file:
|
2
|
+
#
|
3
|
+
# $ bosh deployment path/to/file/above
|
4
|
+
#
|
5
|
+
# Then apply this template:
|
6
|
+
#
|
7
|
+
# $ bosh diff templates/aws/single_vm.yml.erb
|
8
|
+
#
|
9
|
+
---
|
10
|
+
name: NAME
|
11
|
+
director_uuid: UUID
|
12
|
+
networks: {}
|
13
|
+
properties:
|
14
|
+
redis:
|
15
|
+
resource: medium
|
16
|
+
security_group: redis-server
|
@@ -0,0 +1,107 @@
|
|
1
|
+
---
|
2
|
+
<%-
|
3
|
+
# Example source deployment file that can be used:
|
4
|
+
# ---
|
5
|
+
# name: NAME
|
6
|
+
# director_uuid: 4ae3a0f0-70a5-4c0d-95f2-7fafaefe8b9e
|
7
|
+
# networks: {}
|
8
|
+
# properties:
|
9
|
+
# redis:
|
10
|
+
# instance_type: m1.medium
|
11
|
+
# security_groups: redis-server
|
12
|
+
#
|
13
|
+
# Then target that deployment file:
|
14
|
+
#
|
15
|
+
# $ bosh deployment path/to/file/above
|
16
|
+
#
|
17
|
+
# Then apply this template:
|
18
|
+
#
|
19
|
+
# $ bosh diff templates/aws/single_vm.yml.erb
|
20
|
+
#
|
21
|
+
redis_sg = find("properties.redis.security_group")
|
22
|
+
redis_port = 6379
|
23
|
+
redis_password = random_string 12, :redis
|
24
|
+
redis_resource = find("properties.redis.resource")
|
25
|
+
puts "export REDIS_URL=redis://:#{redis_password}@HOST:#{redis_port}/0"
|
26
|
+
-%>
|
27
|
+
name: <%= find("name") %>
|
28
|
+
director_uuid: <%= find("director_uuid") %>
|
29
|
+
|
30
|
+
release:
|
31
|
+
name: redis
|
32
|
+
version: latest
|
33
|
+
|
34
|
+
compilation:
|
35
|
+
workers: 10
|
36
|
+
network: default
|
37
|
+
reuse_compilation_vms: true
|
38
|
+
cloud_properties:
|
39
|
+
instance_type: m1.small
|
40
|
+
|
41
|
+
update:
|
42
|
+
canaries: 1
|
43
|
+
canary_watch_time: 30000-300000
|
44
|
+
update_watch_time: 30000-300000
|
45
|
+
max_in_flight: 4
|
46
|
+
max_errors: 1
|
47
|
+
|
48
|
+
networks:
|
49
|
+
- name: default
|
50
|
+
type: dynamic
|
51
|
+
cloud_properties:
|
52
|
+
security_groups:
|
53
|
+
- <%= redis_sg %>
|
54
|
+
|
55
|
+
resource_pools:
|
56
|
+
- name: small
|
57
|
+
network: default
|
58
|
+
size: <%= redis_resource == "small" ? 1 : 0 %>
|
59
|
+
stemcell:
|
60
|
+
name: bosh-stemcell
|
61
|
+
version: latest
|
62
|
+
cloud_properties:
|
63
|
+
instance_type: m1.small
|
64
|
+
|
65
|
+
- name: medium
|
66
|
+
network: default
|
67
|
+
size: <%= redis_resource == "medium" ? 1 : 0 %>
|
68
|
+
stemcell:
|
69
|
+
name: bosh-stemcell
|
70
|
+
version: latest
|
71
|
+
cloud_properties:
|
72
|
+
instance_type: m1.medium
|
73
|
+
|
74
|
+
- name: large
|
75
|
+
network: default
|
76
|
+
size: <%= redis_resource == "large" ? 1 : 0 %>
|
77
|
+
stemcell:
|
78
|
+
name: bosh-stemcell
|
79
|
+
version: latest
|
80
|
+
cloud_properties:
|
81
|
+
instance_type: m1.large
|
82
|
+
|
83
|
+
- name: xlarge
|
84
|
+
network: default
|
85
|
+
size: <%= redis_resource == "xlarge" ? 1 : 0 %>
|
86
|
+
stemcell:
|
87
|
+
name: bosh-stemcell
|
88
|
+
version: latest
|
89
|
+
cloud_properties:
|
90
|
+
instance_type: m1.xlarge
|
91
|
+
|
92
|
+
jobs:
|
93
|
+
- name: redis
|
94
|
+
template: redis
|
95
|
+
instances: 1
|
96
|
+
resource_pool: <%= redis_resource %>
|
97
|
+
networks:
|
98
|
+
- name: default
|
99
|
+
default:
|
100
|
+
- dns
|
101
|
+
- gateway
|
102
|
+
|
103
|
+
properties:
|
104
|
+
redis:
|
105
|
+
port: <%= redis_port %>
|
106
|
+
password: <%= redis_password %>
|
107
|
+
resource: <%= redis_resource %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
resources:
|
3
|
+
- small
|
4
|
+
- medium
|
5
|
+
- large
|
6
|
+
- xlarge
|
7
|
+
|
8
|
+
properties:
|
9
|
+
- name: redis.resource
|
10
|
+
description: Resource/flavor of instance to use
|
11
|
+
- name: redis.security_group
|
12
|
+
description: Security group for instance(s). Must have TCP ports 22 & 6379 open.
|
13
|
+
default: default
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Then target that deployment file:
|
2
|
+
#
|
3
|
+
# $ bosh deployment path/to/file/above
|
4
|
+
#
|
5
|
+
# Then apply this template:
|
6
|
+
#
|
7
|
+
# $ bosh diff templates/openstack/single_vm.yml.erb
|
8
|
+
#
|
9
|
+
---
|
10
|
+
name: NAME
|
11
|
+
director_uuid: UUID
|
12
|
+
networks: {}
|
13
|
+
properties:
|
14
|
+
redis:
|
15
|
+
resource: medium
|
16
|
+
security_group: redis-server
|
@@ -0,0 +1,107 @@
|
|
1
|
+
---
|
2
|
+
<%-
|
3
|
+
# Example source deployment file that can be used:
|
4
|
+
# ---
|
5
|
+
# name: NAME
|
6
|
+
# director_uuid: 4ae3a0f0-70a5-4c0d-95f2-7fafaefe8b9e
|
7
|
+
# networks: {}
|
8
|
+
# properties:
|
9
|
+
# redis:
|
10
|
+
# instance_type: m1.medium
|
11
|
+
# security_groups: redis-server
|
12
|
+
#
|
13
|
+
# Then target that deployment file:
|
14
|
+
#
|
15
|
+
# $ bosh deployment path/to/file/above
|
16
|
+
#
|
17
|
+
# Then apply this template:
|
18
|
+
#
|
19
|
+
# $ bosh diff templates/openstack/single_vm.yml.erb
|
20
|
+
#
|
21
|
+
redis_sg = find("properties.redis.security_group")
|
22
|
+
redis_port = 6379
|
23
|
+
redis_password = random_string 12, :redis
|
24
|
+
redis_resource = find("properties.redis.resource")
|
25
|
+
puts "export REDIS_URL=redis://:#{redis_password}@HOST:#{redis_port}/0"
|
26
|
+
-%>
|
27
|
+
name: <%= find("name") %>
|
28
|
+
director_uuid: <%= find("director_uuid") %>
|
29
|
+
|
30
|
+
release:
|
31
|
+
name: redis
|
32
|
+
version: latest
|
33
|
+
|
34
|
+
compilation:
|
35
|
+
workers: 10
|
36
|
+
network: default
|
37
|
+
reuse_compilation_vms: true
|
38
|
+
cloud_properties:
|
39
|
+
instance_type: m1.small
|
40
|
+
|
41
|
+
update:
|
42
|
+
canaries: 1
|
43
|
+
canary_watch_time: 30000-300000
|
44
|
+
update_watch_time: 30000-300000
|
45
|
+
max_in_flight: 4
|
46
|
+
max_errors: 1
|
47
|
+
|
48
|
+
networks:
|
49
|
+
- name: default
|
50
|
+
type: dynamic
|
51
|
+
cloud_properties:
|
52
|
+
security_groups:
|
53
|
+
- <%= redis_sg %>
|
54
|
+
|
55
|
+
resource_pools:
|
56
|
+
- name: small
|
57
|
+
network: default
|
58
|
+
size: <%= redis_resource == "small" ? 1 : 0 %>
|
59
|
+
stemcell:
|
60
|
+
name: bosh-stemcell
|
61
|
+
version: latest
|
62
|
+
cloud_properties:
|
63
|
+
instance_type: m1.small
|
64
|
+
|
65
|
+
- name: medium
|
66
|
+
network: default
|
67
|
+
size: <%= redis_resource == "medium" ? 1 : 0 %>
|
68
|
+
stemcell:
|
69
|
+
name: bosh-stemcell
|
70
|
+
version: latest
|
71
|
+
cloud_properties:
|
72
|
+
instance_type: m1.medium
|
73
|
+
|
74
|
+
- name: large
|
75
|
+
network: default
|
76
|
+
size: <%= redis_resource == "large" ? 1 : 0 %>
|
77
|
+
stemcell:
|
78
|
+
name: bosh-stemcell
|
79
|
+
version: latest
|
80
|
+
cloud_properties:
|
81
|
+
instance_type: m1.large
|
82
|
+
|
83
|
+
- name: xlarge
|
84
|
+
network: default
|
85
|
+
size: <%= redis_resource == "xlarge" ? 1 : 0 %>
|
86
|
+
stemcell:
|
87
|
+
name: bosh-stemcell
|
88
|
+
version: latest
|
89
|
+
cloud_properties:
|
90
|
+
instance_type: m1.xlarge
|
91
|
+
|
92
|
+
jobs:
|
93
|
+
- name: redis
|
94
|
+
template: redis
|
95
|
+
instances: 1
|
96
|
+
resource_pool: <%= redis_resource %>
|
97
|
+
networks:
|
98
|
+
- name: default
|
99
|
+
default:
|
100
|
+
- dns
|
101
|
+
- gateway
|
102
|
+
|
103
|
+
properties:
|
104
|
+
redis:
|
105
|
+
port: <%= redis_port %>
|
106
|
+
password: <%= redis_password %>
|
107
|
+
resource: <%= redis_resource %>
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
# for the #sh helper
|
4
|
+
require "rake"
|
5
|
+
require "rake/file_utils"
|
6
|
+
|
7
|
+
module RedisCfPlugin
|
8
|
+
class Plugin < CF::CLI
|
9
|
+
include FileUtils
|
10
|
+
|
11
|
+
desc "Prepare target bosh for deploying one or more Redis services"
|
12
|
+
group :services, :manage
|
13
|
+
def prepare_redis
|
14
|
+
within_bosh_release do
|
15
|
+
# the releases/index.yml contains all the available release versions in an unordered
|
16
|
+
# hash of hashes in YAML format:
|
17
|
+
# ---
|
18
|
+
# builds:
|
19
|
+
# af61f03c5ad6327e0795402f1c458f2fc6f21201:
|
20
|
+
# version: 3
|
21
|
+
# 39c029d0af9effc6913f3333434b894ff6433638:
|
22
|
+
# version: 1
|
23
|
+
# 5f5d0a7fb577fec3c09408c94f7abbe2d52a042c:
|
24
|
+
# version: 4
|
25
|
+
# f044d47e0183f084db9dac5a6ef00d7bd21c8451:
|
26
|
+
# version: 2
|
27
|
+
release_index = YAML.load_file("releases/index.yml")
|
28
|
+
latest_version = release_index["builds"].values.inject(0) do |max_version, release|
|
29
|
+
version = release["version"]
|
30
|
+
max_version < version ? version : max_version
|
31
|
+
end
|
32
|
+
|
33
|
+
sh "bosh upload release releases/*-#{latest_version}.yml"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO - size must be valid
|
38
|
+
# TODO - name must be unique (cf services & bosh deployments)
|
39
|
+
|
40
|
+
desc "Create a Redis service deployed upon target bosh"
|
41
|
+
group :services, :manage
|
42
|
+
input :name, desc: "Unique name for service (within bosh & cloud foundry)"
|
43
|
+
input :size, desc: "Size of provisioned VMs", default: "small"
|
44
|
+
input :security_group, desc: "Security group to assign to provisioned VMs", default: "default"
|
45
|
+
def create_redis
|
46
|
+
require "cli" # bosh_cli's director client library
|
47
|
+
service_name = input[:name] || "redis-#{Time.now.to_i}"
|
48
|
+
resource_size = input[:size]
|
49
|
+
security_group = input[:security_group]
|
50
|
+
|
51
|
+
bosh_uuid = bosh_director_client.get_status["uuid"]
|
52
|
+
bosh_cpi = bosh_director_client.get_status["cpi"]
|
53
|
+
|
54
|
+
template_file = File.join(bosh_release_dir, "templates", bosh_cpi, "single_vm.yml.erb")
|
55
|
+
|
56
|
+
# Create an initial deployment file; upon which the CPI-specific template will be applied below
|
57
|
+
# Initial file will look like:
|
58
|
+
# ---
|
59
|
+
# name: NAME
|
60
|
+
# director_uuid: UUID
|
61
|
+
# networks: {}
|
62
|
+
# properties:
|
63
|
+
# redis:
|
64
|
+
# resource: medium
|
65
|
+
# security_group: redis-server
|
66
|
+
deployment_file = "deployments/redis/#{service_name}.yml"
|
67
|
+
sh "mkdir -p deployments/redis"
|
68
|
+
line "Creating deployment file #{deployment_file}..."
|
69
|
+
File.open(deployment_file, "w") do |file|
|
70
|
+
file << {
|
71
|
+
"name" => service_name,
|
72
|
+
"director_uuid" => bosh_uuid,
|
73
|
+
"networks" => {},
|
74
|
+
"properties" => {
|
75
|
+
"redis" => {
|
76
|
+
"resource" => resource_size,
|
77
|
+
"security_group" => security_group
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}.to_yaml
|
81
|
+
end
|
82
|
+
|
83
|
+
sh "bosh deployment #{deployment_file}"
|
84
|
+
sh "bosh -n diff #{template_file}"
|
85
|
+
sh "bosh -n deploy"
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Show the redis URI for connection via bosh DNS"
|
89
|
+
group :services, :manage
|
90
|
+
def show_redis_uri
|
91
|
+
load_bosh_and_validate_current_deployment
|
92
|
+
print service_uri
|
93
|
+
end
|
94
|
+
|
95
|
+
desc "Bind current Redis service URI to current app via env variable"
|
96
|
+
input :app, argument: "required", desc: "Application to immediately bind to", from_given: by_name(:app)
|
97
|
+
input :env_var, desc: "Environment variable to bind redis URI (default $REDIS_URI)", default: "REDIS_URI"
|
98
|
+
group :services, :manage
|
99
|
+
def bind_redis_env_var
|
100
|
+
load_bosh_and_validate_current_deployment
|
101
|
+
env_var = input[:env_var]
|
102
|
+
app = input[:app]
|
103
|
+
invoke :set_env, app: app, name: env_var, value: service_uri, restart: true
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "Delete current Redis service"
|
107
|
+
group :services, :manage
|
108
|
+
def delete_redis
|
109
|
+
load_bosh_and_validate_current_deployment
|
110
|
+
sh "bosh delete deployment #{deployment_name}"
|
111
|
+
end
|
112
|
+
|
113
|
+
protected
|
114
|
+
def release_name
|
115
|
+
"redis"
|
116
|
+
end
|
117
|
+
|
118
|
+
def bosh_release_dir
|
119
|
+
File.expand_path("../../../bosh_release", __FILE__)
|
120
|
+
end
|
121
|
+
|
122
|
+
def within_bosh_release(&block)
|
123
|
+
chdir(bosh_release_dir, &block)
|
124
|
+
end
|
125
|
+
|
126
|
+
def bosh_director_client
|
127
|
+
@bosh_director_client ||= begin
|
128
|
+
command = ::Bosh::Cli::Command::Deployment.new
|
129
|
+
command.send(:auth_required)
|
130
|
+
command.director
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def deployment_file
|
135
|
+
@current_deployment_file ||= ::Bosh::Cli::Command::Deployment.new.deployment
|
136
|
+
end
|
137
|
+
|
138
|
+
def load_bosh_and_validate_current_deployment
|
139
|
+
require "cli" # bosh_cli's director client library
|
140
|
+
unless File.exists?(deployment_file)
|
141
|
+
fail "Target deployment file no longer exists: #{deployment_file}"
|
142
|
+
end
|
143
|
+
@deployment = YAML.load_file(deployment_file)
|
144
|
+
unless @deployment["release"] && @deployment["release"]["name"] == release_name
|
145
|
+
fail "Target deployment file is not for redis service: #{deployment_file}"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def deployment_name
|
150
|
+
@deployment["name"]
|
151
|
+
end
|
152
|
+
|
153
|
+
def service_uri
|
154
|
+
password = @deployment["properties"]["redis"]["password"]
|
155
|
+
port = @deployment["properties"]["redis"]["port"]
|
156
|
+
db = 0
|
157
|
+
"redis://:#{password}@#{server_host}:#{port}/#{db}"
|
158
|
+
end
|
159
|
+
|
160
|
+
# returns the first DNS entry for the running instance
|
161
|
+
def server_host
|
162
|
+
@server_host ||= begin
|
163
|
+
vms = bosh_director_client.fetch_vm_state(deployment_name, use_cache: false)
|
164
|
+
if vms.empty?
|
165
|
+
fail "Deployment has no running instances"
|
166
|
+
end
|
167
|
+
if vms.size > 1
|
168
|
+
warn "Deployment has more than 1 running instance (#{vms.size}); using first instance"
|
169
|
+
end
|
170
|
+
vm = vms.first
|
171
|
+
vm["dns"].first
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "redis-cf-plugin"
|
5
|
+
spec.version = "0.1.0"
|
6
|
+
spec.authors = ["Dr Nic Williams"]
|
7
|
+
spec.email = ["drnicwilliams@gmail.com"]
|
8
|
+
spec.description = %q{Create & bind dedicated Redis to Cloud Foundry apps using Bosh}
|
9
|
+
spec.summary = %q{Create & bind dedicated Redis to Cloud Foundry apps using Bosh}
|
10
|
+
spec.homepage = ""
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_runtime_dependency "cf", "~> 4.1"
|
19
|
+
spec.add_runtime_dependency "bosh_cli", "~> 1.5.0.pre"
|
20
|
+
spec.add_runtime_dependency "rake"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-cf-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dr Nic Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cf
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '4.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bosh_cli
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.5.0.pre
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.5.0.pre
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
description: Create & bind dedicated Redis to Cloud Foundry apps using Bosh
|
79
|
+
email:
|
80
|
+
- drnicwilliams@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- ChangeLog.md
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bosh_release/.final_builds/jobs/redis/index.yml
|
92
|
+
- bosh_release/.final_builds/packages/redis/index.yml
|
93
|
+
- bosh_release/config/.gitkeep
|
94
|
+
- bosh_release/config/final.yml
|
95
|
+
- bosh_release/jobs/.gitkeep
|
96
|
+
- bosh_release/packages/.gitkeep
|
97
|
+
- bosh_release/releases/index.yml
|
98
|
+
- bosh_release/releases/redis-1.yml
|
99
|
+
- bosh_release/src/.gitkeep
|
100
|
+
- bosh_release/templates/aws/sample_deployment_file.yml
|
101
|
+
- bosh_release/templates/aws/single_vm.yml.erb
|
102
|
+
- bosh_release/templates/aws/spec
|
103
|
+
- bosh_release/templates/openstack/sample_deployment_file.yml
|
104
|
+
- bosh_release/templates/openstack/single_vm.yml.erb
|
105
|
+
- lib/redis-cf-plugin/plugin.rb
|
106
|
+
- redis-cf-plugin.gemspec
|
107
|
+
homepage: ''
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
hash: -3377918208959437738
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
hash: -3377918208959437738
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.25
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Create & bind dedicated Redis to Cloud Foundry apps using Bosh
|
138
|
+
test_files: []
|