shipment-deploy 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86469817a1abdb8afef74ba478c6fbcc4cd09e6d
4
- data.tar.gz: c1d42b3aa527d742484ca4a0584ce949fdf67a03
3
+ metadata.gz: 7dc543b41e53f64aa3e3a2f8258075a61b510475
4
+ data.tar.gz: eb0240009362593422324bdf3e064b978db117a1
5
5
  SHA512:
6
- metadata.gz: 26e85ca97548fb373f653d9e4316cd48a89661b7046637410b6ae3f452892b28d7fb35e0db99604e240f9db6d12c0766ae27241f5a4ec7ce553e18d34186b4cf
7
- data.tar.gz: f326df3df0e58440109d16598e947469a2d92e2ebc16fbe3ddc9d0668c0293bd3db5dc2c25663e8fbf686e369753d98fba5b55effa548c6a73bbf7b60781e32c
6
+ metadata.gz: 0219c5c43851a0ed2a6e92d02ebb57237fb7052c4cb670f3081712cb243f36e018b83ee4db49e709c2af6c3a470b9f65a895909206e5ff93dfac5a0bb728c8e0
7
+ data.tar.gz: 08cc1e8af18e4bda0f0179ecfe826158d407d201e55ae8be94a8b1571ec33e7ba50dcd1ed77be6fdf2105811493379f2f6fbcac5367a01c10745cdbe510d2c88
data/README.md CHANGED
@@ -4,7 +4,7 @@ Easy deployment using Docker
4
4
 
5
5
  ## Installation
6
6
 
7
- $ gem install shipment
7
+ $ gem install shipment-deploy
8
8
 
9
9
  ## Usage
10
10
 
@@ -41,6 +41,16 @@ stdout on the server.
41
41
 
42
42
  ## Todo
43
43
 
44
+ ### For Logging Feature
45
+
46
+ 1. Check to see if project Gemfile has `rails_12factor`, remove it, and
47
+ rebundle.
48
+ 2. Add the following line inside `config/environments/production.rb`: `config.logger = Logger.new('/var/lib/docker/volumes/log/production.log')`
49
+ 3. Add `logs` command that runs `tail -f log/production.log` on the
50
+ server.
51
+
52
+ ### Other Stuff
53
+
44
54
  1. Only add `.shipmet` to `.gitignore` once, duh!
45
55
  2. Handle SSH authorization issues when re-setting up. DigitalOcean
46
56
  allows adding multiple keys with the same name. Need to delete
@@ -56,17 +66,16 @@ command is run.)
56
66
  setups/deploys.
57
67
  7. Look into creating a base image that already includes ruby and
58
68
  postgres containers. (Requires support from DigitalOcean.)
59
- 8. Look into using `docker attach` to allow viewing logs.
60
- 9. Better deal with committing and pushing on `ship this`. Right now,
69
+ 8. Better deal with committing and pushing on `ship this`. Right now,
61
70
  rejected pushes would break everything.
62
- 10. Create simple way to symlink credentials from an `application.yml` or
71
+ 9. Create simple way to symlink credentials from an `application.yml` or
63
72
  `.env` file.
64
- 11. Fix messy output during setup and deploy. Also, deal with duplicate
73
+ 10. Fix messy output during setup and deploy. Also, deal with duplicate
65
74
  'Done.'s when a command is re-run.
66
- 12. Speed everything up.
67
- 13. Clean up the classes. Most things are doing *way* too much.
68
- 14. Write specs!
69
- 15. Add cleanup option to remove all system config.
75
+ 11. Speed everything up.
76
+ 12. Clean up the classes. Most things are doing *way* too much.
77
+ 13. Write specs!
78
+ 14. Add cleanup option to remove all system config.
70
79
 
71
80
  ## Contributing
72
81
 
@@ -3,6 +3,7 @@ require 'shipment/mooring'
3
3
  require 'shipment/credentials_checker'
4
4
  require 'shipment/rigging'
5
5
  require 'shipment/slip'
6
+ require 'shipment/manifest'
6
7
 
7
8
  module Shipment
8
9
 
@@ -50,6 +51,22 @@ module Shipment
50
51
 
51
52
  Shipment::Slip.cast_off
52
53
  end
54
+
55
+ desc "logs", "View logs"
56
+ long_desc <<-LONGDESC
57
+ `ship logs` will tail your application's production logs.
58
+ LONGDESC
59
+ def logs
60
+ if !Shipment::CredentialsChecker.verify
61
+ Shipment::Mooring.lash
62
+ end
63
+
64
+ if !File.exist?('.shipment')
65
+ Shipment::Rigging.rig
66
+ end
67
+
68
+ Shipment::Manifest.review
69
+ end
53
70
  end
54
71
 
55
72
  end
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'shipment/server/ssh_client'
3
+ require 'shipment/project/repo'
4
+
5
+ module Shipment
6
+ class Manifest
7
+ def self.review
8
+ Shipment::Server::SSHClient.tail_logs(
9
+ repo: Shipment::Project::Repo.new,
10
+ ip_address: YAML.load(File.read('.shipment'))[:ip_address]
11
+ )
12
+ end
13
+ end
14
+ end
@@ -29,6 +29,8 @@ module Shipment
29
29
  update_db_info
30
30
  puts "-----> ".green + "Adding .shipment file to .gitignore..."
31
31
  add_shipment_to_gitignore
32
+ puts "-----> ".green + "Ensuring correct logging settings..."
33
+ fix_logging_settings
32
34
  puts "-----> ".green + "Committing and pushing changes..."
33
35
  commit_and_push
34
36
  end
@@ -40,6 +42,39 @@ module Shipment
40
42
  git.push(git.remote("origin"))
41
43
  end
42
44
 
45
+ def fix_logging_settings
46
+ remove_12_factor_gem
47
+ update_production_rb
48
+ end
49
+
50
+ def remove_12_factor_gem
51
+ if !!File.read('Gemfile').match(/rails_12factor/)
52
+ File.open('Gemfile.tmp', 'w') do |tmp|
53
+ File.readlines('Gemfile').each do |line|
54
+ tmp.write(line) unless line.match(/rails_12factor/)
55
+ end
56
+ end
57
+
58
+ FileUtils.mv 'Gemfile.tmp', 'Gemfile'
59
+
60
+ system("bundle install > /dev/null")
61
+ end
62
+ end
63
+
64
+ def update_production_rb
65
+ File.open('production.rb.tmp', 'w') do |tmp|
66
+ File.readlines('config/environments/production.rb').each do |line|
67
+ if line == 'end' || line == "end\n"
68
+ tmp.write(" config.logger = Logger.new('/var/lib/docker/volumes/log/production.log')\nend")
69
+ else
70
+ tmp.write(line)
71
+ end
72
+ end
73
+ end
74
+
75
+ FileUtils.mv 'production.rb.tmp', 'config/environments/production.rb'
76
+ end
77
+
43
78
  def add_shipment_to_gitignore
44
79
  File.open(".gitignore", "a") do |f|
45
80
  f.write '.shipment'
@@ -19,6 +19,10 @@ module Shipment
19
19
  new(repo, ip_address).deploy
20
20
  end
21
21
 
22
+ def self.tail_logs(repo:, ip_address:)
23
+ new(repo, ip_address).tail_logs
24
+ end
25
+
22
26
  def initialize(repo, ip_address)
23
27
  @gh_username, @gh_token = Netrc.read["shipment.gh"]
24
28
  @ip_address = ip_address
@@ -40,7 +44,15 @@ module Shipment
40
44
  kill_and_commit_old_server
41
45
  start_new_server
42
46
  puts "-----> ".green + "Done.\nYour application is accessable at: #{ip_address}"
47
+ end
43
48
 
49
+ def tail_logs
50
+ puts "-----> ".green + "Accessing application logs..."
51
+ begin
52
+ run_remote_command("tail -f log/production.log")
53
+ rescue Interrupt
54
+ puts "\nDone."
55
+ end
44
56
  end
45
57
 
46
58
  def kill_and_commit_old_server
@@ -51,7 +63,7 @@ module Shipment
51
63
  def start_new_server
52
64
  puts "-----> ".green + "Restarting server..."
53
65
  redis_command, sidekiq_command = parse_redis_and_sidekiq
54
- run_remote_command("docker run -d -p 80:3000 --name application -e SECRET_KEY_BASE=#{secret_key_base} #{repo_user}/#{repo_name} /bin/bash -c 'kill -9 $(pgrep -f sidekiq) > /dev/null 2>&1 && kill -9 $(pgrep -f redis-server) > /dev/null 2>&1 && kill -9 $(pgrep -f rails) > /dev/null 2>&1 && source /etc/profile.d/rvm.sh && rm -rf #{repo_name} && git clone #{repo_url} #{repo_name} && cd #{repo_name} && bundle install && RAILS_ENV=production bundle exec rake db:migrate#{redis_command}#{sidekiq_command} && rails server -p 3000 -e production'")
66
+ run_remote_command("docker run -d -p 80:3000 --name application -e SECRET_KEY_BASE=#{secret_key_base} -v /root/log:/var/lib/docker/volumes/log #{repo_user}/#{repo_name} /bin/bash -c 'kill -9 $(pgrep -f sidekiq) > /dev/null 2>&1 && kill -9 $(pgrep -f redis-server) > /dev/null 2>&1 && kill -9 $(pgrep -f rails) > /dev/null 2>&1 && source /etc/profile.d/rvm.sh && rm -rf #{repo_name} && git clone #{repo_url} #{repo_name} && cd #{repo_name} && bundle install && RAILS_ENV=production bundle exec rake db:migrate#{redis_command}#{sidekiq_command} && rails server -p 3000 -e production'")
55
67
  end
56
68
 
57
69
  def parse_redis_and_sidekiq
@@ -122,6 +134,7 @@ module Shipment
122
134
 
123
135
  puts "-----> ".green + "Done.\nReady to deploy."
124
136
  puts "Your server's IP Address is: #{ip_address}"
137
+ puts "Deploy with: ship out"
125
138
  end
126
139
 
127
140
  def pull_ruby_image
@@ -146,7 +159,7 @@ module Shipment
146
159
 
147
160
  def migrate
148
161
  puts "-----> ".green + "Migrating database..."
149
- run_remote_command("docker run --name migrate #{repo_user}/#{repo_name} /bin/bash -c 'source /etc/profile.d/rvm.sh && cd #{repo_name} && RAILS_ENV=production bundle exec rake db:migrate' && docker rm migrate")
162
+ run_remote_command("docker run --name migrate #{repo_user}/#{repo_name} /bin/bash -c 'source /etc/profile.d/rvm.sh && mkdir -p /var/lib/docker/volumes/log && touch /var/lib/docker/volumes/log/production.log && cd #{repo_name} && RAILS_ENV=production bundle exec rake db:migrate && cd ..' && docker commit migrate #{repo_user}/#{repo_name} && docker rm migrate")
150
163
  end
151
164
 
152
165
  #def save_docker_image
@@ -1,4 +1,4 @@
1
1
  module Shipment
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipment-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Hasson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,6 +197,7 @@ files:
197
197
  - lib/shipment.rb
198
198
  - lib/shipment/cli.rb
199
199
  - lib/shipment/credentials_checker.rb
200
+ - lib/shipment/manifest.rb
200
201
  - lib/shipment/mooring.rb
201
202
  - lib/shipment/project/customizer.rb
202
203
  - lib/shipment/project/repo.rb