webflow_cap 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67006ecdc85663bc7c411b169bf8671e5093dcba
4
- data.tar.gz: 949091f4bfc3435466bc1921e611f7d944a9375b
3
+ metadata.gz: 16b1cbbc91b99f3c04536390582e3a5397d8d338
4
+ data.tar.gz: 5f6b95473b4a8f121cc2dd96cc8aaed416b7963c
5
5
  SHA512:
6
- metadata.gz: 9f06ec46fc1b5bcfa901fd80d41542173de2a03d57ad3fdd699c727e35ce0aadd984de729640882b75f93dfbf64116316cb1fce09908b87287e2bf82d129528e
7
- data.tar.gz: 90d1dae73cab2a66268522681a9e2dae3811900eee518f33b09e9aec9e5cac78f2e1c764da72c8b3af199361738a68104740e80474edcc64ef30312e5015f0be
6
+ metadata.gz: 65dfcbd41dd73f94bf3ec4bda1be7daecfeb0a3857a5a1e1f70c226ed8accbc3a0f6b686553d6f9cf49bb91463fb3d95a9c96044bb3e226f690ee78eb97abccb
7
+ data.tar.gz: 8986def589f5e7e95f7a004bf51a2ceaa70182a5f9eb3e858527f4fad3e3df1ac73cdcc98de5f928aa625af368d414d798477cfb191bcdcb22c8b4c3a71986e0
@@ -15,108 +15,12 @@ namespace :load do
15
15
  set :deploy_to, -> { "/docs/#{fetch :user}/#{fetch :domain}/#{fetch :application}" }
16
16
  set :server_port, -> { 10000 + ((fetch :user)[3..6] + "0").to_i }
17
17
 
18
+ set :linked_files, %w{}
19
+
18
20
  set :default_env, -> {
19
21
  {'PATH' => "/docs/#{fetch :user}/.gem/ruby/#{fetch :ruby_version}/bin:/opt/ruby/#{fetch :ruby_version}/bin:$PATH"}
20
22
  }
21
-
22
- set :runit_service_dir, -> {"#{fetch :home}/etc/service/rails-#{fetch :server_port}-#{fetch :domain}-#{fetch :application}"}
23
- end
24
- end
25
-
26
- namespace :runit do
27
- task :setup_application_server do
28
- on roles :all do
29
- daemon_name = "rails-#{fetch :server_port}-#{fetch :domain}-#{fetch :application}"
30
- runit_dir = "#{fetch :home}/etc/sv/#{daemon_name}"
31
-
32
- if test("[ -e #{runit_dir} ]")
33
- info("runit ready @ #{runit_dir}")
34
- next
35
- end
36
-
37
- daemon_script = <<-EOF
38
- #!/bin/bash -e
39
- exec 2>&1
40
- export HOME=#{fetch :home}
41
- export PATH=#{fetch(:default_env)['PATH']}
42
- source $HOME/.bashrc
43
- cd #{fetch :deploy_to}/current
44
- exec bundle exec #{fetch :application_server} -p #{fetch :server_port} -e production 2>&1
45
- EOF
46
-
47
- log_script = <<-EOF
48
- #!/bin/bash -e
49
- exec svlogd -tt ./main
50
- EOF
51
-
52
- execute "mkdir -p #{runit_dir}"
53
- execute "mkdir -p #{runit_dir}/log/main"
54
- upload! StringIO.new(daemon_script), "#{runit_dir}/run"
55
- upload! StringIO.new(log_script), "#{runit_dir}/log/run"
56
- execute "chmod +x #{runit_dir}/run"
57
- execute "chmod +x #{runit_dir}/log/run"
58
- execute "ln -nfs #{runit_dir} #{fetch :runit_service_dir}"
59
- end
60
- end
61
-
62
- after 'deploy:started', 'runit:setup_application_server'
63
- end
64
-
65
- namespace :htaccess do
66
- task :create do
67
- on roles :all do
68
- if test("[ -e #{shared_path}/.htaccess ]")
69
- info "[skip] .htaccess already exists"
70
- elsif fetch(:password_protected)
71
- ask(:htaccess_user, fetch(:user))
72
- ask(:htaccess_pass, nil)
73
-
74
- htaccess_content = <<-EOF
75
- AuthName "#{fetch :application}"
76
- AuthType Basic
77
- AuthUserFile #{shared_path}/.htpasswd
78
- Require valid-user
79
- EOF
80
- upload! StringIO.new(htaccess_content), "#{shared_path}/.htaccess"
81
- execute "htpasswd -dbc #{shared_path}/.htpasswd #{fetch :htaccess_user} #{fetch :htaccess_pass}"
82
- end
83
- end
84
23
  end
85
-
86
- task :remove do
87
- on roles :all do
88
- if test("[ -e #{shared_path}/.htaccess ]")
89
- execute "rm -f #{shared_path}/.htaccess"
90
- execute "rm -f #{shared_path}/.htpasswd"
91
- execute "rm -f #{current_path}/.htaccess"
92
- end
93
- end
94
- end
95
-
96
- after 'deploy:updated', 'htaccess:create'
97
- end
98
-
99
- namespace :apache do
100
- task :setup_reverse_proxy do
101
- on roles :all do
102
- path = "#{fetch :home}/#{fetch :domain}/htdocs"
103
-
104
- if test("[ -e #{path} ]")
105
- info "reverse proxy configured @ #{path}/.htaccess"
106
- next
107
- end
108
-
109
- htaccess = <<-EOF
110
- RewriteEngine On
111
- RewriteRule ^(.*)$ http://localhost:#{fetch :server_port}/$1 [P]
112
- EOF
113
- execute "mkdir -p #{path}"
114
- upload! StringIO.new(htaccess), "#{path}/.htaccess"
115
- execute "chmod +r #{path}/.htaccess"
116
- end
117
- end
118
-
119
- after 'deploy:started', 'apache:setup_reverse_proxy'
120
24
  end
121
25
 
122
26
  namespace :deploy do
@@ -141,16 +45,4 @@ namespace :deploy do
141
45
  execute "sv status #{fetch :runit_service_dir}"
142
46
  end
143
47
  end
144
-
145
- task :symlink_shared do
146
- on roles :all do
147
- execute "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
148
-
149
- if fetch(:password_protected)
150
- execute "ln -nfs #{shared_path}/.htaccess #{release_path}/.htaccess"
151
- end
152
- end
153
- end
154
-
155
- before :updated, :symlink_shared
156
48
  end
@@ -0,0 +1,32 @@
1
+ namespace :htaccess do
2
+ task :password_protection do
3
+ on roles :all do
4
+ path = "#{fetch :home}/#{fetch :domain}/htdocs"
5
+
6
+ if test("[ -e #{shared_path}/.htpasswd ]")
7
+ info "[skip] password protection is already active"
8
+ elsif fetch(:password_protected)
9
+ ask(:htaccess_user, fetch(:user))
10
+ ask(:htaccess_pass, nil)
11
+
12
+ execute "echo 'AuthName #{fetch :application}' >> #{path}/.htaccess"
13
+ execute "echo 'AuthType Basic' >> #{path}/.htaccess"
14
+ execute "echo 'AuthUserFile #{shared_path}/.htpasswd' >> #{path}/.htaccess"
15
+ execute "echo 'Require valid-user' >> #{path}/.htaccess"
16
+
17
+ execute "htpasswd -dbc #{shared_path}/.htpasswd #{fetch :htaccess_user} #{fetch :htaccess_pass}"
18
+ end
19
+ end
20
+ end
21
+
22
+ task :change_credentials do
23
+ on roles :all do
24
+ ask(:htaccess_user, fetch(:user))
25
+ ask(:htaccess_pass, nil)
26
+
27
+ execute "htpasswd -dbc #{shared_path}/.htpasswd #{fetch :htaccess_user} #{fetch :htaccess_pass}"
28
+ end
29
+ end
30
+
31
+ after 'deploy:finished', :password_protection
32
+ end
@@ -26,6 +26,8 @@ namespace :mysql do
26
26
 
27
27
  execute "mkdir -p #{shared_path}/config"
28
28
  upload! StringIO.new(config.to_yaml), "#{shared_path}/config/database.yml"
29
+
30
+ set :linked_files, fetch(:linked_files).push("config/database.yml")
29
31
  end
30
32
  end
31
33
 
@@ -0,0 +1,73 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :runit_service_dir, -> {"#{fetch :home}/etc/service/rails-#{fetch :server_port}-#{fetch :domain}-#{fetch :application}"}
4
+ end
5
+ end
6
+
7
+ namespace :rails do
8
+ task :versions do
9
+ on roles :all do
10
+ within '/opt/ruby' do
11
+ execute(:ls)
12
+ end
13
+ end
14
+ end
15
+
16
+ task :setup_reverse_proxy do
17
+ on roles :all do
18
+ path = "#{fetch :home}/#{fetch :domain}/htdocs"
19
+
20
+ if test("[ -e #{path}/.htaccess ]")
21
+ info "reverse proxy configured @ #{path}/.htaccess"
22
+ next
23
+ end
24
+
25
+ htaccess = <<-EOF
26
+ RewriteEngine On
27
+ RewriteRule ^(.*)$ http://localhost:#{fetch :server_port}/$1 [P]
28
+
29
+ EOF
30
+ execute "mkdir -p #{path}"
31
+ upload! StringIO.new(htaccess), "#{path}/.htaccess"
32
+ execute "chmod +r #{path}/.htaccess"
33
+ end
34
+ end
35
+
36
+ task :setup_application_server do
37
+ on roles :all do
38
+ daemon_name = "rails-#{fetch :server_port}-#{fetch :domain}-#{fetch :application}"
39
+ runit_dir = "#{fetch :home}/etc/sv/#{daemon_name}"
40
+
41
+ if test("[ -e #{runit_dir} ]")
42
+ info("runit ready @ #{runit_dir}")
43
+ next
44
+ end
45
+
46
+ daemon_script = <<-EOF
47
+ #!/bin/bash -e
48
+ exec 2>&1
49
+ export HOME=#{fetch :home}
50
+ export PATH=#{fetch(:default_env)['PATH']}
51
+ source $HOME/.bashrc
52
+ cd #{fetch :deploy_to}/current
53
+ exec bundle exec #{fetch :application_server} -p #{fetch :server_port} -e production 2>&1
54
+ EOF
55
+
56
+ log_script = <<-EOF
57
+ #!/bin/bash -e
58
+ exec svlogd -tt ./main
59
+ EOF
60
+
61
+ execute "mkdir -p #{runit_dir}"
62
+ execute "mkdir -p #{runit_dir}/log/main"
63
+ upload! StringIO.new(daemon_script), "#{runit_dir}/run"
64
+ upload! StringIO.new(log_script), "#{runit_dir}/log/run"
65
+ execute "chmod +x #{runit_dir}/run"
66
+ execute "chmod +x #{runit_dir}/log/run"
67
+ execute "ln -nfs #{runit_dir} #{fetch :runit_service_dir}"
68
+ end
69
+ end
70
+
71
+ after 'deploy:published', :setup_application_server
72
+ after :setup_application_server, :setup_reverse_proxy
73
+ end
@@ -0,0 +1,60 @@
1
+ require 'erb'
2
+ require 'pathname'
3
+
4
+ namespace :webflow do
5
+ desc "Install webflow flavoured capistrano files"
6
+ task :install do
7
+ on roles :all do
8
+ set :application, ask("Application name", "APP")
9
+ set :ruby_version, ask("Ruby version", "2.1.5")
10
+ set :repo_url, ask("Repository URL", nil)
11
+ set :user, ask("Username", "f999999")
12
+ set :domain, ask("Domain", "example.com")
13
+ set :server, ask("Server", "server.example.com")
14
+
15
+ @application = fetch(:application)
16
+ @ruby_version = fetch(:ruby_version)
17
+ @repo_url = fetch(:repo_url)
18
+ @user = fetch(:user)
19
+ @domain = fetch(:domain)
20
+ @server = fetch(:server)
21
+
22
+ envs = ENV['STAGES'] || 'staging,production'
23
+
24
+ tasks_dir = Pathname.new('lib/capistrano/tasks')
25
+ config_dir = Pathname.new('config')
26
+ deploy_dir = config_dir.join('deploy')
27
+
28
+ deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
29
+ stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
30
+ capfile = File.expand_path("../../templates/Capfile", __FILE__)
31
+
32
+ execute "mkdir -p #{deploy_dir}"
33
+
34
+ entries = [{template: deploy_rb, file: config_dir.join('deploy.rb')}]
35
+ entries += envs.split(',').map { |stage| {template: stage_rb, file: deploy_dir.join("#{stage}.rb")} }
36
+
37
+ entries.each do |entry|
38
+ if File.exists?(entry[:file])
39
+ warn "[skip] #{entry[:file]} already exists"
40
+ else
41
+ File.open(entry[:file], 'w+') do |f|
42
+ f.write(ERB.new(File.read(entry[:template])).result(binding))
43
+ puts "create #{entry[:file]}"
44
+ end
45
+ end
46
+ end
47
+
48
+ execute "mkdir -p #{tasks_dir}"
49
+
50
+ if File.exists?('Capfile')
51
+ warn "[skip] Capfile already exists"
52
+ else
53
+ FileUtils.cp(capfile, 'Capfile')
54
+ puts 'create Capfile'
55
+ end
56
+ end
57
+
58
+ puts 'Capified'
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ require 'capistrano/setup'
2
+ require 'capistrano/deploy'
3
+ require 'capistrano/bundler'
4
+ require 'capistrano/rails/migrations'
5
+ require 'capistrano/rails/assets'
6
+ require 'capistrano/webflow/base'
7
+ require 'capistrano/webflow/rails'
8
+ # require the mysql library if you use mysql
9
+ require 'capistrano/webflow/mysql'
10
+ # require the htaccess library for use the htaccess password protection
11
+ require 'capistrano/webflow/htaccess'
12
+
13
+ # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
14
+ Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
@@ -0,0 +1,11 @@
1
+ # config valid only for current version of Capistrano
2
+ lock '<%= Capistrano::VERSION %>'
3
+
4
+ # set the application name to what ever you want. It is used for the folder name which contains the application
5
+ set :application, "<%= @application %>"
6
+
7
+ # set the repository url to repo_url
8
+ set :repo_url, "<%= @repo_url %>"
9
+
10
+ # use ruby_version to set a specific ruby version
11
+ # set :ruby_version, "<%= @ruby_version %>"
@@ -0,0 +1,11 @@
1
+ # set user to the username from webflow e.g. f999999
2
+ set :user, "<%= @user %>"
3
+
4
+ # set domain to the domain which should be used e.g. example.com or dev.example.com
5
+ set :domain, "<%= @domain %>"
6
+
7
+ # set password_protected to true in production or staging to protect the page with htaccess
8
+ # set :password_protected, true
9
+
10
+ # set the servername to the servername or ipaddress from webflow e.g. server.example.com or 192.168.0.1
11
+ server "<%= @server %>", user: fetch(:user), roles: %w(:web :app :db), primary: true
@@ -0,0 +1,2 @@
1
+ load File.expand_path("../../tasks/base.rake", __FILE__)
2
+ load File.expand_path("../../tasks/webflow.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/htaccess.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/mysql.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/rails.rake", __FILE__)
File without changes
data/webflow_cap.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "webflow_cap"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "0.0.4"
16
+ gem.version = "0.0.6"
17
17
 
18
18
  # dependencies
19
19
  gem.add_dependency 'capistrano', '~>3.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webflow_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Aman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -36,8 +36,18 @@ files:
36
36
  - README.md
37
37
  - Rakefile
38
38
  - lib/capistrano/tasks/base.rake
39
+ - lib/capistrano/tasks/htaccess.rake
39
40
  - lib/capistrano/tasks/mysql.rake
40
- - lib/capistrano/webflow.rb
41
+ - lib/capistrano/tasks/rails.rake
42
+ - lib/capistrano/tasks/webflow.rake
43
+ - lib/capistrano/templates/Capfile
44
+ - lib/capistrano/templates/deploy.rb.erb
45
+ - lib/capistrano/templates/stage.rb.erb
46
+ - lib/capistrano/webflow/base.rb
47
+ - lib/capistrano/webflow/htaccess.rb
48
+ - lib/capistrano/webflow/mysql.rb
49
+ - lib/capistrano/webflow/rails.rb
50
+ - lib/webflow_cap.rb
41
51
  - webflow_cap.gemspec
42
52
  homepage: https://rubygems.org/gems/webflow_cap
43
53
  licenses:
@@ -1,2 +0,0 @@
1
- load File.expand_path("../tasks/base.rake", __FILE__)
2
- load File.expand_path("../tasks/mysql.rake", __FILE__)