flash_kick 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +14 -0
- data/README.md +114 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flash_kick.gemspec +33 -0
- data/img/Flash_Kick.gif +0 -0
- data/lib/flash_kick/version.rb +3 -0
- data/lib/flash_kick.rb +14 -0
- data/lib/generators/flash_kick/base.rb +29 -0
- data/lib/generators/flash_kick/deployment_generator.rb +121 -0
- data/lib/generators/flash_kick/init_generator.rb +42 -0
- data/lib/generators/flash_kick/lib/question_helper.rb +50 -0
- data/lib/generators/flash_kick/lib/variable_store.rb +23 -0
- data/lib/generators/flash_kick/templates/_Vagrantfile +20 -0
- data/lib/generators/flash_kick/templates/_database.yml +18 -0
- data/lib/generators/flash_kick/templates/_deploy.rb +59 -0
- data/lib/generators/flash_kick/templates/_puma.rb +23 -0
- data/lib/generators/flash_kick/templates/_puma.sh +78 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/complete/tasks/main.yml +17 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/complete/templates/database.yml +9 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/complete/templates/secrets.yml +2 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/essentials/tasks/main.yml +43 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/essentials/templates/vimrc +470 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/nginx/tasks/main.yml +15 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/nginx/templates/platform.conf +24 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/nodejs/tasks/main.yml +6 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/postgresql/handlers/main.yml +3 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/postgresql/tasks/main.yml +39 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/postgresql/templates/pg_hba.conf +91 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/ruby/files/gemrc +5 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/ruby/tasks/gems.yml +6 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/ruby/tasks/main.yml +4 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/ruby/tasks/rbenv.yml +32 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/ruby/tasks/ruby.yml +15 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/security/tasks/fail2ban.yml +4 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/security/tasks/firewall.yml +8 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/security/tasks/main.yml +4 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/security/tasks/ssh_settings.yml +25 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/user/tasks/main.yml +6 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/variables/tasks/application.yml +21 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/variables/tasks/main.yml +3 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/roles/variables/tasks/session.yml +23 -0
- data/lib/generators/flash_kick/templates/ansible/playbooks/tasks/vagrant_settings.yml +3 -0
- data/lib/generators/flash_kick/templates/ansible/provision.sh +1 -0
- data/lib/generators/flash_kick/templates/ansible_templates/_hosts +3 -0
- data/lib/generators/flash_kick/templates/ansible_templates/playbooks/_production.yml +21 -0
- data/lib/generators/flash_kick/templates/ansible_templates/playbooks/_vagrant.yml +17 -0
- data/lib/generators/flash_kick/templates/ansible_templates/playbooks/group_vars/_all.yml +4 -0
- data/lib/generators/flash_kick/templates/env_templates/_development_env.yml +1 -0
- data/lib/generators/flash_kick/templates/env_templates/_production_env.yml +13 -0
- data/lib/generators/flash_kick/templates/env_templates/_test_env.yml +1 -0
- data/lib/generators/flash_kick/vagrant_generator.rb +56 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4a3e7d7b69bf1530a6cb8dd7bcc5f0398fe0c0d
|
4
|
+
data.tar.gz: 718576dc16ab910243fbd2f7daf59548d2a156b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abec3e82283446f6d851499aa18e0f194579e4186f427269651a6b29044126b1e316b4ecfc79945f4a3869ecef2c99b6fca6691885f11421bc31b2c9a82735fa
|
7
|
+
data.tar.gz: cbde8438a127018378c1949be896a64c5576a7f790b0ad71fd9e57ef29af81b3bb08f0e32760eb8c9983c69ac60f0a28906c29fd7c2889b9613e353232906cfa
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at hheelliioo@live.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 3, December 2016
|
3
|
+
|
4
|
+
Copyleft (ɔ) 2016 Helio Oliveira <hheelliioo@live.com>
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
7
|
+
copies of this license document, and changing it is allowed as long
|
8
|
+
as the name is changed.
|
9
|
+
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
14
|
+
1. Same as 0
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+

|
2
|
+
```
|
3
|
+
_____________ ______ ______ _____ ______
|
4
|
+
___ __/__ /_____ __________ /_ ___ /____(_)________ /__
|
5
|
+
__ /_ __ /_ __ `/_ ___/_ __ \ __ //_/_ /_ ___/_ //_/
|
6
|
+
_ __/ _ / / /_/ /_(__ )_ / / / _ ,< _ / / /__ _ ,<
|
7
|
+
/_/ /_/ \__,_/ /____/ /_/ /_/ /_/|_| /_/ \___/ /_/|_|
|
8
|
+
|
9
|
+
Flash kick = Ansible + Mina + Nginx + Puma
|
10
|
+
```
|
11
|
+
This gem is a fork of [Ahoy](https://github.com/npearson72/rails-ahoy)
|
12
|
+
|
13
|
+
# Flash Kick will generate everything you need to deploy your Rails application
|
14
|
+
|
15
|
+
* Ansible scripts to provision your server with Nginx, Ruby, PostgreSQL, and recommended security settings (ssh hardening, firewall, fail2ban, etc.)
|
16
|
+
* Mina scripts to deploy your Rails application
|
17
|
+
* Puma application server configuration files
|
18
|
+
* An *.env* directory that will use YAML to store your environment variables securely
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
**RECOMMENDATION:** You might want to first try this using a fresh Rails application so you can see how it effects your files before running this in your existing code base.
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
You'll need [Ansible](http://docs.ansible.com/ansible/intro_installation.html)
|
26
|
+
and [Mina](http://nadarei.co/mina/)
|
27
|
+
|
28
|
+
### Step 1
|
29
|
+
|
30
|
+
Add the gem to your Gemfile and bundle
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'flash_kick'
|
34
|
+
```
|
35
|
+
|
36
|
+
$ bundle install
|
37
|
+
|
38
|
+
Execute the following terminal command to launch flash_kick's interactive guide
|
39
|
+
|
40
|
+
$ rails g flash_kick:init
|
41
|
+
|
42
|
+
Continue to next step AFTER you complete the interactive guide
|
43
|
+
|
44
|
+
### Step 2
|
45
|
+
|
46
|
+
If you don't have a production *secret_key_base*, generate one using:
|
47
|
+
|
48
|
+
$ rake secret
|
49
|
+
|
50
|
+
This will produce something that looks like:
|
51
|
+
|
52
|
+
$ f67395912d0ddd0de80a734822e73b327d007809123...
|
53
|
+
|
54
|
+
Now just copy and paste it into the following file:
|
55
|
+
|
56
|
+
$ <YOUR RAILS APP>/.env/production_env.yml
|
57
|
+
|
58
|
+
**IMPORTANT:** At this point make sure to commit your changes and push them up to your repo!
|
59
|
+
|
60
|
+
### Step 3
|
61
|
+
|
62
|
+
**IMPORTANT:** For this step, you will need a freshly installed Ubuntu box with root ssh privileges. If you're not sure how to do this, contact your web hosting administrator.
|
63
|
+
|
64
|
+
From the root of your Rails application...
|
65
|
+
|
66
|
+
$ cd config/ansible && ./provision.sh production
|
67
|
+
|
68
|
+
Executing `provision.sh <RAILS ENVIRONMENT FOR DEPLOYED APP>` will launch the provisioning process and setup your box so it can run Rails using Nginx as the web server, Puma as your application server, and PostgreSQL as your database.
|
69
|
+
|
70
|
+
**NOTE:** This process may take a while (15 mins or so), so sit back and relax.
|
71
|
+
|
72
|
+
### Step 4
|
73
|
+
Once the provisioning process is complete, log into your box with the server user (ex: deployer)
|
74
|
+
|
75
|
+
$ ssh deployer@<YOUR SERVER IP>
|
76
|
+
|
77
|
+
Once in, get your server user's public key
|
78
|
+
|
79
|
+
$ cat ~/.ssh/id_rsa.pub
|
80
|
+
|
81
|
+
This will print out something like this:
|
82
|
+
|
83
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOv2hw90hySH+41A6NVjp6GXhBS/PUVmTot...
|
84
|
+
|
85
|
+
Copy the public key and paste it into your git repo [Github](https://developer.github.com/guides/using-ssh-agent-forwarding/), [Bitbucket](https://confluence.atlassian.com/bitbucket/repository-privacy-permissions-and-more-221449716.html) settings to allow SSH access.
|
86
|
+
|
87
|
+
### Step 5
|
88
|
+
Go back to the ***root of your Rails application and execute the following command:
|
89
|
+
|
90
|
+
$ mina production setup
|
91
|
+
|
92
|
+
Then...
|
93
|
+
|
94
|
+
$ mina production deploy
|
95
|
+
|
96
|
+
### Congratulations!
|
97
|
+
|
98
|
+
If everything worked as it should have, your Rails application should be up and running on the Web. Enjoy!
|
99
|
+
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
1. Fork it ( https://github.com/heliohead/flash_kick/fork )
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Create a new Pull Request
|
108
|
+
|
109
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/heliohead/flash_kick. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available under the terms of the [wtfpl](LICENSE.txt).
|
114
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flash_kick"
|
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/flash_kick.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flash_kick/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'flash_kick'
|
8
|
+
spec.version = FlashKick::VERSION
|
9
|
+
spec.authors = ['Helio Oliveira']
|
10
|
+
spec.email = ['hheelliioo@live.com']
|
11
|
+
|
12
|
+
spec.summary = 'Quick and painless Rails deployment'
|
13
|
+
spec.description = 'Generator for building ansible based provisioning scripts, and mina/puma deployment scripts'
|
14
|
+
spec.homepage = 'https://github.com/heliohead/flash_kick'
|
15
|
+
spec.license = 'wtfpl'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
+
end
|
data/img/Flash_Kick.gif
ADDED
Binary file
|
data/lib/flash_kick.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "flash_kick/version"
|
2
|
+
|
3
|
+
module FlashKick
|
4
|
+
def self.load_variables
|
5
|
+
begin
|
6
|
+
env_file = File.open(Rails.root + ".env/#{Rails.env}_env.yml", 'r')
|
7
|
+
if env_file
|
8
|
+
env_yaml = YAML.load(env_file)
|
9
|
+
env_yaml.each { |k,v| ENV[k.to_s.upcase] = v.to_s } if env_yaml.present?
|
10
|
+
end
|
11
|
+
rescue
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'generators/flash_kick/base'
|
2
|
+
|
3
|
+
module FlashKick
|
4
|
+
module Initialize
|
5
|
+
def root
|
6
|
+
File.dirname(__FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def temp_dir
|
10
|
+
File.join(File.dirname(__FILE__), 'tmp/')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Generator
|
15
|
+
extend Initialize
|
16
|
+
|
17
|
+
class Base < Rails::Generators::Base
|
18
|
+
def self.source_root
|
19
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def question(type, &block)
|
25
|
+
FlashKick::QuestionHelper.question(type, &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'generators/flash_kick/base'
|
3
|
+
require 'generators/flash_kick/lib/question_helper'
|
4
|
+
require 'generators/flash_kick/lib/variable_store'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module FlashKick
|
8
|
+
class DeploymentGenerator < FlashKick::Generator::Base
|
9
|
+
|
10
|
+
def prompt_user
|
11
|
+
question :string do
|
12
|
+
{
|
13
|
+
app_name: 'What is the name of your application? [enter for default]',
|
14
|
+
default: Rails.application.class.parent_name.underscore
|
15
|
+
}
|
16
|
+
end
|
17
|
+
question :string do
|
18
|
+
{
|
19
|
+
server_domain: 'Which domain will you be deploying to? [enter for default]',
|
20
|
+
required: true
|
21
|
+
}
|
22
|
+
end
|
23
|
+
question :string do
|
24
|
+
{
|
25
|
+
server_user: 'Enter a name for your server user',
|
26
|
+
required: true
|
27
|
+
}
|
28
|
+
end
|
29
|
+
question :string do
|
30
|
+
{
|
31
|
+
server_ssh_port: 'What SSH port would you like to use on your server? [enter for default]',
|
32
|
+
default: '22'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
question :string do
|
36
|
+
{
|
37
|
+
ruby_version: 'Which version of Ruby would you like to install? [enter for default]',
|
38
|
+
default: '2.1.5'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
question :string do
|
42
|
+
{
|
43
|
+
postgresql_version: 'Which version of PostgreSQL would you like to install? [enter for default]',
|
44
|
+
default: '9.3'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
question :string do
|
48
|
+
{
|
49
|
+
database_name: 'Enter a name for your production database',
|
50
|
+
default: Rails.application.class.parent_name.underscore + '_production'
|
51
|
+
}
|
52
|
+
end
|
53
|
+
question :string do
|
54
|
+
{
|
55
|
+
database_user: 'Enter a name for your production database user',
|
56
|
+
required: true
|
57
|
+
}
|
58
|
+
end
|
59
|
+
question :string do
|
60
|
+
{
|
61
|
+
database_password: 'Enter a password for your production database',
|
62
|
+
required: true
|
63
|
+
}
|
64
|
+
end
|
65
|
+
question :string do
|
66
|
+
{
|
67
|
+
app_repo: 'What is the github repository for this application?',
|
68
|
+
required: true
|
69
|
+
}
|
70
|
+
end
|
71
|
+
question :string do
|
72
|
+
{
|
73
|
+
app_repo_branch: 'Which repository branch will be used for deployment? [enter for default]',
|
74
|
+
default: 'master'
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def copy_directory
|
80
|
+
directory 'ansible', 'config/ansible'
|
81
|
+
end
|
82
|
+
|
83
|
+
def copy_files
|
84
|
+
copy_file 'env_templates/_development_env.yml', '.env/development_env.yml'
|
85
|
+
copy_file 'env_templates/_test_env.yml', '.env/test_env.yml'
|
86
|
+
end
|
87
|
+
|
88
|
+
def copy_templates
|
89
|
+
template 'ansible_templates/_hosts', 'config/ansible/hosts'
|
90
|
+
template 'ansible_templates/playbooks/_production.yml', 'config/ansible/playbooks/production.yml'
|
91
|
+
template 'ansible_templates/playbooks/group_vars/_all.yml', 'config/ansible/playbooks/group_vars/all.yml'
|
92
|
+
template '_puma.sh', 'bin/puma.sh'
|
93
|
+
template '_puma.rb', 'config/puma.rb'
|
94
|
+
template '_deploy.rb', 'config/deploy.rb'
|
95
|
+
template 'env_templates/_production_env.yml', '.env/production_env.yml'
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_gems
|
99
|
+
gem 'puma'
|
100
|
+
gem 'rb-readline'
|
101
|
+
end
|
102
|
+
|
103
|
+
def modify_files
|
104
|
+
append_file '.gitignore', '.env/'
|
105
|
+
inject_into_file 'config/environment.rb', after: "require File.expand_path('../application', __FILE__)\n\n" do <<-'RUBY'
|
106
|
+
FlashKick.load_variables
|
107
|
+
|
108
|
+
RUBY
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def change_permissions
|
113
|
+
FileUtils.chmod 0751, 'config/ansible/provision.sh'
|
114
|
+
FileUtils.chmod 0751, 'bin/puma.sh'
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_symlinks
|
118
|
+
FileUtils.ln_s '../../../../.env/production_env.yml', 'config/ansible/playbooks/group_vars/production.yml'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'flash_kick/version'
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'generators/flash_kick/base'
|
4
|
+
require 'generators/flash_kick/lib/variable_store'
|
5
|
+
|
6
|
+
module FlashKick
|
7
|
+
class InitGenerator < FlashKick::Generator::Base
|
8
|
+
|
9
|
+
def init
|
10
|
+
FlashKick::VariableStore.mkdir_tmp
|
11
|
+
section_divider
|
12
|
+
masthead
|
13
|
+
section_divider
|
14
|
+
generate 'flash_kick:deployment'
|
15
|
+
section_divider
|
16
|
+
generate 'flash_kick:vagrant'
|
17
|
+
section_divider
|
18
|
+
puts 'Finalizing...'
|
19
|
+
section_divider
|
20
|
+
puts 'Finished!'
|
21
|
+
FlashKick::VariableStore.rm_tmp
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def section_divider
|
28
|
+
puts '=' * 100
|
29
|
+
end
|
30
|
+
|
31
|
+
def masthead
|
32
|
+
puts ' _____________ ______ ______ _____ ______ '
|
33
|
+
puts ' ___ __/__ /_____ __________ /_ ___ /____(_)________ /__ ' + ' FlashKick!'
|
34
|
+
puts ' __ /_ __ /_ __ `/_ ___/_ __ \ __ //_/_ /_ ___/_ //_/ ' + ' Get your Rails app deployed'
|
35
|
+
puts ' _ __/ _ / / /_/ /_(__ )_ / / / _ ,< _ / / /__ _ ,< '
|
36
|
+
puts ' /_/ /_/ \__,_/ /____/ /_/ /_/ /_/|_| /_/ \___/ /_/|_| ' + " v.#{FlashKick::VERSION}"
|
37
|
+
puts ' _________________________________________________________________ '
|
38
|
+
puts ' Flash kick = Ansible + Mina + Nginx + Puma '
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'generators/flash_kick/lib/variable_store'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module FlashKick
|
5
|
+
class QuestionHelper
|
6
|
+
|
7
|
+
cattr_accessor :required
|
8
|
+
|
9
|
+
def self.question(type, &block)
|
10
|
+
question_hash = block.call
|
11
|
+
@@required = question_hash[:required]
|
12
|
+
default = question_hash[:default]
|
13
|
+
key = question_hash.keys[0]
|
14
|
+
question = "#{question_hash[key]}:"
|
15
|
+
|
16
|
+
question_divider(default)
|
17
|
+
|
18
|
+
case type
|
19
|
+
when :string
|
20
|
+
string_question(question, key, default)
|
21
|
+
when :boolean
|
22
|
+
boolean_question(question, key, default)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.string_question(question, key, default=nil)
|
27
|
+
if @@required == true
|
28
|
+
answer = ''
|
29
|
+
until answer != ''
|
30
|
+
answer = Thor.new.ask(question)
|
31
|
+
FlashKick::VariableStore.add_variable(key, answer.empty? ? default : answer)
|
32
|
+
puts "Answer required, but you can always change it later!!!\n\n" if answer == ''
|
33
|
+
end
|
34
|
+
else
|
35
|
+
answer = Thor.new.ask(question)
|
36
|
+
FlashKick::VariableStore.add_variable(key, answer.empty? ? default : answer)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.boolean_question(question, key, default=nil)
|
41
|
+
answer = Thor.new.yes?(question)
|
42
|
+
FlashKick::VariableStore.add_variable(key, answer == true ? answer : false)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.question_divider(value=nil)
|
46
|
+
puts '-' * 100
|
47
|
+
puts "Default: #{value}" unless value.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'generators/flash_kick/base'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module FlashKick
|
6
|
+
class VariableStore
|
7
|
+
def self.add_variable(key, value)
|
8
|
+
File.open(FlashKick::Generator.temp_dir + "variables.yml", 'a') {|f| f.write("#{key}: #{value}\n") }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.variables
|
12
|
+
YAML.load(File.open(FlashKick::Generator.temp_dir + "variables.yml", 'r'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.mkdir_tmp
|
16
|
+
FileUtils.mkdir(FlashKick::Generator.root + '/tmp')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.rm_tmp
|
20
|
+
FileUtils.remove_dir(FlashKick::Generator.root + '/tmp')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
VAGRANTFILE_API_VERSION = 2
|
5
|
+
|
6
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
7
|
+
config.vm.box = 'hashicorp/precise64'
|
8
|
+
|
9
|
+
config.vm.network :forwarded_port, guest: 3000, host: 3000
|
10
|
+
|
11
|
+
config.vm.provider 'virtualbox' do |v|
|
12
|
+
v.memory = <%= FlashKick::VariableStore.variables['vagrant_memory'].to_i * 1024 %>
|
13
|
+
v.cpus = <%= FlashKick::VariableStore.variables['vagrant_cpus'].to_i %>
|
14
|
+
end
|
15
|
+
|
16
|
+
config.vm.provision 'ansible' do |ansible|
|
17
|
+
ansible.playbook = 'config/ansible/playbooks/vagrant.yml'
|
18
|
+
ansible.limit = 'default'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: postgresql
|
3
|
+
host: localhost
|
4
|
+
encoding: unicode
|
5
|
+
ctype: en_US.utf8
|
6
|
+
collation: en_US.utf8
|
7
|
+
template: template0
|
8
|
+
pool: 5
|
9
|
+
username: vagrant
|
10
|
+
password: vagrant
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: <%= FlashKick::VariableStore.variables['app_name'] %>_development
|
15
|
+
|
16
|
+
test:
|
17
|
+
<<: *default
|
18
|
+
database: <%= FlashKick::VariableStore.variables['app_name'] %>_test
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'mina/bundler'
|
2
|
+
require 'mina/rails'
|
3
|
+
require 'mina/git'
|
4
|
+
require 'mina/rbenv'
|
5
|
+
|
6
|
+
set :deploy_to, '/var/www/<%= FlashKick::VariableStore.variables['app_name'] %>'
|
7
|
+
set :app_path, '/var/www/<%= FlashKick::VariableStore.variables['app_name'] %>/current'
|
8
|
+
set :user, '<%= FlashKick::VariableStore.variables['server_user'] %>'
|
9
|
+
set :port, '<%= FlashKick::VariableStore.variables['server_ssh_port'] %>'
|
10
|
+
set :repository, '<%= FlashKick::VariableStore.variables['app_repo'] %>'
|
11
|
+
set :forward_agent, true
|
12
|
+
|
13
|
+
task :production do
|
14
|
+
set :domain, '<%= FlashKick::VariableStore.variables['server_domain'] %>'
|
15
|
+
set :branch, '<%= FlashKick::VariableStore.variables['app_repo_branch'] %>'
|
16
|
+
set :rails_env, 'production'
|
17
|
+
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log', 'tmp', '.env/production_env.yml']
|
18
|
+
end
|
19
|
+
|
20
|
+
task :environment do
|
21
|
+
queue 'export PATH=/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH'
|
22
|
+
queue 'source ~/.session_vars'
|
23
|
+
end
|
24
|
+
|
25
|
+
task setup: :environment do
|
26
|
+
queue "mkdir -m 750 -p #{deploy_to}/#{shared_path}/log"
|
27
|
+
queue "mkdir -m 750 -p #{deploy_to}/#{shared_path}/config"
|
28
|
+
queue "mkdir -m 750 -p #{deploy_to}/#{shared_path}/tmp/log"
|
29
|
+
queue "mkdir -m 750 -p #{deploy_to}/#{shared_path}/tmp/pids"
|
30
|
+
queue "mkdir -m 750 -p #{deploy_to}/#{shared_path}/tmp/sockets"
|
31
|
+
end
|
32
|
+
|
33
|
+
task deploy: :environment do
|
34
|
+
deploy do
|
35
|
+
invoke :'git:clone'
|
36
|
+
invoke :'deploy:link_shared_paths'
|
37
|
+
invoke :'bundle:install'
|
38
|
+
invoke :'rails:db_migrate'
|
39
|
+
invoke :'rails:assets_precompile'
|
40
|
+
invoke :'deploy:cleanup'
|
41
|
+
to :launch do
|
42
|
+
invoke :'server:restart'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
namespace :server do
|
48
|
+
task start: :environment do
|
49
|
+
queue "cd #{app_path} && rails_env=#{rails_env} && bin/puma.sh start"
|
50
|
+
end
|
51
|
+
|
52
|
+
task stop: :environment do
|
53
|
+
queue "cd #{app_path} && rails_env=#{rails_env} && bin/puma.sh stop"
|
54
|
+
end
|
55
|
+
|
56
|
+
task restart: :environment do
|
57
|
+
queue "cd #{app_path} && rails_env=#{rails_env} && bin/puma.sh restart"
|
58
|
+
end
|
59
|
+
end
|