dip 4.2.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -42
- data/exe/dip +8 -8
- data/lib/dip.rb +2 -2
- data/lib/dip/cli.rb +47 -33
- data/lib/dip/cli/base.rb +11 -0
- data/lib/dip/cli/console.rb +9 -8
- data/lib/dip/cli/dns.rb +33 -32
- data/lib/dip/cli/nginx.rb +27 -26
- data/lib/dip/cli/ssh.rb +27 -23
- data/lib/dip/command.rb +8 -7
- data/lib/dip/commands/compose.rb +21 -16
- data/lib/dip/commands/console.rb +6 -6
- data/lib/dip/commands/dns.rb +7 -7
- data/lib/dip/commands/list.rb +3 -3
- data/lib/dip/commands/nginx.rb +4 -4
- data/lib/dip/commands/provision.rb +1 -1
- data/lib/dip/commands/run.rb +44 -19
- data/lib/dip/commands/ssh.rb +13 -5
- data/lib/dip/config.rb +73 -15
- data/lib/dip/environment.rb +24 -8
- data/lib/dip/ext/hash.rb +1 -1
- data/lib/dip/interaction_tree.rb +3 -16
- data/lib/dip/version.rb +1 -1
- metadata +46 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5df0e0954a241e561cfe313fc0f6a8000644e8ebe102a954ba721e81752046a6
|
4
|
+
data.tar.gz: 89c96af17e4dc28d2d0953deb411075e662eb7815193517634b08242d9a31761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6730c668a3850de7625f819045787dd901546868df56ecde7264796736b567e66a3ef96a7db7b7855585f6b6a47ba0b241e0ce7b07177692cf0df783a35bc313
|
7
|
+
data.tar.gz: d32638715384461a37cb62ed6f2f0f41b6b3ea3618e9b7dd006d3d57b88325f3c37ac9faa5e82727fda56297473153b59736c97f162d326e8ffb3d1020519d45
|
data/README.md
CHANGED
@@ -16,9 +16,11 @@ A command-line utility that gives the "native" interaction with applications con
|
|
16
16
|
## Presentations and examples
|
17
17
|
|
18
18
|
- [Local development with Docker containers](https://slides.com/bibendi/dip)
|
19
|
-
- Dockerized Ruby on Rails applications: [one](https://github.com/bibendi/dip-example-rails), [
|
20
|
-
-
|
19
|
+
- Dockerized Ruby on Rails applications: [one](https://github.com/lewagon/rails-k8s-demo), [two](https://github.com/bibendi/dip-example-rails), [three](https://github.com/evilmartians/evil_chat)
|
20
|
+
- Dockerized Node.js application: [one](https://github.com/bibendi/twinkle.js), [two](https://github.com/bibendi/yt-graphql-react-event-booking-api)
|
21
21
|
- [Dockerized Ruby gem](https://github.com/bibendi/schked)
|
22
|
+
- [Dockerizing Ruby and Rails development](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development)
|
23
|
+
- [Reusable development containers with Docker Compose and Dip](https://evilmartians.com/chronicles/reusable-development-containers-with-docker-compose-and-dip)
|
22
24
|
|
23
25
|
[![asciicast](https://asciinema.org/a/210236.svg)](https://asciinema.org/a/210236)
|
24
26
|
|
@@ -36,6 +38,7 @@ After that we can type commands without `dip` prefix. For example:
|
|
36
38
|
<run-command> *any-args
|
37
39
|
compose *any-compose-arg
|
38
40
|
up <service>
|
41
|
+
build
|
39
42
|
down
|
40
43
|
provision
|
41
44
|
```
|
@@ -53,41 +56,11 @@ After that, it will be automatically applied when you open your preferred termin
|
|
53
56
|
|
54
57
|
## Installation
|
55
58
|
|
56
|
-
You have many ways.
|
57
|
-
|
58
|
-
### Homebrew
|
59
|
-
|
60
|
-
|
61
|
-
You can use [Homebrew](https://brew.sh) on macOS (or [Linux](https://docs.brew.sh/Homebrew-on-Linux)).
|
62
|
-
|
63
|
-
Today Homebrew tap for DIP is located at https://github.com/bibendi/homebrew-dip
|
64
|
-
|
65
|
-
```sh
|
66
|
-
brew tap bibendi/dip
|
67
|
-
brew install dip
|
68
|
-
```
|
69
|
-
|
70
|
-
### Ruby Gem
|
71
|
-
|
72
59
|
```sh
|
73
60
|
gem install dip
|
74
61
|
```
|
75
62
|
|
76
|
-
|
77
|
-
|
78
|
-
If you don't have installed Ruby, then you could copy a precompiled binary to your system.
|
79
|
-
It can be found at [releases page](https://github.com/bibendi/dip/releases)
|
80
|
-
or type bellow into your terminal:
|
81
|
-
|
82
|
-
```sh
|
83
|
-
curl -L https://github.com/bibendi/dip/releases/download/4.2.0/dip-`uname -s`-`uname -m` > /usr/local/bin/dip
|
84
|
-
chmod +x /usr/local/bin/dip
|
85
|
-
```
|
86
|
-
|
87
|
-
## Docker installation
|
88
|
-
|
89
|
-
- [Ubuntu](docs/docker-ubuntu-install.md)
|
90
|
-
- [Mac OS](docs/docker-for-mac-install.md)
|
63
|
+
The compiled binary is no more provided since version 7, because of new version of [Ruby Packer](https://github.com/pmq20/ruby-packer) not released for a long time with recent Ruby version. Also there was a lot of work to prepare each release of Dip for MacOS version.
|
91
64
|
|
92
65
|
## Usage
|
93
66
|
|
@@ -98,17 +71,17 @@ dip SUBCOMMAND --help
|
|
98
71
|
|
99
72
|
### dip.yml
|
100
73
|
|
101
|
-
The configuration
|
74
|
+
The configuration is loaded from `dip.yml` file. It may be located in a working directory, or it will be found in the nearest parent directory up to the file system root. If nearby places `dip.override.yml` file, it will be merged into the main config.
|
75
|
+
|
102
76
|
Also, in some cases, you may want to change the default config path by providing an environment variable `DIP_FILE`.
|
103
|
-
If nearby places `dip.override.yml` file it would be merged into the main config.
|
104
77
|
|
105
78
|
Below is an example of a real config.
|
106
|
-
|
107
|
-
Also, you can check out examples
|
79
|
+
Config file reference will be written soon.
|
80
|
+
Also, you can check out examples at the top.
|
108
81
|
|
109
82
|
```yml
|
110
83
|
# Required minimum dip version
|
111
|
-
version: '
|
84
|
+
version: '7.0'
|
112
85
|
|
113
86
|
environment:
|
114
87
|
COMPOSE_EXT: development
|
@@ -121,9 +94,10 @@ compose:
|
|
121
94
|
project_name: bear
|
122
95
|
|
123
96
|
interaction:
|
124
|
-
|
97
|
+
shell:
|
125
98
|
description: Open the Bash shell in app's container
|
126
99
|
service: app
|
100
|
+
command: bash
|
127
101
|
compose:
|
128
102
|
run_options: [no-deps]
|
129
103
|
|
@@ -153,7 +127,7 @@ interaction:
|
|
153
127
|
description: Run Rails server at http://localhost:3000
|
154
128
|
service: web
|
155
129
|
compose:
|
156
|
-
run_options: [service-ports]
|
130
|
+
run_options: [service-ports, use-aliases]
|
157
131
|
|
158
132
|
sidekiq:
|
159
133
|
description: Run sidekiq in background
|
@@ -168,12 +142,55 @@ interaction:
|
|
168
142
|
default_args: db_dev
|
169
143
|
command: psql -h pg -U postgres
|
170
144
|
|
145
|
+
clean_cache:
|
146
|
+
description: Delete cache files on the host machine
|
147
|
+
command: rm -rf $(pwd)/tmp/cache/*
|
148
|
+
|
171
149
|
provision:
|
172
150
|
- dip compose down --volumes
|
151
|
+
- dip clean_cache
|
173
152
|
- dip compose up -d pg redis
|
174
153
|
- dip bash -c ./bin/setup
|
175
154
|
```
|
176
155
|
|
156
|
+
### Predefined environment variables
|
157
|
+
|
158
|
+
#### $DIP_OS
|
159
|
+
|
160
|
+
Current OS architecture (e.g. `linux`, `darwin`, `freebsd`, and so on). Sometime it may be useful to have one common `docker-compose.yml` and OS-dependent Compose configs.
|
161
|
+
|
162
|
+
#### $DIP_WORK_DIR_REL_PATH
|
163
|
+
|
164
|
+
Relative path from the current directory to the nearest directory where a Dip's config is found. It is useful when you need to mount a specific local directory to a container along with ability to change its working dir. For example:
|
165
|
+
|
166
|
+
```
|
167
|
+
- project_root
|
168
|
+
|- dip.yml (1)
|
169
|
+
|- docker-compose.yml (2)
|
170
|
+
|- sub-project-dir
|
171
|
+
|- your current directory is here <<<
|
172
|
+
```
|
173
|
+
|
174
|
+
```yml
|
175
|
+
# dip.yml (1)
|
176
|
+
environment:
|
177
|
+
WORK_DIR: /app/${DIP_WORK_DIR_REL_PATH}
|
178
|
+
```
|
179
|
+
|
180
|
+
```yml
|
181
|
+
# docker-compose.yml (2)
|
182
|
+
services:
|
183
|
+
app:
|
184
|
+
working_dir: ${WORK_DIR:-/app}
|
185
|
+
```
|
186
|
+
|
187
|
+
```sh
|
188
|
+
cd sub-project-dir
|
189
|
+
dip run bash -c pwd
|
190
|
+
```
|
191
|
+
|
192
|
+
returned is `/app/sub-project-dir`.
|
193
|
+
|
177
194
|
### dip run
|
178
195
|
|
179
196
|
Run commands defined within the `interaction` section of dip.yml
|
@@ -183,16 +200,27 @@ dip run rails c
|
|
183
200
|
dip run rake db:migrate
|
184
201
|
```
|
185
202
|
|
186
|
-
`run` argument can be omitted
|
203
|
+
Also, `run` argument can be omitted
|
187
204
|
|
188
205
|
```sh
|
189
206
|
dip rake db:migrate
|
207
|
+
```
|
208
|
+
|
209
|
+
You can pass in a custom environment variable into a container:
|
210
|
+
|
211
|
+
```sh
|
190
212
|
dip VERSION=12352452 rake db:rollback
|
191
213
|
```
|
192
214
|
|
215
|
+
Use options `-p, --publish=[]` if you need to additionally publish a container's port(s) to the host unless this behaviour is not configured at dip.yml:
|
216
|
+
|
217
|
+
```sh
|
218
|
+
dip run -p 3000:3000 bundle exec rackup config.ru
|
219
|
+
```
|
220
|
+
|
193
221
|
### dip ls
|
194
222
|
|
195
|
-
List
|
223
|
+
List all available run commands.
|
196
224
|
|
197
225
|
```sh
|
198
226
|
dip ls
|
@@ -242,6 +270,21 @@ volumes:
|
|
242
270
|
name: ssh_data
|
243
271
|
```
|
244
272
|
|
273
|
+
if you want to use non-root user you can specify UID like so:
|
274
|
+
|
275
|
+
```
|
276
|
+
dip ssh up -u 1000
|
277
|
+
```
|
278
|
+
|
279
|
+
This especially helpful if you have something like this in your docker-compose.yml:
|
280
|
+
|
281
|
+
```
|
282
|
+
services:
|
283
|
+
web:
|
284
|
+
user: "1000:1000"
|
285
|
+
|
286
|
+
```
|
287
|
+
|
245
288
|
### dip nginx
|
246
289
|
|
247
290
|
Runs Nginx server container based on [bibendi/nginx-proxy](https://github.com/bibendi/nginx-proxy) image. An application's docker-compose.yml should contain environment variable `VIRTUAL_HOST` and `VIRTUAL_PATH` and connects to external network `frontend`.
|
data/exe/dip
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
lib_path = File.expand_path(
|
4
|
+
lib_path = File.expand_path("../lib", __dir__)
|
5
5
|
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
6
6
|
|
7
|
-
require 'dip'
|
8
|
-
require 'dip/cli'
|
9
|
-
require 'dip/run_vars'
|
10
|
-
|
11
7
|
begin
|
12
|
-
require
|
8
|
+
require "pry-byebug" if ENV["DIP_ENV"] == "debug"
|
13
9
|
rescue LoadError
|
14
|
-
|
10
|
+
# do nothing
|
15
11
|
end
|
16
12
|
|
17
|
-
|
13
|
+
require "dip"
|
14
|
+
require "dip/cli"
|
15
|
+
require "dip/run_vars"
|
16
|
+
|
17
|
+
Signal.trap("INT") do
|
18
18
|
warn("\n#{caller.join("\n")}: interrupted")
|
19
19
|
exit(1)
|
20
20
|
end
|
data/lib/dip.rb
CHANGED
@@ -11,14 +11,14 @@ module Dip
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def env
|
14
|
-
@env ||= Dip::Environment.new(
|
14
|
+
@env ||= Dip::Environment.new(config.exist? ? config.environment : {})
|
15
15
|
end
|
16
16
|
|
17
17
|
def bin_path
|
18
18
|
$PROGRAM_NAME.start_with?("./") ? File.expand_path($PROGRAM_NAME) : "dip"
|
19
19
|
end
|
20
20
|
|
21
|
-
%w
|
21
|
+
%w[test debug].each do |key|
|
22
22
|
define_method("#{key}?") do
|
23
23
|
ENV["DIP_ENV"] == key
|
24
24
|
end
|
data/lib/dip/cli.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "thor"
|
4
|
+
require "dip/run_vars"
|
5
5
|
|
6
6
|
module Dip
|
7
7
|
class CLI < Thor
|
8
|
+
TOP_LEVEL_COMMANDS = %w[help version ls compose up stop down run provision ssh dns nginx console].freeze
|
9
|
+
|
8
10
|
class << self
|
9
11
|
# Hackery. Take the run method away from Thor so that we can redefine it.
|
10
12
|
def is_thor_reserved_word?(word, type)
|
@@ -13,44 +15,49 @@ module Dip
|
|
13
15
|
super
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
+
def exit_on_failure?
|
19
|
+
true
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
+
def start(argv)
|
23
|
+
argv = Dip::RunVars.call(argv, ENV)
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
cmd = argv.first
|
26
|
+
|
27
|
+
if cmd && !TOP_LEVEL_COMMANDS.include?(cmd) && Dip.config.exist? && Dip.config.interaction.key?(cmd.to_sym)
|
28
|
+
argv.unshift("run")
|
29
|
+
end
|
30
|
+
|
31
|
+
super Dip::RunVars.call(argv, ENV)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
Dip.config.interaction.key?(cmd.to_sym)
|
33
|
-
end
|
35
|
+
stop_on_unknown_option! :run
|
34
36
|
|
35
|
-
desc
|
37
|
+
desc "version", "dip version"
|
36
38
|
def version
|
37
|
-
require_relative
|
39
|
+
require_relative "version"
|
38
40
|
puts Dip::VERSION
|
39
41
|
end
|
40
|
-
map %w
|
42
|
+
map %w[--version -v] => :version
|
41
43
|
|
42
|
-
desc
|
44
|
+
desc "ls", "List available run commands"
|
43
45
|
def ls
|
44
|
-
require_relative
|
46
|
+
require_relative "commands/list"
|
45
47
|
Dip::Commands::List.new.execute
|
46
48
|
end
|
47
49
|
|
48
|
-
desc
|
50
|
+
desc "compose CMD [OPTIONS]", "Run docker-compose commands"
|
49
51
|
def compose(*argv)
|
50
|
-
require_relative
|
52
|
+
require_relative "commands/compose"
|
51
53
|
Dip::Commands::Compose.new(*argv).execute
|
52
54
|
end
|
53
55
|
|
56
|
+
desc "build [OPTIONS] SERVICE", "Run `docker-compose build` command"
|
57
|
+
def build(*argv)
|
58
|
+
compose("build", *argv)
|
59
|
+
end
|
60
|
+
|
54
61
|
desc "up [OPTIONS] SERVICE", "Run `docker-compose up` command"
|
55
62
|
def up(*argv)
|
56
63
|
compose("up", *argv)
|
@@ -61,42 +68,49 @@ module Dip
|
|
61
68
|
compose("stop", *argv)
|
62
69
|
end
|
63
70
|
|
64
|
-
desc "down
|
71
|
+
desc "down [OPTIONS]", "Run `docker-compose down` command"
|
65
72
|
def down(*argv)
|
66
73
|
compose("down", *argv)
|
67
74
|
end
|
68
75
|
|
69
|
-
desc
|
76
|
+
desc "run [OPTIONS] CMD [ARGS]", "Run configured command in a docker-compose service. `run` prefix may be omitted"
|
77
|
+
method_option :publish, aliases: "-p", type: :string, repeatable: true,
|
78
|
+
desc: "Publish a container's port(s) to the host"
|
79
|
+
method_option :help, aliases: "-h", type: :boolean, desc: "Display usage information"
|
70
80
|
def run(*argv)
|
71
|
-
|
72
|
-
|
81
|
+
if argv.empty? || options[:help]
|
82
|
+
invoke :help, ["run"]
|
83
|
+
else
|
84
|
+
require_relative "commands/run"
|
85
|
+
Dip::Commands::Run.new(*argv, publish: options[:publish]).execute
|
86
|
+
end
|
73
87
|
end
|
74
88
|
|
75
89
|
desc "provision", "Execute commands within provision section"
|
76
|
-
method_option :help, aliases:
|
77
|
-
desc:
|
90
|
+
method_option :help, aliases: "-h", type: :boolean,
|
91
|
+
desc: "Display usage information"
|
78
92
|
def provision
|
79
93
|
if options[:help]
|
80
|
-
invoke :help, [
|
94
|
+
invoke :help, ["provision"]
|
81
95
|
else
|
82
|
-
require_relative
|
96
|
+
require_relative "commands/provision"
|
83
97
|
Dip::Commands::Provision.new.execute
|
84
98
|
end
|
85
99
|
end
|
86
100
|
|
87
|
-
require_relative
|
101
|
+
require_relative "cli/ssh"
|
88
102
|
desc "ssh", "ssh-agent container commands"
|
89
103
|
subcommand :ssh, Dip::CLI::SSH
|
90
104
|
|
91
|
-
require_relative
|
105
|
+
require_relative "cli/dns"
|
92
106
|
desc "dns", "DNS server for automatic docker container discovery"
|
93
107
|
subcommand :dns, Dip::CLI::DNS
|
94
108
|
|
95
|
-
require_relative
|
109
|
+
require_relative "cli/nginx"
|
96
110
|
desc "nginx", "Nginx reverse proxy server"
|
97
111
|
subcommand :nginx, Dip::CLI::Nginx
|
98
112
|
|
99
|
-
require_relative
|
113
|
+
require_relative "cli/console"
|
100
114
|
desc "console", "Integrate Dip commands into shell (only ZSH and Bash is supported)"
|
101
115
|
subcommand :console, Dip::CLI::Console
|
102
116
|
end
|
data/lib/dip/cli/base.rb
ADDED
data/lib/dip/cli/console.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "thor"
|
4
|
+
require_relative "./base"
|
4
5
|
require_relative "../commands/console"
|
5
6
|
|
6
7
|
module Dip
|
7
8
|
class CLI
|
8
|
-
class Console <
|
9
|
+
class Console < Base
|
9
10
|
desc "start", "Integrate Dip into current shell"
|
10
|
-
method_option :help, aliases:
|
11
|
-
desc:
|
11
|
+
method_option :help, aliases: "-h", type: :boolean,
|
12
|
+
desc: "Display usage information"
|
12
13
|
def start
|
13
14
|
if options[:help]
|
14
|
-
invoke :help, [
|
15
|
+
invoke :help, ["start"]
|
15
16
|
else
|
16
17
|
Dip::Commands::Console::Start.new.execute
|
17
18
|
end
|
@@ -20,11 +21,11 @@ module Dip
|
|
20
21
|
default_task :start
|
21
22
|
|
22
23
|
desc "inject", "Inject aliases"
|
23
|
-
method_option :help, aliases:
|
24
|
-
desc:
|
24
|
+
method_option :help, aliases: "-h", type: :boolean,
|
25
|
+
desc: "Display usage information"
|
25
26
|
def inject
|
26
27
|
if options[:help]
|
27
|
-
invoke :help, [
|
28
|
+
invoke :help, ["inject"]
|
28
29
|
else
|
29
30
|
Dip::Commands::Console::Inject.new.execute
|
30
31
|
end
|