Skip to content

Commit d8153fa

Browse files
committed
Initial commit
0 parents  commit d8153fa

27 files changed

+1194
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.gem

.rspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--format documentation
2+
--color
3+
--require spec_helper
4+
--require byebug

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: ruby
2+
rvm:
3+
- "1.8.7"
4+
- "1.9.2"
5+
- "1.9.3"
6+
- rbx
7+
sudo: required
8+
dist: trusty
9+
script: bundle exec rspec spec

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec

Gemfile.lock

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
PATH
2+
remote: .
3+
specs:
4+
dory (0.0.1)
5+
colorize (~> 0.7)
6+
ptools (~> 1.3)
7+
thor (~> 0.19)
8+
9+
GEM
10+
remote: https://rubygems.org/
11+
specs:
12+
byebug (4.0.5)
13+
columnize (= 0.9.0)
14+
colorize (0.7.7)
15+
columnize (0.9.0)
16+
diff-lcs (1.2.5)
17+
ptools (1.3.3)
18+
rake (10.5.0)
19+
rspec (3.4.0)
20+
rspec-core (~> 3.4.0)
21+
rspec-expectations (~> 3.4.0)
22+
rspec-mocks (~> 3.4.0)
23+
rspec-core (3.4.3)
24+
rspec-support (~> 3.4.0)
25+
rspec-expectations (3.4.0)
26+
diff-lcs (>= 1.2.0, < 2.0)
27+
rspec-support (~> 3.4.0)
28+
rspec-mocks (3.4.1)
29+
diff-lcs (>= 1.2.0, < 2.0)
30+
rspec-support (~> 3.4.0)
31+
rspec-support (3.4.1)
32+
thor (0.19.1)
33+
34+
PLATFORMS
35+
ruby
36+
37+
DEPENDENCIES
38+
byebug (~> 4.0)
39+
dory!
40+
rake (~> 10.5)
41+
rspec (~> 3.4)
42+
43+
BUNDLED WITH
44+
1.11.2

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# dory
2+
3+
[Dory](https://github.com/FreedomBen/dory) wraps [codekitchen/dinghy-http-proxy](https://github.com/codekitchen/dinghy-http-proxy) and makes it easily
4+
available for use on Linux. This way you can work comfortably
5+
side by side on [docker](https://github.com/docker/docker)/[docker-compose](https://github.com/docker/compose) with your colleagues
6+
who run OS X.
7+
8+
Specifically, dory will:
9+
10+
* Fire up the nginx proxy in a daemonized docker container for you
11+
* Configure and start a local dnsmasq to forward DNS queries for
12+
your local domain to the nginx proxy
13+
* Configure your local DNS resolver to point to the local dnsmasq
14+
15+
## Installation
16+
17+
```bash
18+
gem install dory
19+
```
20+
21+
## Usage
22+
23+
Dory has a small selection of commands that are hopefully intuitive. To customize and fine-tune dory's behavior, it can be configured with a yaml config file.
24+
25+
26+
### Commands
27+
```
28+
Commands:
29+
dory config-file # Write a default config file
30+
dory down # Stop all dory services
31+
dory help [COMMAND] # Describe available commands or one specific command
32+
dory restart # Stop and restart all dory services
33+
dory status # Report status of the dory services
34+
dory up # Bring up dory services (nginx-proxy, dnsmasq, resolv)
35+
dory version # Check current installed version of dory
36+
37+
Options:
38+
v, [--verbose], [--no-verbose]
39+
```
40+
41+
### Config file
42+
43+
Default config file which should be placed at `~/.dory.yml` (can be generated with `dory config-file`):
44+
45+
```yaml
46+
---
47+
:dory:
48+
# Be careful if you change the settings of some of
49+
# these services. They may not talk to each other
50+
# if you change IP Addresses.
51+
# For example, resolv expects a nameserver listening at
52+
# the specified address. dnsmasq normally does this,
53+
# but if you disable dnsmasq, it
54+
# will make your system look for a name server that
55+
# doesn't exist.
56+
:dnsmasq:
57+
:enabled: true
58+
:domain: docker # domain that will be listend for
59+
:address: 127.0.0.1 # address returned for queries against domain
60+
:container_name: dory_dnsmasq
61+
:nginx_proxy:
62+
:enabled: true
63+
:container_name: dory_dinghy_http_proxy
64+
:resolv:
65+
:enabled: true
66+
:nameserver: 127.0.0.1
67+
```
68+
69+
## Is this dinghy for Linux?
70+
71+
No. Well, maybe sort of, but not really. [Dinghy](https://github.com/codekitchen/dinghy) has a lot of responsibilities on OS X, most of which are not necessary on Linux since docker runs natively. Something it does that can benefit linux users however, is the setup and management of an [nginx reverse HTTP proxy](https://www.nginx.com/resources/admin-guide/reverse-proxy/). Using full dinghy on Linux for local development doesn't really make sense to me, but using a reverse proxy does. Furthermore, if you work with other devs who run Dinghy on OS X, you will have to massage your (docker-compose)[https://docs.docker.com/compose/] files to avoid conflicting. By using [dory](https://github.com/FreedomBen/dory), you can safely use the same `VIRTUAL_HOST` setup without conflict. And because dory uses [dinghy-http-proxy](https://github.com/codekitchen/dinghy-http-proxy) under the hood, you will be as compatible as possible.
72+
73+
## Are there any reasons to run full dinghy on Linux?
74+
75+
Right now no, but I am intrigued at the possibilities of using dinghy on Linux to drive a cloud-based docker engine. We'll stay tuned.
76+
77+
## Why didn't you just fork dinghy?
78+
79+
That was actually my first approach, and I considered it quite a bit. As I went through the process in my head tho, and reviewed the dinghy source code, I decided that it was just too heavy to really fit the need I had. I love being able to run docker natively, and I revere [the Arch Way](https://wiki.archlinux.org/index.php/The_Arch_Way). Dinghy just seemed like too big of a hammer for this problem (the problem being that I work on Linux, but my colleagues use OS X/Dinghy for docker development).
80+
81+
## What if I'm developing on a cloud server?
82+
83+
You do this too!? Well fine hacker, it's your lucky day because dory has you covered. You can run the nginx proxy on the cloud server and the dnsmasq/resolver locally. Here's how:
84+
85+
## Built on:
86+
87+
* [jwilder/nginx-proxy](https://github.com/jwilder/nginx-proxy) (Indirectly but worthy of mention)
88+
* [codekitchen/dinghy-http-proxy](https://github.com/codekitchen/dinghy-http-proxy)
89+
* [erikhuda/thor](https://github.com/erikhuda/thor)

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'bundler/gem_tasks'
2+
require 'rspec/core/rake_task'
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task default: :spec
7+
task test: :spec

bin/dory

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'thor'
4+
require 'yaml'
5+
6+
require 'dory'
7+
8+
class DoryBin < Thor
9+
class_option :verbose, type: :boolean, aliases: 'v', default: false
10+
11+
desc 'up', 'Bring up dory services (nginx-proxy, dnsmasq, resolv)'
12+
long_desc <<-LONGDESC
13+
Bring up dory services (nginx-proxy, dnsmasq, resolv)
14+
15+
When run, the docker container for the nginx proxy is started,
16+
along with a local dnsmasq instance to resolve DNS requests
17+
for your custom domain to the nginx proxy. The local resolver
18+
will also be configured to use the dnsmasq instance as a nameserver
19+
20+
You can optionally pass in [-s|--server] or [-c|--client] if doing
21+
development on a cloud server. This will tell dory to only bring
22+
up the nginx proxy container if passed --server or only the
23+
dnsmasq/resolv if passed --client. If both server and client
24+
are passed, it is equivalent to a naked 'up'
25+
26+
> $ dory up [-s|--server] [-c|--client]
27+
LONGDESC
28+
option :client, type: :boolean, aliases: 'c', default: false
29+
option :server, type: :boolean, aliases: 's', default: false
30+
def up
31+
exec_up(options)
32+
end
33+
34+
desc 'down', 'Stop all dory services'
35+
long_desc <<-LONGDESC
36+
Stops all dory services. Can optionally pass [-d|--destroy]
37+
to destroy the containers when they stop.
38+
39+
> $ dory down [-d|--destroy]
40+
LONGDESC
41+
option :destroy, type: :boolean, aliases: 'd', default: true
42+
def down
43+
exec_down(options)
44+
end
45+
46+
desc 'version', 'Check current installed version of dory'
47+
def version
48+
puts "Dory - Version: #{Dory::VERSION}"
49+
end
50+
51+
desc 'restart', 'Stop and restart all dory services'
52+
long_desc <<-LONGDESC
53+
Stop and restart dory services (nginx-proxy, dnsmasq, resolv)
54+
55+
> $ dory restart [-d|--destroy] [-s|--server] [-c|--client]
56+
LONGDESC
57+
option :client, type: :boolean, aliases: 'c', default: false
58+
option :server, type: :boolean, aliases: 's', default: false
59+
option :destroy, type: :boolean, aliases: 'd', default: true
60+
def restart
61+
exec_down(options)
62+
exec_up(options)
63+
end
64+
65+
desc 'status', 'Report status of the dory services'
66+
long_desc <<-LONGDESC
67+
Checks the current status of the services managed by dory.
68+
This includes nginx-proxy, dnsmasq, and resolv
69+
70+
> $ dory status
71+
LONGDESC
72+
def status
73+
exec_status(options)
74+
end
75+
76+
desc 'config-file', 'Write a default config file'
77+
long_desc <<-LONGDESC
78+
Writes a dory config file to #{Dory::Config.filename}
79+
containing the default settings. This can then be configured
80+
as preferred.
81+
LONGDESC
82+
def config_file
83+
exec_config_file(options)
84+
end
85+
86+
private
87+
88+
def exec_config_file(options)
89+
if File.exist?(Dory::Config.filename)
90+
print "A config file already exists at #{Dory::Config.filename}. Overwrite with default settings? (Y/N): ".yellow
91+
conf = STDIN.gets.chomp
92+
unless conf =~ /y/i
93+
puts "User declined over-writing. Not writing config file".red
94+
return
95+
end
96+
end
97+
puts "Writing config file to #{Dory::Config.filename}".green
98+
Dory::Config.write_default_settings_file
99+
end
100+
101+
def exec_up(options)
102+
full = (!options[:server] && !options[:client]) ||
103+
( options[:server] && options[:client])
104+
105+
puts "Reading settings file at '#{Dory::Config.filename}'".green if options[:verbose]
106+
settings = Dory::Config.settings
107+
if settings[:dory][:nginx_proxy][:enabled]
108+
puts "nginx_proxy enabled in config file".green if options[:verbose]
109+
if Dory::Proxy.start
110+
puts "Successfully started nginx proxy".green
111+
else
112+
puts "Error starting nginx proxy".red
113+
end
114+
else
115+
puts "nginx_proxy disabled in config file".yellow if options[:verbose]
116+
end
117+
118+
if settings[:dory][:dnsmasq][:enabled]
119+
puts "dnsmasq enabled in config file".green if options[:verbose]
120+
if Dory::Dnsmasq.start
121+
puts "Successfully started dnsmasq".green
122+
else
123+
puts "Error starting dnsmasq".red
124+
end
125+
else
126+
puts "dnsmasq disabled in config file".yellow if options[:verbose]
127+
end
128+
129+
if settings[:dory][:resolv][:enabled]
130+
if Dory::Resolv.configure
131+
puts "Successfully configured local resolver".green
132+
else
133+
puts "Error configuring local resolver".red
134+
end
135+
puts "resolv enabled in config file".green if options[:verbose]
136+
else
137+
puts "resolv disabled in config file".yellow if options[:verbose]
138+
end
139+
end
140+
141+
def exec_status(options)
142+
settings = Dory::Config.settings
143+
144+
if Dory::Proxy.running?
145+
puts "[*] Nginx proxy: Running as docker container #{Dory::Proxy.container_name}".green
146+
elsif !settings[:dory][:nginx_proxy][:enabled]
147+
puts "[*] Nginx proxy is disabled in config file".yellow
148+
else
149+
puts "[*] Nginx proxy is not running".red
150+
end
151+
152+
if Dory::Dnsmasq.running?
153+
puts "[*] Dnsmasq: Running as docker container #{Dory::Dnsmasq.container_name}".green
154+
elsif !settings[:dory][:dnsmasq][:enabled]
155+
puts "[*] Dnsmasq is disabled in config file".yellow
156+
else
157+
puts "[*] Dnsmasq is not running".red
158+
end
159+
160+
if Dory::Resolv.has_our_nameserver?
161+
puts "[*] Resolv: configured with nameserver #{}".green
162+
elsif !settings[:dory][:resolv][:enabled]
163+
puts "[*] Resolv is disabled in config file".yellow
164+
else
165+
puts "[*] Resolv is not configured".red
166+
end
167+
end
168+
169+
def exec_down(options)
170+
destroy = options[:destroy]
171+
172+
if Dory::Resolv.clean
173+
puts "nameserver removed from resolv file".green
174+
else
175+
puts "Unable to remove nameserver from resolv file".red
176+
end
177+
178+
if Dory::Dnsmasq.stop
179+
puts "Dnsmasq container stopped".green
180+
if options[:destroy]
181+
if Dory::Dnsmasq.delete
182+
puts "Dnsmasq container successfully deleted".green
183+
else
184+
puts "Dnsmasq container failed to delete".red
185+
end
186+
end
187+
else
188+
puts "Dnsmasq container failed to stop".red
189+
end
190+
191+
if Dory::Proxy.stop
192+
puts "Nginx proxy stopped".green
193+
if options[:destroy]
194+
if Dory::Proxy.delete
195+
puts "Nginx proxy container successfully deleted".green
196+
else
197+
puts "Nginx proxy container failed to delete".red
198+
end
199+
end
200+
else
201+
puts "Nginx proxy failed to stop".red
202+
end
203+
end
204+
end
205+
206+
if !ARGV.empty? && %w[-v --version].include?(ARGV.first)
207+
puts "Dory - Version: #{Dory::VERSION}"
208+
else
209+
DoryBin.start(ARGV)
210+
end

0 commit comments

Comments
 (0)