carina 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/carina.gemspec +25 -0
- data/lib/carina/generators/carina_generator.rb +47 -0
- data/lib/carina/version.rb +3 -0
- data/lib/carina.rb +5 -0
- data/lib/generators/carina/USAGE +8 -0
- data/lib/generators/carina/carina_generator.rb +62 -0
- data/lib/generators/carina/templates/Dockerfile +50 -0
- data/lib/generators/carina/templates/backup +15 -0
- data/lib/generators/carina/templates/config +19 -0
- data/lib/generators/carina/templates/deploy +72 -0
- data/lib/generators/carina/templates/lib +179 -0
- data/lib/generators/carina/templates/logstash.conf +31 -0
- data/lib/generators/carina/templates/puma.rb +29 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ee5a0288fc8ed82e450752c0597f2a2aba4fce0
|
4
|
+
data.tar.gz: b24cc6b07b5ae97e26d9da1ca783437d0280eddf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a134c01f428c1e2d4adc817b0d12b10b86c38dcc6a37ee1c822e73341a781cd68225a1abb1b816e0719d72ccaf67c0873d9dee8d6a25a57e7665cfe17c29cf4a
|
7
|
+
data.tar.gz: 6f4a213734b5c8619007cec0846d8af4757225213d96bb0b217238583fa3809a45ca86886b23889da1d028ab143a82f347e8b07f87268445e485d52ce396010d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Matt Darby
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Carina
|
2
|
+
|
3
|
+
This gem will create and help maintain an average Rails-based application's infrastructure needs on Rackspace's Carina offering ([GetCarina.com](getcarina.com))
|
4
|
+
|
5
|
+
#### Install
|
6
|
+
Add this to your `Gemfile`:
|
7
|
+
`gem 'carina', git: "https://github.com/getcarina/carina-gem.git"`
|
8
|
+
|
9
|
+
#### Generate
|
10
|
+
`rails g carina install`
|
11
|
+
|
12
|
+
#### Create Carina cluster (FREE)
|
13
|
+
`brew install carina`
|
14
|
+
`carina create <ClusterName>`
|
15
|
+
|
16
|
+
#### Configure
|
17
|
+
`vim carina/config`
|
18
|
+
|
19
|
+
#### Quickstart
|
20
|
+
`./carina/deploy bootstrap`
|
21
|
+
|
22
|
+
#### Deploying changes
|
23
|
+
`./carina/deploy latest`
|
24
|
+
|
25
|
+
#### Backing up Postgresql
|
26
|
+
`./carina/backup postgresql`
|
27
|
+
|
28
|
+
#### All Commands
|
29
|
+
```
|
30
|
+
./carina/deploy help
|
31
|
+
|
32
|
+
Commands:
|
33
|
+
deploy bootstrap # Build everything (idempotent)
|
34
|
+
deploy db_setup # Rebuild, load, migrate and seed the database
|
35
|
+
deploy elasticsearch # Rebuild the ElasticSearch container
|
36
|
+
deploy help [COMMAND] # Describe available commands or one specific command
|
37
|
+
deploy image # Rebuild the Rails image with current code
|
38
|
+
deploy info # Show the IP and port(s) your application is available
|
39
|
+
deploy interlock # Rebuild the Interlock container
|
40
|
+
deploy kibana # Rebuild the Kibana container
|
41
|
+
deploy latest # Deploy the latest Rails code
|
42
|
+
deploy logstash # Rebuild the Logstash container
|
43
|
+
deploy postgres # Rebuild the Postgresql container
|
44
|
+
|
45
|
+
|
46
|
+
./carina/backup help
|
47
|
+
|
48
|
+
Commands:
|
49
|
+
backup help [COMMAND] # Describe available commands or one specific command
|
50
|
+
backup postgresql # Backup Postgresql to file
|
51
|
+
```
|
52
|
+
|
53
|
+
#### URLs
|
54
|
+
* Main site: `http(s):\\<Domain>`
|
55
|
+
* Kibana: `http:\\<Domain>:5601`
|
56
|
+
* HAProxy: `http:\\<Domain>/haproxy?monitor`
|
57
|
+
|
58
|
+
#### Caveats
|
59
|
+
* This setup requires you access the cluster via domain name. If you're testing locally you can update your `/etc/hosts` file like so: `<ClusterIP> <DomainName>`
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "carina"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/carina.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carina/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "carina"
|
8
|
+
spec.version = Carina::VERSION
|
9
|
+
spec.authors = ["Matt Darby"]
|
10
|
+
spec.email = ["matt.darby@rackspace.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Easily bootstrap Rails on Rackspace's Carina}
|
13
|
+
spec.description = %q{Easily bootstrap Rails on Rackspace's Carina}
|
14
|
+
spec.homepage = "http://getcarina.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class CarinaGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_install_file
|
5
|
+
empty_directory "carina"
|
6
|
+
empty_directory "carina/ssl_certs"
|
7
|
+
|
8
|
+
copy_file "build", "carina/build"
|
9
|
+
copy_file "deploy", "carina/deploy"
|
10
|
+
copy_file "logstash.conf", "carina/logstash.conf"
|
11
|
+
copy_file "puma.rb", "config/puma.rb"
|
12
|
+
copy_file "Dockerfile", "Dockerfile"
|
13
|
+
copy_file "vars", "vars"
|
14
|
+
|
15
|
+
chmod "carina/build", 0777
|
16
|
+
chmod "carina/deploy", 0777
|
17
|
+
|
18
|
+
prod_log = %q{
|
19
|
+
require 'logstash-logger'
|
20
|
+
config.log_level = :debug
|
21
|
+
config.autoflush_log = true
|
22
|
+
config.logstash.formatter = :json_lines
|
23
|
+
config.logstash.buffer_max_items = 50
|
24
|
+
config.logstash.buffer_max_interval = 5
|
25
|
+
config.logstash.host = 'logstash'
|
26
|
+
config.logstash.type = :udp
|
27
|
+
config.logstash.port = 5228
|
28
|
+
}
|
29
|
+
|
30
|
+
gems = %q{
|
31
|
+
gem 'logstash-logger'
|
32
|
+
gem 'pg'
|
33
|
+
gem 'puma'
|
34
|
+
}
|
35
|
+
|
36
|
+
puts "\n"
|
37
|
+
puts "Please add the following code into config/environments/production.rb:"
|
38
|
+
puts prod_log
|
39
|
+
|
40
|
+
puts "\n"
|
41
|
+
puts "Please add the following gems to your Gemfile:"
|
42
|
+
puts gems
|
43
|
+
|
44
|
+
puts "\n"
|
45
|
+
puts "Now create a Carina cluster at getcarina.com."
|
46
|
+
end
|
47
|
+
end
|
data/lib/carina.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
class CarinaGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_install_file
|
5
|
+
empty_directory "carina"
|
6
|
+
empty_directory "carina/ssl"
|
7
|
+
|
8
|
+
copy_file "lib", "carina/lib"
|
9
|
+
copy_file "deploy", "carina/deploy"
|
10
|
+
copy_file "config", "carina/config"
|
11
|
+
copy_file "backup", "carina/backup"
|
12
|
+
copy_file "logstash.conf", "carina/logstash.conf"
|
13
|
+
copy_file "puma.rb", "config/puma.rb"
|
14
|
+
copy_file "Dockerfile", "Dockerfile"
|
15
|
+
|
16
|
+
chmod "carina/lib", 0777
|
17
|
+
chmod "carina/deploy", 0777
|
18
|
+
chmod "carina/config", 0777
|
19
|
+
chmod "carina/backup", 0777
|
20
|
+
|
21
|
+
prod_log = %q{
|
22
|
+
require 'logstash-logger'
|
23
|
+
config.log_level = :debug
|
24
|
+
config.autoflush_log = true
|
25
|
+
config.logstash.formatter = :json_lines
|
26
|
+
config.logstash.buffer_max_items = 50
|
27
|
+
config.logstash.buffer_max_interval = 5
|
28
|
+
config.logstash.host = 'logstash'
|
29
|
+
config.logstash.type = :udp
|
30
|
+
config.logstash.port = 5228
|
31
|
+
}
|
32
|
+
|
33
|
+
gems = %q{
|
34
|
+
gem 'logstash-logger'
|
35
|
+
gem 'pg'
|
36
|
+
gem 'puma'
|
37
|
+
}
|
38
|
+
|
39
|
+
db = %q{
|
40
|
+
production:
|
41
|
+
adapter: postgresql
|
42
|
+
encoding: unicode
|
43
|
+
database: <DatabaseName>
|
44
|
+
pool: 5
|
45
|
+
username: <%= ENV['POSTGRES_USER'] %>
|
46
|
+
password: <%= ENV['POSTGRES_PASSWORD'] %>
|
47
|
+
host: db
|
48
|
+
}
|
49
|
+
|
50
|
+
puts "\n"
|
51
|
+
puts "Please add the following code into config/environments/production.rb:"
|
52
|
+
puts prod_log
|
53
|
+
|
54
|
+
puts "\n"
|
55
|
+
puts "Please add the following gems to your Gemfile:"
|
56
|
+
puts gems
|
57
|
+
|
58
|
+
puts "\n"
|
59
|
+
puts "Please update config/database.yml:"
|
60
|
+
puts db
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
FROM ruby:2.2.1
|
2
|
+
MAINTAINER Matt Darby <matt.darby@rackspace.com>
|
3
|
+
RUN apt-get update && apt-get install -y \
|
4
|
+
autoconf \
|
5
|
+
automake \
|
6
|
+
bison \
|
7
|
+
build-essential \
|
8
|
+
curl \
|
9
|
+
g++ \
|
10
|
+
gawk \
|
11
|
+
gcc \
|
12
|
+
libc6-dev \
|
13
|
+
libffi-dev \
|
14
|
+
imagemagick \
|
15
|
+
libgdbm-dev \
|
16
|
+
libncurses5-dev \
|
17
|
+
libpq-dev \
|
18
|
+
libreadline6-dev \
|
19
|
+
libsqlite3-dev \
|
20
|
+
libssl-dev \
|
21
|
+
libtool \
|
22
|
+
libyaml-dev \
|
23
|
+
make \
|
24
|
+
nodejs \
|
25
|
+
nodejs-legacy \
|
26
|
+
npm \
|
27
|
+
patch \
|
28
|
+
pkg-config \
|
29
|
+
sqlite3 \
|
30
|
+
vim \
|
31
|
+
zlib1g-dev
|
32
|
+
|
33
|
+
RUN npm install -g phantomjs
|
34
|
+
RUN mkdir /my-app
|
35
|
+
WORKDIR /tmp
|
36
|
+
COPY Gemfile Gemfile
|
37
|
+
COPY Gemfile.lock Gemfile.lock
|
38
|
+
RUN bundle install --without development test
|
39
|
+
|
40
|
+
ADD . /my-app
|
41
|
+
WORKDIR /my-app
|
42
|
+
|
43
|
+
RUN rm -rf shared
|
44
|
+
RUN mkdir -p shared/logs shared/pids shared/sockets
|
45
|
+
RUN chown -R 777 shared/
|
46
|
+
|
47
|
+
RUN bundle exec rake assets:precompile
|
48
|
+
CMD bundle exec puma -p 3000 -C ./config/puma.rb
|
49
|
+
|
50
|
+
EXPOSE 3000
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
class CarinaBackup < Thor
|
6
|
+
|
7
|
+
desc "postgresql", "Backup Postgresql to file"
|
8
|
+
def postgresql
|
9
|
+
puts "Backing up Postgresql"
|
10
|
+
system "source carina/lib; backup_postgres"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
CarinaBackup.start
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Carina config
|
2
|
+
export CARINA_APIKEY='' # Rackspace API key
|
3
|
+
export CARINA_USERNAME='' # Rackspace username
|
4
|
+
export CARINA_CLUSTER='' # This is the name of the Carina cluster to use.
|
5
|
+
|
6
|
+
# Infrastructure config
|
7
|
+
export DOMAIN='' # This is the domain name you're deploying
|
8
|
+
export SCALE=3 # How many application containers you'd like to run (2 or 3 per core)
|
9
|
+
|
10
|
+
# Database config
|
11
|
+
export POSTGRES_PASSWORD='' # Postgresql password of choice
|
12
|
+
export POSTGRES_USER='postgres' # Postgresql user of choice
|
13
|
+
|
14
|
+
# Rails config
|
15
|
+
export LANG=en_US.UTF-8 # Default language for the application
|
16
|
+
export RAILS_ENV=production # Which RAILS_ENV to run under
|
17
|
+
export RACK_ENV=production # Which Rack ENV to run under
|
18
|
+
export RAILS_SERVE_STATIC_FILES=true # Ask Rails to serve static assets (images, css, js)
|
19
|
+
export SECRET_KEY_BASE='' # The secret key base of choice for your Rails application
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
class Carina < Thor
|
6
|
+
|
7
|
+
desc "bootstrap", "Build everything (idempotent)"
|
8
|
+
def bootstrap
|
9
|
+
puts "Bootstrapping cluster (idempotently)"
|
10
|
+
system "source carina/lib; build_all"
|
11
|
+
invoke :info
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "info", "Show the IP and port(s) your application is available"
|
15
|
+
def info
|
16
|
+
puts "\n\n#{ENV['DOMAIN']} is now available via:"
|
17
|
+
puts `source carina/lib; docker port interlock`
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "db_setup", "Rebuild, load, migrate and seed the database"
|
21
|
+
def db_setup
|
22
|
+
puts "Setting up DB"
|
23
|
+
system "source carina/lib; build_db_setup"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "latest", "Deploy the latest Rails code"
|
27
|
+
def latest
|
28
|
+
invoke :build_image
|
29
|
+
puts "Deploying image containers"
|
30
|
+
system "source carina/lib; build_deploy"
|
31
|
+
invoke :info
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "elasticsearch", "Rebuild the ElasticSearch container"
|
35
|
+
def elasticsearch
|
36
|
+
puts "Building Elasticsearch container"
|
37
|
+
system "source carina/lib; build_elasticsearch"
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "image", "Rebuild the Rails image with current code"
|
41
|
+
def build_image
|
42
|
+
puts "Building the Rails image"
|
43
|
+
system "source carina/lib; build_image"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "interlock", "Rebuild the Interlock container"
|
47
|
+
def interlock
|
48
|
+
puts "Building Interlock container"
|
49
|
+
system "source carina/lib; build_interlock"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "kibana", "Rebuild the Kibana container"
|
53
|
+
def kibana
|
54
|
+
puts "Building Kibana container"
|
55
|
+
system "source carina/lib; build_kibana"
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "logstash", "Rebuild the Logstash container"
|
59
|
+
def logstash
|
60
|
+
puts "Building Logstash container"
|
61
|
+
system "source carina/lib; build_logstash"
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "postgres", "Rebuild the Postgresql container"
|
65
|
+
def postgres
|
66
|
+
puts "Building Postgresql container"
|
67
|
+
system "source carina/lib; build_postgres"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
Carina.start
|
@@ -0,0 +1,179 @@
|
|
1
|
+
source $PWD/carina/config
|
2
|
+
eval $(carina env $CARINA_CLUSTER)
|
3
|
+
|
4
|
+
# -------------------
|
5
|
+
# UTILS
|
6
|
+
# -------------------
|
7
|
+
delete_if_exists() {
|
8
|
+
exists=$(docker inspect $1 2> /dev/null)
|
9
|
+
if [[ "$exists" != "[]" ]]; then
|
10
|
+
docker rm -f $1
|
11
|
+
fi
|
12
|
+
}
|
13
|
+
|
14
|
+
find_or_create_dvc() {
|
15
|
+
name=$1
|
16
|
+
path=$2
|
17
|
+
image=$3
|
18
|
+
exists=$(docker inspect $1 2> /dev/null)
|
19
|
+
|
20
|
+
if [[ "$exists" == "[]" ]]; then
|
21
|
+
echo "Creating ${name} data volume container"
|
22
|
+
docker create --name $name --volume $path $image
|
23
|
+
fi
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
# -------------------
|
28
|
+
# POSTGRESQL
|
29
|
+
# -------------------
|
30
|
+
|
31
|
+
build_postgres() {
|
32
|
+
find_or_create_dvc "pgdata" "/var/lib/postgresql/data" "postgres"
|
33
|
+
delete_if_exists "postgres"
|
34
|
+
|
35
|
+
docker run \
|
36
|
+
-d \
|
37
|
+
--name postgres \
|
38
|
+
-e POSTGRES_USER=$POSTGRES_USER \
|
39
|
+
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
40
|
+
--volumes-from pgdata \
|
41
|
+
postgres
|
42
|
+
}
|
43
|
+
|
44
|
+
backup_postgres() {
|
45
|
+
docker cp pgdata:/var/lib/postgresql/data pg_backup
|
46
|
+
tar cpjf postgresql-$(date +%Y%m%d%H%M%S).tar.gz pg_backup
|
47
|
+
rm -rf pg_backup
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
# -------------------
|
52
|
+
# ELASTICSEARCH
|
53
|
+
# -------------------
|
54
|
+
|
55
|
+
build_elasticsearch() {
|
56
|
+
find_or_create_dvc "esdata" "/usr/share/elasticsearch/data" "elasticsearch"
|
57
|
+
delete_if_exists "es"
|
58
|
+
|
59
|
+
docker run \
|
60
|
+
-d \
|
61
|
+
--name es \
|
62
|
+
-p 9200:9200 \
|
63
|
+
--volumes-from esdata \
|
64
|
+
elasticsearch
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
# -------------------
|
69
|
+
# LOGSTASH
|
70
|
+
# -------------------
|
71
|
+
|
72
|
+
build_logstash() {
|
73
|
+
delete_if_exists "logstash"
|
74
|
+
|
75
|
+
LOGSTASH=$(echo `cat $PWD/carina/logstash.conf`|tr -d '\n')
|
76
|
+
docker run \
|
77
|
+
-d \
|
78
|
+
--name logstash \
|
79
|
+
--link es:elasticsearch \
|
80
|
+
-p 5000:5000 \
|
81
|
+
-p 12201:12201/udp \
|
82
|
+
-p 5228:5228/udp \
|
83
|
+
logstash logstash -e "$LOGSTASH"
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
# -------------------
|
88
|
+
# KIBANA
|
89
|
+
# -------------------
|
90
|
+
|
91
|
+
build_kibana() {
|
92
|
+
delete_if_exists "kibana"
|
93
|
+
|
94
|
+
docker run \
|
95
|
+
-d \
|
96
|
+
-p 5601:5601 \
|
97
|
+
--name kibana \
|
98
|
+
--link es:elasticsearch \
|
99
|
+
kibana
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
# -------------------
|
104
|
+
# INTERLOCK
|
105
|
+
# -------------------
|
106
|
+
build_interlock() {
|
107
|
+
find_or_create_dvc "interlockdata" "/ssl" "ehazlett/interlock"
|
108
|
+
|
109
|
+
# docker cp carina/ssl_certs/* interlockdata:/ssl
|
110
|
+
|
111
|
+
delete_if_exists "interlock"
|
112
|
+
|
113
|
+
docker run -d \
|
114
|
+
--name interlock \
|
115
|
+
-p 80:80 \
|
116
|
+
--volumes-from swarm-data \
|
117
|
+
--volumes-from interlockdata \
|
118
|
+
ehazlett/interlock \
|
119
|
+
--debug \
|
120
|
+
--swarm-url $DOCKER_HOST \
|
121
|
+
--swarm-tls-ca-cert=/etc/docker/ca.pem \
|
122
|
+
--swarm-tls-cert=/etc/docker/server-cert.pem \
|
123
|
+
--swarm-tls-key=/etc/docker/server-key.pem \
|
124
|
+
--plugin haproxy start
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
# -------------------
|
129
|
+
# APP
|
130
|
+
# -------------------
|
131
|
+
|
132
|
+
build_image() {
|
133
|
+
docker build -t my-app .
|
134
|
+
}
|
135
|
+
|
136
|
+
build_deploy() {
|
137
|
+
for i in $(eval echo "{1..$SCALE}")
|
138
|
+
do
|
139
|
+
delete_if_exists "rails-${i}"
|
140
|
+
|
141
|
+
docker run \
|
142
|
+
-d \
|
143
|
+
-p :3000 \
|
144
|
+
--name rails-${i} \
|
145
|
+
--link postgres:db \
|
146
|
+
--link logstash:logstash \
|
147
|
+
--hostname $DOMAIN \
|
148
|
+
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
|
149
|
+
-e POSTGRES_USER=$POSTGRES_USER \
|
150
|
+
-e RAILS_ENV=$RAILS_ENV \
|
151
|
+
-e RACK_ENV=$RACK_ENV \
|
152
|
+
-e LOG_LEVEL=$LOG_LEVEL \
|
153
|
+
-e RAILS_SERVE_STATIC_FILES=$RAILS_SERVE_STATIC_FILES \
|
154
|
+
-e SECRET_KEY_BASE=$SECRET_KEY_BASE \
|
155
|
+
-e INTERLOCK_DATA='{"port": 3000, "warm": true}' \
|
156
|
+
-t my-app
|
157
|
+
done
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
# -------------------
|
162
|
+
# DB SETUP
|
163
|
+
# -------------------
|
164
|
+
|
165
|
+
build_db_setup() {
|
166
|
+
docker exec -it rails-1 rake db:setup db:seed
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
build_all() {
|
171
|
+
build_postgres
|
172
|
+
build_elasticsearch
|
173
|
+
build_logstash
|
174
|
+
build_kibana
|
175
|
+
build_interlock
|
176
|
+
build_image
|
177
|
+
build_deploy
|
178
|
+
build_db_setup
|
179
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
input {
|
2
|
+
gelf {
|
3
|
+
type => docker
|
4
|
+
port => 12201
|
5
|
+
}
|
6
|
+
|
7
|
+
udp {
|
8
|
+
type => rails
|
9
|
+
port => 5228
|
10
|
+
codec => json_lines
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
filter {
|
15
|
+
if [type] == "rails" {
|
16
|
+
multiline {
|
17
|
+
pattern => "^Started"
|
18
|
+
negate => true
|
19
|
+
what => "previous"
|
20
|
+
}
|
21
|
+
|
22
|
+
grok {
|
23
|
+
match => [ "message", "%{RAILS3}" ]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
output {
|
29
|
+
elasticsearch { hosts => [elasticsearch] }
|
30
|
+
stdout { codec => rubydebug }
|
31
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Change to match your CPU core count
|
2
|
+
workers 8
|
3
|
+
|
4
|
+
# Min and Max threads per worker
|
5
|
+
threads 1, 6
|
6
|
+
|
7
|
+
app_dir = File.expand_path("../..", __FILE__)
|
8
|
+
shared_dir = "#{app_dir}/shared"
|
9
|
+
|
10
|
+
# Default to production
|
11
|
+
rails_env = ENV['RAILS_ENV'] || "production"
|
12
|
+
environment rails_env
|
13
|
+
|
14
|
+
# Set up socket location
|
15
|
+
bind "unix://#{shared_dir}/sockets/puma.sock"
|
16
|
+
|
17
|
+
# Set master PID and state locations
|
18
|
+
pidfile "#{shared_dir}/pids/puma.pid"
|
19
|
+
state_path "#{shared_dir}/pids/puma.state"
|
20
|
+
activate_control_app
|
21
|
+
|
22
|
+
preload_app!
|
23
|
+
|
24
|
+
on_worker_boot do
|
25
|
+
require "active_record"
|
26
|
+
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
|
27
|
+
db_info = YAML.load(ERB.new(File.read("#{Rails.root}/config/database.yml")).result)[Rails.env]
|
28
|
+
ActiveRecord::Base.establish_connection(db_info)
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carina
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Darby
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Easily bootstrap Rails on Rackspace's Carina
|
56
|
+
email:
|
57
|
+
- matt.darby@rackspace.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- carina.gemspec
|
73
|
+
- lib/carina.rb
|
74
|
+
- lib/carina/generators/carina_generator.rb
|
75
|
+
- lib/carina/version.rb
|
76
|
+
- lib/generators/carina/USAGE
|
77
|
+
- lib/generators/carina/carina_generator.rb
|
78
|
+
- lib/generators/carina/templates/Dockerfile
|
79
|
+
- lib/generators/carina/templates/backup
|
80
|
+
- lib/generators/carina/templates/config
|
81
|
+
- lib/generators/carina/templates/deploy
|
82
|
+
- lib/generators/carina/templates/lib
|
83
|
+
- lib/generators/carina/templates/logstash.conf
|
84
|
+
- lib/generators/carina/templates/puma.rb
|
85
|
+
homepage: http://getcarina.com
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.8
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Easily bootstrap Rails on Rackspace's Carina
|
109
|
+
test_files: []
|