Add capistrano 3 and documentation

Dominik Sander 8 years ago
parent
commit
a16fb09fa6
9 changed files with 146 additions and 3 deletions
  1. 8 0
      .env.example
  2. 8 2
      Capfile
  3. 4 0
      Gemfile
  4. 21 0
      Gemfile.lock
  5. 54 0
      config/deploy.rb
  6. 1 0
      config/deploy/production.rb
  7. 1 0
      doc/README.md
  8. 2 1
      doc/manual/README.md
  9. 47 0
      doc/manual/capistrano.md

+ 8 - 0
.env.example

@@ -175,3 +175,11 @@ DELAYED_JOB_MAX_RUNTIME=2
175 175
 
176 176
 # Amount of seconds for delayed_job to sleep before checking for new jobs
177 177
 DELAYED_JOB_SLEEP_DELAY=10
178
+
179
+##########################################################
180
+#  Capistrano deployment (read the documentation FIXME)  #
181
+##########################################################
182
+
183
+#CAPISTRANO_DEPLOY_SERVER=
184
+#CAPISTRANO_DEPLOY_USER=
185
+#CAPISTRANO_DEPLOY_REPO_URL=

+ 8 - 2
Capfile

@@ -1,2 +1,8 @@
1
-load 'deploy'
2
-load 'config/deploy'
1
+# Load DSL and set up stages
2
+require 'capistrano/setup'
3
+# Include default deployment tasks
4
+require 'capistrano/deploy'
5
+
6
+require 'capistrano/bundler'
7
+require 'capistrano/rails/assets'
8
+require 'capistrano/rails/migrations'

+ 4 - 0
Gemfile

@@ -103,6 +103,10 @@ group :development do
103 103
   gem 'guard-rspec'
104 104
   gem 'letter_opener_web'
105 105
 
106
+  gem 'capistrano', '~> 3.4.0'
107
+  gem 'capistrano-rails', '~> 1.1'
108
+  gem 'capistrano-bundler', '~> 1.1.4'
109
+
106 110
   group :test do
107 111
     gem 'coveralls', require: false
108 112
     gem 'delorean'

+ 21 - 0
Gemfile.lock

@@ -84,6 +84,16 @@ GEM
84 84
       rails (>= 3.1)
85 85
     buftok (0.2.0)
86 86
     builder (3.2.2)
87
+    capistrano (3.4.0)
88
+      i18n
89
+      rake (>= 10.0.0)
90
+      sshkit (~> 1.3)
91
+    capistrano-bundler (1.1.4)
92
+      capistrano (~> 3.1)
93
+      sshkit (~> 1.2)
94
+    capistrano-rails (1.1.3)
95
+      capistrano (~> 3.1)
96
+      capistrano-bundler (~> 1.1)
87 97
     celluloid (0.16.0)
88 98
       timers (~> 4.0.0)
89 99
     chronic (0.10.2)
@@ -95,6 +105,7 @@ GEM
95 105
       coffee-script-source
96 106
       execjs
97 107
     coffee-script-source (1.9.1)
108
+    colorize (0.7.7)
98 109
     cookiejar (0.3.2)
99 110
     coveralls (0.7.1)
100 111
       multi_json (~> 1.3)
@@ -267,6 +278,9 @@ GEM
267 278
     mysql2 (0.3.16)
268 279
     naught (1.0.0)
269 280
     net-ftp-list (3.2.8)
281
+    net-scp (1.2.1)
282
+      net-ssh (>= 2.6.5)
283
+    net-ssh (2.9.2)
270 284
     netrc (0.10.3)
271 285
     nokogiri (1.6.6.2)
272 286
       mini_portile (~> 0.6.0)
@@ -425,6 +439,10 @@ GEM
425 439
       actionpack (>= 3.0)
426 440
       activesupport (>= 3.0)
427 441
       sprockets (>= 2.8, < 4.0)
442
+    sshkit (1.7.1)
443
+      colorize (>= 0.7.0)
444
+      net-scp (>= 1.1.2)
445
+      net-ssh (>= 2.8.0)
428 446
     string-scrub (0.0.5)
429 447
     systemu (2.6.4)
430 448
     term-ansicolor (1.3.0)
@@ -500,6 +518,9 @@ DEPENDENCIES
500 518
   binding_of_caller
501 519
   bootstrap-kaminari-views (~> 0.0.3)
502 520
   bundler (>= 1.5.0)
521
+  capistrano (~> 3.4.0)
522
+  capistrano-bundler (~> 1.1.4)
523
+  capistrano-rails (~> 1.1)
503 524
   coffee-rails (~> 4.1.0)
504 525
   coveralls
505 526
   daemons (~> 1.1.9)

+ 54 - 0
config/deploy.rb

@@ -0,0 +1,54 @@
1
+require 'dotenv'
2
+Dotenv.load
3
+
4
+# config valid only for current version of Capistrano
5
+lock '3.4.0'
6
+
7
+set :application, 'huginn'
8
+set :repo_url, ENV['CAPISTRANO_DEPLOY_REPO_URL'] || 'https://github.com/cantino/huginn.git'
9
+
10
+# Default branch is :master
11
+set :branch, ENV['BRANCH'] || 'master'
12
+
13
+set :deploy_to, '/home/huginn'
14
+
15
+# Set to :debug for verbose ouput
16
+set :log_level, :info
17
+
18
+# Default value for :linked_files is []
19
+set :linked_files, fetch(:linked_files, []).push('.env', 'Procfile', 'config/unicorn.rb')
20
+
21
+# Default value for linked_dirs is []
22
+set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle')
23
+
24
+# Default value for keep_releases is 5
25
+# set :keep_releases, 5
26
+
27
+set :bundle_jobs, 4
28
+
29
+set :conditionally_migrate, true # Defaults to false. If true, it's skip migration if files in db/migrate not modified
30
+
31
+task :deploy => [:production]
32
+
33
+namespace :deploy do
34
+  after 'check:make_linked_dirs', :migrate_to_cap do
35
+    on roles(:all) do
36
+      # Try to migrate from the manual installation to capistrano directory structure
37
+      next if test('[ -L ~/huginn ]')
38
+      fetch(:linked_files).each do |f|
39
+        if !test("[ -f ~/shared/#{f} ] ") && test("[ -f ~/huginn/#{f} ]")
40
+          execute("cp ~/huginn/#{f} ~/shared/#{f}")
41
+        end
42
+      end
43
+      execute('mv ~/huginn ~/huginn.manual')
44
+      execute('ln -s ~/current ~/huginn')
45
+    end
46
+  end
47
+  after :publishing, :restart do
48
+    on roles(:all) do
49
+      within release_path do
50
+        execute :rake, 'production:restart'
51
+      end
52
+    end
53
+  end
54
+end

+ 1 - 0
config/deploy/production.rb

@@ -0,0 +1 @@
1
+server ENV['CAPISTRANO_DEPLOY_SERVER'], user: ENV['CAPISTRANO_DEPLOY_USER'] || 'huginn', roles: %w{app db web}

+ 1 - 0
doc/README.md

@@ -12,6 +12,7 @@ Manual installation which will guide through the steps to install Huginn on any
12 12
 
13 13
 - [Install](manual/README.md) Requirements, directory structures and installation from source.
14 14
 - [Update](manual/update.md) Update your installation.
15
+- Deploy updates via [Capistrano](manual/capistrano.md).
15 16
 
16 17
 ### Heroku
17 18
 

+ 2 - 1
doc/manual/README.md

@@ -2,4 +2,5 @@
2 2
 
3 3
 - [Requirements](requirements.md) Software and hardware requirements to run the Huginn installation
4 4
 - [Install](installation.md) Installation guide for Ubundu/Debian
5
-- [Update](update.md) Update an existing Huginn installation
5
+- [Update](update.md) Update an existing Huginn installation
6
+- Deploy updates via [Capistrano](capistrano.md)

+ 47 - 0
doc/manual/capistrano.md

@@ -0,0 +1,47 @@
1
+# Deploy updates via Capistrano
2
+
3
+After you followed the [manual installation guide](installation.md) it is simple to push updates to your huginn instance using capistrano.
4
+
5
+### 1. Ensure you have SSH access to your server via the huginn user
6
+
7
+Either set a password for the huginn user or add your public SSH key:
8
+
9
+    # Set password
10
+    sudo passwd huginn
11
+
12
+    # Or add a SSH key
13
+    sudo -u huginn -H mkdir -p /home/huginn/.ssh
14
+    sudo -u huginn -H editor /home/huginn/.ssh/authorized_keys
15
+    sudo -u huginn -H chmod -R 700 /home/huginn/.ssh
16
+
17
+### 2. Configure Capistrano on your local machine
18
+
19
+Add Capistrano configuration to you local `.env`:
20
+
21
+    CAPISTRANO_DEPLOY_SERVER=<IP or FQDN of your server>
22
+    CAPISTRANO_DEPLOY_USER=huginn
23
+    CAPISTRANO_DEPLOY_REPO_URL=https://github.com/cantino/huginn.git
24
+
25
+
26
+### 3. Run Capistrano
27
+
28
+You can now run Capistrano and update your server:
29
+
30
+    cap production deploy
31
+
32
+If you want to deploy a different branch, pass it as environment variable:
33
+
34
+    cap production deploy BRANCH=awesome-feature
35
+
36
+### Changes to remote .env and Procfile
37
+
38
+If you want to change the `.env`, `Procfile` or `config/unicorn.rb` of your installation you still need to do it on your server, do not forget to export the init scripts after your are done:
39
+
40
+    cd /home/huginn/huginn
41
+    # Whichever you want to change
42
+    sudo -u huginn -H editor Procfile
43
+    sudo -u huginn -H editor .env
44
+    sudo -u huginn -H editor config/unicorn.rb
45
+    # Export init scripts and restart huginn
46
+    sudo rake production:export
47
+