hak 0.5.2 → 0.5.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hak +83 -88
  3. data/lib/hak/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59036d5baab90eccfda9560822c1344bcd5bcd89
4
- data.tar.gz: 18b22fa73884b8713ce8c543a642a0090af4e5d8
3
+ metadata.gz: de167389e00c46748a4b0c2690c5616382ef66a6
4
+ data.tar.gz: a70b22a1e315f1e8ab9d4af493656a3d1ebd703f
5
5
  SHA512:
6
- metadata.gz: 512494f63e62bd716e6228896204663f05a0cef309106a5589d19475016fb0be48f0f353fb78c077f86b75e579af9f98241aeefdd1e06331080853296135d612
7
- data.tar.gz: cc6cd146a93e1154e2d07bd1b0e9461db18c2173dad577fbe871d352757cf04a1e04f5061d758599b0ebfa1e61000b11064914cd3633f5a6554287cd8da3afb8
6
+ metadata.gz: 6e785bcb1a9601495f81a7af0d37b4fb97444b4c3b8d9aaf62970527f37d34899576c4730cf1bf9162002685f3be30ec112d44259f3fa40a5d092296e8022e89
7
+ data.tar.gz: 85ac0bc43d632b37928260cade340f0c73e8699a5daa20dd766f7940d7fdaebcda07fc051ca850f11064f6a3129a0edfadbb4ddf7271ab3472241b8aed719ba2
data/bin/hak CHANGED
@@ -7,7 +7,7 @@ require 'colorize'
7
7
  require 'highline'
8
8
 
9
9
  program :name, 'hak'
10
- program :version, '0.5.2'
10
+ program :version, '0.5.3'
11
11
  program :description, 'Hak - A Docker powered website manager for OSX'
12
12
 
13
13
  default_command :help
@@ -22,19 +22,18 @@ command :install do |c|
22
22
  # if ~/.hak not exists, initialize it
23
23
  puts "checking to see if ~/.hak exists".blue
24
24
  if !Dir.exists?(File.expand_path('~/.hak'))
25
- puts "- creating ~/.hak".light_blue
25
+ puts "- creating ~/.hak".blue
26
26
  system "mkdir -p ~/.hak/packages"
27
27
 
28
28
  # install required dependencies
29
- puts "- installing docker, docker-machine, docker-compose, xhyve, wget".light_blue
29
+ puts "- setting up docker, docker-machine, docker-compose, xhyve, wget from brew".blue
30
30
 
31
31
  # re-install docker
32
- system "brew upgrade dinghy docker docker-machine docker-compose wget docker-machine-driver-xhyve"
33
32
  system "brew tap codekitchen/dinghy"
34
- system "brew install dinghy"
35
- system "brew install docker docker-machine docker-compose wget"
36
- system "brew install docker-machine-driver-xhyve"
37
- system "brew link --overwrite docker-machine"
33
+ system "brew install dinghy docker docker-machine docker-compose wget docker-machine-driver-xhyve"
34
+ system "brew upgrade dinghy docker docker-machine docker-compose wget docker-machine-driver-xhyve"
35
+ system "brew unlink dinghy docker docker-machine docker-compose wget docker-machine-driver-xhyve"
36
+ system "brew link dinghy docker docker-machine docker-compose wget docker-machine-driver-xhyve"
38
37
  system "sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve"
39
38
  system "sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve"
40
39
  system "dinghy create --provider xhyve"
@@ -42,31 +41,12 @@ command :install do |c|
42
41
  else
43
42
  puts "- it exists, skipping".blue
44
43
  end
44
+
45
+ # check if docker is running
46
+ check_docker
45
47
 
46
- # check if Docker env variables are set and from which SHELL
47
- puts "checking your shell:".blue
48
- shell = `echo $SHELL`.strip
49
- puts "- #{shell} detected".blue
50
-
51
- puts "checking if docker environmental variables are set:".blue
52
- if shell == '/bin/zsh'
53
- docker_env_exist = `fgrep "export DOCKER_MACHINE_NAME=dinghy" ~/.zshrc |wc -l`.to_i
54
- if docker_env_exist == 0
55
- puts '- not set, type:'.yellow
56
- puts "echo 'eval $(dinghy env)' >> ~/.zshrc"
57
- end
58
- end
59
-
60
- if shell == '/bin/bash'
61
- docker_env_exist = `fgrep "export DOCKER_MACHINE_NAME=dinghy" ~/.bash_profile |wc -l`.to_i
62
- if docker_env_exist == 0
63
- puts '- not set, type:'.yellow
64
- puts "echo 'eval $(dinghy env)' >> ~/.bash_profile"
65
- end
66
- end
67
-
68
- puts "to power on hak, type:".yellow
69
- puts " hak on"
48
+ # check if env is set
49
+ check_env
70
50
 
71
51
  end
72
52
  end
@@ -90,8 +70,13 @@ command :on do |c|
90
70
  c.description = 'powers on the hak server'
91
71
  c.example 'description', 'hak on'
92
72
  c.action do |args, options|
93
- # start up
94
- system "dinghy up"
73
+ if check_env
74
+
75
+ if check_proxy
76
+ system "dinghy start"
77
+ end
78
+
79
+ end
95
80
  end
96
81
  end
97
82
 
@@ -101,48 +86,22 @@ command :off do |c|
101
86
  c.description = 'shuts off the hak server'
102
87
  c.example 'description', 'hak off'
103
88
  c.action do |args, options|
104
- system "dinghy halt"
89
+ system "dinghy stop"
105
90
  end
106
91
  end
107
92
 
108
- command :pull do |c|
109
- c.syntax = 'hak pull jaequery/honeybadger'
110
- c.summary = 'downloads framework'
93
+ command :clone do |c|
94
+ c.syntax = 'hak clone jaequery/react-starter'
95
+ c.summary = 'clones github repo'
111
96
  c.description = ''
112
- c.example 'description', 'hak pull jaequery/honeybadger'
97
+ c.example 'description', 'hak clone jaequery/react-starter'
113
98
  c.action do |args, options|
114
99
 
115
- if !Dir.exists?(File.expand_path("~/.hak"))
116
- system "mkdir ~/.hak"
117
- end
118
-
119
100
  if args.empty?
120
- repo = "jaequery/honeybadger"
121
- package_author = "jaequery"
122
- package = "honeybadger"
123
- puts "Pulling #{repo}"
124
- else
125
- repo = args[0]
126
- package_author = repo.split("/")[0]
127
- package = repo.split("/")[1]
128
- end
129
-
130
- system "cd ~/.hak && rm -rf #{repo} && mkdir -p #{repo} && cd #{repo} && wget https://github.com/#{repo}/archive/master.zip && unzip master.zip && rm -f master.zip && mv #{package}-master/* . && rm -r #{package}-master"
131
- end
132
- end
133
-
134
- command :get do |c|
135
- c.syntax = 'hak get jaequery/react-starter'
136
- c.summary = 'creates site'
137
- c.description = ''
138
- c.example 'description', 'hak get jaequery/react-starter'
139
- c.action do |args, options|
140
-
141
- if args.empty?
142
- puts "for more hak-ready packages, check out https://hak.sh/".yellow
143
- puts "type one of the following to get started: ".yellow
144
- puts "hak get jaequery/react-starter"
145
- puts "hak get jaequery/honeybadger"
101
+ puts "for more hak ready packages, check out https://hak.sh/"
102
+ puts "type one of the following to get started: "
103
+ puts "hak clone jaequery/react-starter".yellow
104
+ puts "hak clone jaequery/honeybadger".yellow
146
105
  puts " "
147
106
 
148
107
  else
@@ -159,10 +118,6 @@ command :get do |c|
159
118
  # downloads package from github
160
119
  system "mkdir -p #{folder} && cd #{folder} && wget https://github.com/#{repo}/archive/master.zip && unzip master.zip && rm -f master.zip && mv #{package}-master/* #{package}-master/.* . && rm -r #{package}-master"
161
120
 
162
- # copies the package from local ~/.hak/[repo] to local folder
163
- #puts "copying ~/.hak/#{repo} to ./#{folder}"
164
- #system "cp -Rfp ~/.hak/#{repo} #{folder}"
165
-
166
121
  # rename virtual host to app name
167
122
  file_path = "#{folder}/docker-compose.yml"
168
123
  file = File.open(file_path, "r+")
@@ -171,9 +126,9 @@ command :get do |c|
171
126
  new_content = content.gsub(/VIRTUAL_HOST=(.*?)\n/, "VIRTUAL_HOST=#{host}\n")
172
127
  File.write(file_path, new_content)
173
128
 
174
- puts "now type:".yellow
175
- puts "cd #{folder}"
176
- puts "hak start"
129
+ puts "now type:"
130
+ puts "cd #{folder}".yellow
131
+ puts "hak start".yellow
177
132
  puts "site should be viewable at http://#{host}/".green
178
133
 
179
134
  end
@@ -291,8 +246,7 @@ command :ps do |c|
291
246
  if dinghy_running == true
292
247
  puts sites.uniq
293
248
  else
294
- puts "hak is off, turn it on first by typing:"
295
- puts "hak on"
249
+ check_docker
296
250
  end
297
251
 
298
252
  end
@@ -320,7 +274,7 @@ command :deploy do |c|
320
274
  dest_docker_installed = true
321
275
 
322
276
  if args.empty?
323
- puts "ex: hak deploy jae@someserver.com".yellow
277
+ puts "ex: hak deploy jae@someserver.com"
324
278
  else
325
279
 
326
280
  # get app name, make sure hak deploy is run from root of your app
@@ -332,8 +286,8 @@ command :deploy do |c|
332
286
  res = `ls -l |grep docker-compose-production.yml`
333
287
  if res == ""
334
288
  puts "docker-compose-production file not exists".red
335
- puts "copying docker-compose.yml to docker-compose-production.yml".green
336
- domain = ask "what domain do you want to use? ex) myawesomesite.com".light_blue
289
+ puts "copying docker-compose.yml to docker-compose-production.yml".blue
290
+ domain = ask "what domain do you want to use? ex) myawesomesite.com".green
337
291
  puts "#{domain} set in docker-compose-production.yml"
338
292
  system "cp docker-compose.yml docker-compose-production.yml"
339
293
 
@@ -380,13 +334,13 @@ command :deploy do |c|
380
334
  # deploy to dest
381
335
  #res = `rsync -avzr ../#{app} #{dest}:~/sites/`
382
336
  #res = `ssh #{dest} \"cd ~/sites/#{app} && docker-compose stop && docker-compose up && docker-compose logs -f\"`
383
- puts "rsyncing from ../#{app} to #{dest}:~/sites/ ... ".yellow
337
+ puts "rsyncing from ../#{app} to #{dest}:~/sites/ ... ".blue
384
338
  res = `rsync -avzr ../#{app} #{dest}:~/sites/`
385
- puts "rsync done".green
339
+ puts "rsync done".blue
386
340
 
387
- puts "running docker-compose -f docker-compose-production.yml up".yellow
341
+ puts "running docker-compose -f docker-compose-production.yml up".blue
388
342
  res = `ssh #{dest} "cd ~/sites/#{app} && docker-compose stop && docker-compose -f docker-compose-production.yml up && docker-compose logs"`
389
- puts "all up and running!".green
343
+ puts "all up and running!".blue
390
344
 
391
345
  end
392
346
 
@@ -411,13 +365,54 @@ def check_docker
411
365
  res = `dinghy status`
412
366
  if res.include? "VM: stopped"
413
367
  running = false
414
- puts "docker not running or stopped".yellow
415
- puts "type this to power it on:".yellow
416
- puts "hak on"
368
+ puts "docker not running or stopped"
369
+ puts "type this to power it on:"
370
+ puts "hak on".yellow
417
371
  abort
418
372
  else
419
373
  running = true
420
374
  end
421
375
 
422
376
  return running
377
+ end
378
+
379
+ def check_proxy
380
+ res = `dinghy status`
381
+ if res.include? "PROXY: stopped"
382
+ # restarting seems to sometimes solve this issue
383
+ system "dinghy restart"
384
+ return false
385
+ end
386
+ return true
387
+ end
388
+
389
+ def check_env
390
+ docker_machine_name = `echo $DOCKER_MACHINE_NAME`.strip
391
+ if docker_machine_name == "" || docker_machine_name != "dinghy"
392
+ puts "To connect the Docker client to the Docker daemon, please set these env variables, type:"
393
+ puts "$(dinghy env)".yellow
394
+ puts "To permanently add this to your shell type: ~/.bashrc"
395
+ output_env
396
+ return false
397
+ end
398
+ return true
399
+ end
400
+
401
+ def output_env
402
+
403
+ shell = `echo $SHELL`.strip
404
+
405
+ if shell == '/bin/zsh'
406
+ docker_env_exist = `fgrep "export DOCKER_MACHINE_NAME=dinghy" ~/.zshrc |wc -l`.to_i
407
+ if docker_env_exist == 0
408
+ puts "echo '$(dinghy env)' >> ~/.zshrc".yellow
409
+ end
410
+ end
411
+
412
+ if shell == '/bin/bash'
413
+ docker_env_exist = `fgrep "export DOCKER_MACHINE_NAME=dinghy" ~/.bash_profile |wc -l`.to_i
414
+ if docker_env_exist == 0
415
+ puts "echo '$(dinghy env)' >> ~/.bash_profile".yellow
416
+ end
417
+ end
423
418
  end
data/lib/hak/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hak
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jaequery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander