capistrano-buildpack 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,48 +3,80 @@ require 'digest/sha1'
3
3
  if Capistrano::Configuration.instance
4
4
  Capistrano::Configuration.instance.load do
5
5
 
6
- set :deploy_to, "/apps/#{application}"
6
+ def read_env(name)
7
+ env = {}
8
+ filename = ".env.#{name}"
9
+ return env unless File.exists?(filename)
7
10
 
8
- after "deploy:setup" do
9
- sudo "chown -R #{user} #{deploy_to}"
10
- sudo "gem install foreman-export-nginx --update"
11
+ File.open(".env.#{name}") do |f|
12
+ f.each do |line|
13
+ key, val = line.split('=', 2)
14
+ env[key] = val
15
+ end
16
+ end
17
+
18
+ set :deploy_env, env
11
19
  end
12
20
 
13
- before "deploy" do
14
- default_run_options[:pty] = true
15
- default_run_options[:shell] = '/bin/bash'
21
+ namespace :buildpack do
22
+ task :setup do
23
+ set :deploy_to, "/apps/#{application}"
16
24
 
17
- set :foreman_export_path, "/etc/init"
18
- set :foreman_export_type, "upstart"
19
- set :nginx_export_path, "/etc/nginx/conf.d"
25
+ default_run_options[:pty] = true
26
+ default_run_options[:shell] = '/bin/bash'
20
27
 
21
- set :buildpack_hash, Digest::SHA1.hexdigest(buildpack_url)
22
- set :buildpack_path, "#{shared_path}/buildpack-#{buildpack_hash}"
28
+ set :foreman_export_path, "/etc/init"
29
+ set :foreman_export_type, "upstart"
30
+ set :nginx_export_path, "/etc/nginx/conf.d"
23
31
 
24
- run("[[ ! -e #{buildpack_path} ]] && git clone #{buildpack_url} #{buildpack_path}; exit 0")
25
- run("cd #{buildpack_path} && git fetch origin && git reset --hard origin/master")
26
- run("mkdir -p #{shared_path}/build_cache")
27
- end
32
+ set :buildpack_hash, Digest::SHA1.hexdigest(buildpack_url)
33
+ set :buildpack_path, "#{shared_path}/buildpack-#{buildpack_hash}"
28
34
 
29
- before "deploy:finalize_update" do
30
- run("cd #{buildpack_path} && RACK_ENV=production bin/compile #{release_path} #{shared_path}/build_cache")
35
+ sudo "mkdir -p #{deploy_to}"
36
+ sudo "chown -R #{user} #{deploy_to}"
37
+
38
+ run("[[ ! -e #{buildpack_path} ]] && git clone #{buildpack_url} #{buildpack_path}; exit 0")
39
+ run("cd #{buildpack_path} && git fetch origin && git reset --hard origin/master")
40
+ run("mkdir -p #{shared_path}/build_cache")
31
41
 
32
- env_lines = []
33
- deploy_env.each do |k,v|
34
- env_lines << "#{k}=#{v}"
35
42
  end
36
- env_contents = env_lines.join("\n") + "\n"
37
43
 
38
- put(env_contents, "#{release_path}/.env")
39
- end
44
+ task "install_foreman_export_nginx" do
40
45
 
41
- namespace :deploy do
42
- task :restart do
46
+ sudo "gem install foreman-export-nginx --update"
47
+ end
48
+
49
+ task "compile" do
50
+ run("cd #{buildpack_path} && RACK_ENV=production bin/compile #{release_path} #{shared_path}/build_cache")
51
+
52
+ env_lines = []
53
+ deploy_env.each do |k,v|
54
+ env_lines << "#{k}=#{v}"
55
+ end
56
+ env_contents = env_lines.join("\n") + "\n"
57
+
58
+ put(env_contents, "#{release_path}/.env")
59
+ end
60
+
61
+ task "foreman_export" do
43
62
  sudo "foreman export #{foreman_export_type} #{foreman_export_path} -d #{release_path} -l /var/log/#{application} -a #{application} -u #{user} -p #{base_port} -c #{concurrency}"
44
63
  sudo "env ADDITIONAL_DOMAINS=#{additional_domains.join(',')} BASE_DOMAIN=$CAPISTRANO:HOST$ nginx-foreman export nginx #{nginx_export_path} -d #{release_path} -l /var/log/apps -a #{application} -u #{user} -p #{base_port} -c #{concurrency}"
45
64
  sudo "service #{application} restart || service #{application} start"
46
65
  sudo "service nginx reload || service nginx start"
47
66
  end
67
+
68
+ end
69
+
70
+
71
+ before "deploy:setup", "buildpack:setup"
72
+ after "deploy:setup", "buildpack:install_foreman_export_nginx"
73
+ before "deploy", "buildpack:setup"
74
+ before "deploy:finalize_update", "buildpack:compile"
75
+
76
+ namespace :deploy do
77
+ task :restart do
78
+ buildpack.foreman_export
79
+ end
48
80
  end
49
81
 
50
82
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Buildpack
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-buildpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-01 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Deploy 12-factor applications using Capistrano
15
15
  email: