rails-ahoy 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/ahoy.rb +2 -8
- data/lib/ahoy/version.rb +1 -1
- data/lib/generators/ahoy/deployment_generator.rb +4 -7
- data/lib/generators/ahoy/templates/_deploy.rb +28 -21
- data/lib/generators/ahoy/templates/_puma.sh +3 -4
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/complete/tasks/main.yml +8 -5
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/complete/templates/database.yml +1 -1
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/complete/templates/secrets.yml +1 -1
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/application.yml +3 -3
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/main.yml +1 -1
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/session.yml +23 -0
- data/lib/generators/ahoy/templates/ansible/provision.sh +1 -0
- data/lib/generators/ahoy/templates/ansible_templates/{_production → _hosts} +0 -2
- data/lib/generators/ahoy/templates/env_templates/_production_env.yml +2 -1
- data/lib/generators/ahoy/vagrant_generator.rb +4 -0
- metadata +5 -6
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/system.yml +0 -25
- data/lib/generators/ahoy/templates/ansible/playbooks/roles/variables/templates/profile +0 -22
- data/lib/generators/ahoy/templates/ansible/production.sh +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08f470fbac5f3a6329f346ed0bcaed826b4d0714
|
4
|
+
data.tar.gz: 7d183a79ee04bcf6c00b079069024f32c4ff31dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a04b4b7ef531eed308ff3512bf4cca7eb2ab0a90938c3add31696ab4101d7581d3781fc714947ef186868fe1f1910ca7392aef0e131928f626188c351f507d93
|
7
|
+
data.tar.gz: 8f1e15943b9a4e478d579e9c61772a27eea92f54f79ebf2cbc33a9b451439cc2ddf0b7e701891a7899e025316ea90f7f3929ca2024f97943c5167f81af6aa46c
|
data/Gemfile
CHANGED
data/lib/ahoy.rb
CHANGED
@@ -3,13 +3,7 @@ require 'ahoy'
|
|
3
3
|
|
4
4
|
module Ahoy
|
5
5
|
def self.env
|
6
|
-
|
7
|
-
|
8
|
-
rescue
|
9
|
-
if env_file
|
10
|
-
env_yaml = YAML.load(env_file)
|
11
|
-
env_yaml.each { |k,v| ENV[k.to_s.upcase] = v.to_s } if env_yaml.present?
|
12
|
-
end
|
13
|
-
end
|
6
|
+
env_yaml = YAML.load(File.open(Rails.root + ".env/#{Rails.env}_env.yml", 'r'))
|
7
|
+
env_yaml.each { |k,v| ENV[k.to_s.upcase] = v.to_s } if env_yaml.present?
|
14
8
|
end
|
15
9
|
end
|
data/lib/ahoy/version.rb
CHANGED
@@ -86,7 +86,7 @@ module Ahoy
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def copy_templates
|
89
|
-
template 'ansible_templates/
|
89
|
+
template 'ansible_templates/_hosts', 'config/ansible/hosts'
|
90
90
|
template 'ansible_templates/playbooks/_production.yml', 'config/ansible/playbooks/production.yml'
|
91
91
|
template 'ansible_templates/playbooks/group_vars/_all.yml', 'config/ansible/playbooks/group_vars/all.yml'
|
92
92
|
template '_puma.sh', 'bin/puma.sh'
|
@@ -96,15 +96,12 @@ module Ahoy
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def add_gems
|
99
|
-
|
100
|
-
|
101
|
-
gem 'rb-readline'
|
102
|
-
end
|
99
|
+
gem 'puma'
|
100
|
+
gem 'rb-readline'
|
103
101
|
end
|
104
102
|
|
105
103
|
def modify_files
|
106
104
|
append_file '.gitignore', '.env/'
|
107
|
-
prepend_file 'config/environment.rb', "require 'ahoy'\n"
|
108
105
|
inject_into_file 'config/environment.rb', after: "require File.expand_path('../application', __FILE__)\n\n" do <<-'RUBY'
|
109
106
|
Ahoy.env
|
110
107
|
|
@@ -113,7 +110,7 @@ Ahoy.env
|
|
113
110
|
end
|
114
111
|
|
115
112
|
def change_permissions
|
116
|
-
FileUtils.chmod 0751, 'config/ansible/
|
113
|
+
FileUtils.chmod 0751, 'config/ansible/provision.sh'
|
117
114
|
FileUtils.chmod 0751, 'bin/puma.sh'
|
118
115
|
end
|
119
116
|
|
@@ -3,33 +3,34 @@ require 'mina/rails'
|
|
3
3
|
require 'mina/git'
|
4
4
|
require 'mina/rbenv'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
set :deploy_to, '/var/www/<%= Ahoy::VariableStore.variables['app_name'] %>'
|
7
|
+
set :app_path, '/var/www/<%= Ahoy::VariableStore.variables['app_name'] %>/current'
|
8
|
+
set :user, '<%= Ahoy::VariableStore.variables['server_user'] %>'
|
9
|
+
set :port, '<%= Ahoy::VariableStore.variables['server_ssh_port'] %>'
|
10
|
+
set :repository, '<%= Ahoy::VariableStore.variables['app_repo'] %>'
|
11
|
+
set :forward_agent, true
|
12
|
+
|
13
|
+
task :production do
|
8
14
|
set :domain, '<%= Ahoy::VariableStore.variables['server_domain'] %>'
|
9
|
-
set :port, '<%= Ahoy::VariableStore.variables['server_ssh_port'] %>'
|
10
|
-
set :repository, '<%= Ahoy::VariableStore.variables['app_repo'] %>'
|
11
15
|
set :branch, '<%= Ahoy::VariableStore.variables['app_repo_branch'] %>'
|
12
|
-
set :
|
13
|
-
set :deploy_to, '/var/www/<%= Ahoy::VariableStore.variables['app_name'] %>'
|
14
|
-
set :app_path, '/var/www/<%= Ahoy::VariableStore.variables['app_name'] %>/current'
|
16
|
+
set :rails_env, 'production'
|
15
17
|
set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log', 'tmp', '.env/production_env.yml']
|
16
18
|
end
|
17
19
|
|
18
|
-
task :production do
|
19
|
-
invoke :setup_variables
|
20
|
-
end
|
21
|
-
|
22
20
|
task :environment do
|
23
|
-
queue
|
21
|
+
queue 'export PATH=/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH'
|
22
|
+
queue 'source ~/.session_vars'
|
24
23
|
end
|
25
24
|
|
26
|
-
task :
|
27
|
-
|
28
|
-
|
29
|
-
|
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"
|
30
31
|
end
|
31
32
|
|
32
|
-
task :
|
33
|
+
task deploy: :environment do
|
33
34
|
deploy do
|
34
35
|
invoke :'git:clone'
|
35
36
|
invoke :'deploy:link_shared_paths'
|
@@ -44,9 +45,15 @@ task :deploy => :environment do
|
|
44
45
|
end
|
45
46
|
|
46
47
|
namespace :server do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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"
|
51
58
|
end
|
52
59
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
#! /bin/sh
|
2
2
|
|
3
3
|
BUNDLE_BIN=/usr/local/rbenv/shims/bundle
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
PUMA_SOCKET=$APP_PATH/shared/tmp/sockets/puma.sock
|
4
|
+
PUMA_CONFIG_FILE=$APP_ROOT/current/config/puma.rb
|
5
|
+
PUMA_PID_FILE=$APP_ROOT/shared/tmp/pids/puma.pid
|
6
|
+
PUMA_SOCKET=$APP_ROOT/shared/tmp/sockets/puma.sock
|
8
7
|
|
9
8
|
# check if puma process is running
|
10
9
|
puma_is_running() {
|
@@ -1,14 +1,17 @@
|
|
1
1
|
---
|
2
2
|
- name: create config directory
|
3
3
|
sudo: true
|
4
|
-
file: path
|
4
|
+
file: path={{app_root}}/shared/config owner={{server_user}} group={{server_user}} recurse=yes state=directory
|
5
5
|
|
6
6
|
- name: copy database.yml
|
7
|
-
template: src=database.yml dest
|
7
|
+
template: src=database.yml dest={{app_root}}/shared/config/database.yml owner={{server_user}} group={{server_user}}
|
8
8
|
|
9
9
|
- name: copy secrets.yml
|
10
|
-
template: src=secrets.yml dest
|
10
|
+
template: src=secrets.yml dest={{app_root}}/shared/config/secrets.yml owner={{server_user}} group={{server_user}}
|
11
11
|
|
12
|
-
- name: update
|
12
|
+
- name: update app root directory permissions
|
13
13
|
sudo: true
|
14
|
-
file: path
|
14
|
+
file: path={{app_root}} owner={{server_user}} group={{server_user}} recurse=yes state=directory
|
15
|
+
|
16
|
+
- name: add symlink to app root
|
17
|
+
file: src={{app_root}} dest=/home/{{server_user}}/app owner={{server_user}} group={{server_user}} state=link
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
{{rails_env}}:
|
2
2
|
secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
|
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
- name: check if .env exists
|
3
|
-
stat: path
|
3
|
+
stat: path={{app_root}}/shared/.env/{{rails_env}}_env.yml
|
4
4
|
register: env_file
|
5
5
|
|
6
6
|
- name: delete .env if exists
|
7
|
-
shell: rm
|
7
|
+
shell: rm {{app_root}}/shared/.env/{{rails_env}}_env.yml
|
8
8
|
when: env_file.stat.exists == true
|
9
9
|
|
10
10
|
- name: add environment variables to .env
|
11
11
|
lineinfile:
|
12
|
-
dest
|
12
|
+
dest={{app_root}}/shared/.env/{{rails_env}}_env.yml
|
13
13
|
line='{{item}}'
|
14
14
|
owner={{server_user}}
|
15
15
|
insertafter=EOF
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
- name: check if .session_vars exists
|
3
|
+
stat: path=/home/{{server_user}}/.session_vars
|
4
|
+
register: session_vars
|
5
|
+
|
6
|
+
- name: delete .session_vars if exists
|
7
|
+
shell: rm /home/{{server_user}}/.session_vars
|
8
|
+
when: session_vars.stat.exists == true
|
9
|
+
|
10
|
+
- name: add environment variables to .session_vars
|
11
|
+
lineinfile:
|
12
|
+
dest=/home/{{server_user}}/.session_vars
|
13
|
+
line='{{item}}'
|
14
|
+
owner={{server_user}}
|
15
|
+
insertafter=EOF
|
16
|
+
create=true
|
17
|
+
with_items:
|
18
|
+
- 'export APP_NAME={{app_name}}'
|
19
|
+
- 'export APP_ROOT={{app_root}}'
|
20
|
+
- 'export RAILS_ENV={{rails_env}}'
|
21
|
+
|
22
|
+
- name: source .session_vars from .bashrc
|
23
|
+
lineinfile: dest=/home/{{server_user}}/.bashrc insertafter=EOF line='source ~/.session_vars'
|
@@ -0,0 +1 @@
|
|
1
|
+
ansible-playbook playbooks/$1.yml -i hosts
|
@@ -1,5 +1,3 @@
|
|
1
1
|
[production]
|
2
2
|
root ansible_ssh_host=<%= Ahoy::VariableStore.variables['server_domain'] == '' ? '127.0.0.1' : Ahoy::VariableStore.variables['server_domain'] %>
|
3
|
-
|
4
|
-
[production]
|
5
3
|
deploy ansible_ssh_host=<%= Ahoy::VariableStore.variables['server_domain'] == '' ? '127.0.0.1' : Ahoy::VariableStore.variables['server_domain'] %> ansible_ssh_port=<%= Ahoy::VariableStore.variables['server_ssh_port'] == '' ? '22' : Ahoy::VariableStore.variables['server_ssh_port'] %>
|
@@ -2,8 +2,9 @@
|
|
2
2
|
server_user: <%= Ahoy::VariableStore.variables['server_user'] %>
|
3
3
|
server_domain: <%= Ahoy::VariableStore.variables['server_domain'] %>
|
4
4
|
server_ssh_port: <%= Ahoy::VariableStore.variables['server_ssh_port'] %>
|
5
|
+
rails_env: production
|
5
6
|
app_name: <%= Ahoy::VariableStore.variables['app_name'] %>
|
6
|
-
app_root:
|
7
|
+
app_root: /var/www/<%= Ahoy::VariableStore.variables['app_name'] %>
|
7
8
|
database_name: <%= Ahoy::VariableStore.variables['database_name'] %>
|
8
9
|
database_user: <%= Ahoy::VariableStore.variables['database_user'] %>
|
9
10
|
database_password: <%= Ahoy::VariableStore.variables['database_password'] %>
|
@@ -40,6 +40,10 @@ module Ahoy
|
|
40
40
|
copy_file 'ansible_templates/playbooks/_vagrant.yml', 'config/ansible/playbooks/vagrant.yml'
|
41
41
|
end
|
42
42
|
|
43
|
+
def modify_files
|
44
|
+
append_file '.gitignore', "\n.vagrant/"
|
45
|
+
end
|
46
|
+
|
43
47
|
def backup_files
|
44
48
|
FileUtils.mv 'config/database.yml', 'config/database.yml.bak'
|
45
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-ahoy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,11 +87,10 @@ files:
|
|
87
87
|
- lib/generators/ahoy/templates/ansible/playbooks/roles/user/tasks/main.yml
|
88
88
|
- lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/application.yml
|
89
89
|
- lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/main.yml
|
90
|
-
- lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/
|
91
|
-
- lib/generators/ahoy/templates/ansible/playbooks/roles/variables/templates/profile
|
90
|
+
- lib/generators/ahoy/templates/ansible/playbooks/roles/variables/tasks/session.yml
|
92
91
|
- lib/generators/ahoy/templates/ansible/playbooks/tasks/vagrant_settings.yml
|
93
|
-
- lib/generators/ahoy/templates/ansible/
|
94
|
-
- lib/generators/ahoy/templates/ansible_templates/
|
92
|
+
- lib/generators/ahoy/templates/ansible/provision.sh
|
93
|
+
- lib/generators/ahoy/templates/ansible_templates/_hosts
|
95
94
|
- lib/generators/ahoy/templates/ansible_templates/playbooks/_production.yml
|
96
95
|
- lib/generators/ahoy/templates/ansible_templates/playbooks/_vagrant.yml
|
97
96
|
- lib/generators/ahoy/templates/ansible_templates/playbooks/group_vars/_all.yml
|
@@ -1,25 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- name: check if .profile exists
|
3
|
-
stat: path=/home/{{server_user}}/.profile
|
4
|
-
register: profile_file
|
5
|
-
|
6
|
-
- name: delete .profile if exists
|
7
|
-
shell: rm /home/{{server_user}}/.profile
|
8
|
-
when: profile_file.stat.exists == true
|
9
|
-
|
10
|
-
- name: recreate .profile from a clean template
|
11
|
-
template: src=profile dest=/home/{{server_user}}/.profile owner=deploy group=deploy
|
12
|
-
|
13
|
-
- name: add environment variables to .profile
|
14
|
-
lineinfile:
|
15
|
-
dest=/home/{{server_user}}/.profile
|
16
|
-
line='{{item}}'
|
17
|
-
owner={{server_user}}
|
18
|
-
insertafter=EOF
|
19
|
-
create=true
|
20
|
-
with_items:
|
21
|
-
- export APP_NAME={{app_name}}
|
22
|
-
- export APP_ROOT={{app_root}}
|
23
|
-
- export APP_DOMAIN="{{server_domain}}"
|
24
|
-
- export APP_REPO="{{app_repo}}"
|
25
|
-
- export APP_REPO_BRANCH={{app_repo_branch}}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# ~/.profile: executed by the command interpreter for login shells.
|
2
|
-
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
|
3
|
-
# exists.
|
4
|
-
# see /usr/share/doc/bash/examples/startup-files for examples.
|
5
|
-
# the files are located in the bash-doc package.
|
6
|
-
|
7
|
-
# the default umask is set in /etc/profile; for setting the umask
|
8
|
-
# for ssh logins, install and configure the libpam-umask package.
|
9
|
-
#umask 022
|
10
|
-
|
11
|
-
# if running bash
|
12
|
-
if [ -n "$BASH_VERSION" ]; then
|
13
|
-
# include .bashrc if it exists
|
14
|
-
if [ -f "$HOME/.bashrc" ]; then
|
15
|
-
. "$HOME/.bashrc"
|
16
|
-
fi
|
17
|
-
fi
|
18
|
-
|
19
|
-
# set PATH so it includes user's private bin if it exists
|
20
|
-
if [ -d "$HOME/bin" ] ; then
|
21
|
-
PATH="$HOME/bin:$PATH"
|
22
|
-
fi
|
@@ -1 +0,0 @@
|
|
1
|
-
ansible-playbook playbooks/production.yml -i production
|