hak 0.5.3 → 0.5.5

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hak +56 -111
  3. data/lib/hak.rb +1 -1
  4. data/lib/hak/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de167389e00c46748a4b0c2690c5616382ef66a6
4
- data.tar.gz: a70b22a1e315f1e8ab9d4af493656a3d1ebd703f
3
+ metadata.gz: bd0f7dee1f2a34c899daeb7ead66035c780bee05
4
+ data.tar.gz: 598cc60eb0e34c4993abf0350be5eb98fa344734
5
5
  SHA512:
6
- metadata.gz: 6e785bcb1a9601495f81a7af0d37b4fb97444b4c3b8d9aaf62970527f37d34899576c4730cf1bf9162002685f3be30ec112d44259f3fa40a5d092296e8022e89
7
- data.tar.gz: 85ac0bc43d632b37928260cade340f0c73e8699a5daa20dd766f7940d7fdaebcda07fc051ca850f11064f6a3129a0edfadbb4ddf7271ab3472241b8aed719ba2
6
+ metadata.gz: 28215cc3612f02a526c44e36e84d5f988c4af89d0ce8bbb4fff57648685290dded09bc0cd02c68d984524a8715b99e9fe92512e68e226a0f70ca84a2f7ffe285
7
+ data.tar.gz: d5ce5958e9f75ec9d8381fdbf188352ddc2c6484552766498246a92cb1fdfa135c90acf38740f9a551f0c244f674c464fdfbc94cc035e8aca9564bac331c16f5
data/bin/hak CHANGED
@@ -7,60 +7,37 @@ require 'colorize'
7
7
  require 'highline'
8
8
 
9
9
  program :name, 'hak'
10
- program :version, '0.5.3'
11
- program :description, 'Hak - A Docker powered website manager for OSX'
10
+ program :version, '0.5.5'
11
+ program :description, 'Hak - A Docker-driven development platform'
12
12
 
13
13
  default_command :help
14
14
 
15
15
  command :install do |c|
16
16
  c.syntax = 'hak install'
17
- c.summary = 'installs the hak environment'
18
- c.description = 'installs docker and sets up the entire docker based environment along with proxy'
17
+ c.summary = 'installs hak'
18
+ c.description = 'installs hak'
19
19
  c.example 'description', 'hak install'
20
20
  c.action do |args, options|
21
21
 
22
- # if ~/.hak not exists, initialize it
23
- puts "checking to see if ~/.hak exists".blue
24
- if !Dir.exists?(File.expand_path('~/.hak'))
25
- puts "- creating ~/.hak".blue
26
- system "mkdir -p ~/.hak/packages"
27
-
28
- # install required dependencies
29
- puts "- setting up docker, docker-machine, docker-compose, xhyve, wget from brew".blue
30
-
31
- # re-install docker
32
- system "brew tap codekitchen/dinghy"
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"
37
- system "sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve"
38
- system "sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve"
39
- system "dinghy create --provider xhyve"
22
+ user = `whoami`.strip
40
23
 
24
+ if user != "root"
25
+ puts "Hak will automatically resolve all domains that ends in .docker to your docker vm for you."
26
+ puts "To do this, hak requires sudo to place an entry in /etc/resolver/docker, please type:"
27
+ puts "sudo hak install".yellow
28
+ abort
41
29
  else
42
- puts "- it exists, skipping".blue
43
- end
44
-
45
- # check if docker is running
46
- check_docker
47
30
 
48
- # check if env is set
49
- check_env
31
+ res = `cat > /etc/resolver/docker <<EOL
32
+ nameserver 127.0.0.1
33
+ port 19322`
50
34
 
51
- end
52
- end
35
+ puts "hak installed".green
36
+ puts "now turn hak on by typing:"
37
+ puts "hak on".yellow
53
38
 
54
- command :uninstall do |c|
55
- c.syntax = 'hak destroy'
56
- c.summary = 'destroys hak server'
57
- c.description = 'shuts off and destroys the hak server'
58
- c.example 'description', 'hak destroy'
59
- c.action do |args, options|
60
- system "dinghy halt"
61
- system "dinghy destroy"
62
- system "rm -rf ~/.hak"
63
- system "rm -rf ~/.dinghy"
39
+ end
40
+
64
41
  end
65
42
  end
66
43
 
@@ -70,13 +47,11 @@ command :on do |c|
70
47
  c.description = 'powers on the hak server'
71
48
  c.example 'description', 'hak on'
72
49
  c.action do |args, options|
73
- if check_env
74
-
75
- if check_proxy
76
- system "dinghy start"
77
- end
78
-
79
- end
50
+ check_dns
51
+ `docker stop hak-proxy > /dev/null 2>&1`
52
+ `docker rm hak-proxy > /dev/null 2>&1`
53
+ `docker run -d -v /var/run/docker.sock:/tmp/docker.sock:ro -p 80:80 -p 443:443 -p 19322:19322/udp -e CONTAINER_NAME=hak-proxy --name hak-proxy codekitchen/dinghy-http-proxy`
54
+ puts "hak-proxy started"
80
55
  end
81
56
  end
82
57
 
@@ -86,7 +61,9 @@ command :off do |c|
86
61
  c.description = 'shuts off the hak server'
87
62
  c.example 'description', 'hak off'
88
63
  c.action do |args, options|
89
- system "dinghy stop"
64
+ `docker stop hak-proxy > /dev/null 2>&1`
65
+ `docker rm hak-proxy > /dev/null 2>&1`
66
+ puts "hak-proxy stopped"
90
67
  end
91
68
  end
92
69
 
@@ -142,7 +119,7 @@ command :start do |c|
142
119
  c.description = 'this starts up the website'
143
120
  c.example 'description', 'hak start'
144
121
  c.action do |args, options|
145
- check_docker
122
+ check_all
146
123
  run "docker-compose up -d && docker-compose logs -f"
147
124
  end
148
125
  end
@@ -153,7 +130,7 @@ command :stop do |c|
153
130
  c.description = 'stops the site'
154
131
  c.example 'description', 'hak stop'
155
132
  c.action do |args, options|
156
- check_docker
133
+ check_all
157
134
  run "docker-compose stop"
158
135
  end
159
136
  end
@@ -164,7 +141,7 @@ command :restart do |c|
164
141
  c.description = 'restarts the site'
165
142
  c.example 'description', 'hak restart'
166
143
  c.action do |args, options|
167
- check_docker
144
+ check_all
168
145
  run "docker-compose stop"
169
146
  run "docker-compose up -d && docker-compose logs -f"
170
147
  end
@@ -176,7 +153,7 @@ command :rm do |c|
176
153
  c.description = 'deletes docker containers for the project'
177
154
  c.example 'description', 'hak rm'
178
155
  c.action do |args, options|
179
- check_docker
156
+ check_all
180
157
  run "docker-compose stop && docker-compose rm -f --all"
181
158
  end
182
159
  end
@@ -199,7 +176,7 @@ command :ssh do |c|
199
176
  c.description = ''
200
177
  c.example 'description', 'hak ssh [app]'
201
178
  c.action do |args, options|
202
- check_docker
179
+ check_all
203
180
 
204
181
  file_name = 'docker-compose.yml'
205
182
  config_options = YAML.load_file(file_name)
@@ -228,14 +205,14 @@ command :ps do |c|
228
205
  c.description = ''
229
206
  c.example 'description', 'hak ps'
230
207
  c.action do |args, options|
231
- check_docker
208
+ check_all
232
209
 
233
210
  container_names = run('docker ps --format "{{.Names}}"', true)
234
211
  lines = container_names.lines
235
212
  dinghy_running = false
236
213
  sites = lines.map do |line|
237
214
  name = line.split('_')[0]
238
- if name == 'dinghy'
215
+ if name == 'hak-proxy'
239
216
  dinghy_running = true
240
217
  "proxy"
241
218
  else
@@ -243,23 +220,8 @@ command :ps do |c|
243
220
  end
244
221
  end
245
222
 
246
- if dinghy_running == true
247
- puts sites.uniq
248
- else
249
- check_docker
250
- end
251
-
252
- end
253
- end
223
+ puts sites.uniq
254
224
 
255
- command :upgrade do |c|
256
- c.syntax = 'hak upgrade'
257
- c.summary = 'upgrades hak and dinghy'
258
- c.description = ''
259
- c.example 'description', 'hak upgrade'
260
- c.action do |args, options|
261
- system "gem update hak"
262
- run "dinghy upgrade"
263
225
  end
264
226
  end
265
227
 
@@ -360,59 +322,42 @@ def run(command, hide=false)
360
322
  return res
361
323
  end
362
324
 
325
+ def check_all
326
+ check_docker
327
+ check_dns
328
+ check_proxy
329
+ end
330
+
363
331
  def check_docker
364
332
 
365
- res = `dinghy status`
366
- if res.include? "VM: stopped"
333
+ res = `docker ps`
334
+ if res.include? "Cannot connect to the Docker daemon"
367
335
  running = false
368
336
  puts "docker not running or stopped"
369
- puts "type this to power it on:"
370
- puts "hak on".yellow
337
+ puts "Please turn on Docker first. If you don't have Docker installed, please install it from Docker's website."
371
338
  abort
372
- else
373
- running = true
374
339
  end
375
340
 
376
- return running
341
+ return true
342
+
377
343
  end
378
344
 
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
345
+ def check_dns
346
+ if !File.exist?('/etc/resolver/docker')
347
+ puts "hak not installed properly, please type:"
348
+ puts "sudo hak install".yellow
349
+ abort
385
350
  end
386
351
  return true
387
352
  end
388
353
 
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
354
+ def check_proxy
355
+ res = `docker ps`
356
+ if !res.include? "hak-proxy"
357
+ puts "proxy not running, please type:"
358
+ puts "hak on".yellow
359
+ abort
397
360
  end
398
361
  return true
399
362
  end
400
363
 
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
418
- end
data/lib/hak.rb CHANGED
@@ -3,5 +3,5 @@ require 'rubygems'
3
3
  require 'commander/import'
4
4
 
5
5
  module Hak
6
-
6
+
7
7
  end
data/lib/hak/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hak
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.5"
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.3
4
+ version: 0.5.5
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-21 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander