dip 4.2.0 → 7.0.0

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
  SHA256:
3
- metadata.gz: de28bb80ddff1548082c5b8ccd0115bcd650cbdba9a930c666b02751cf0ba976
4
- data.tar.gz: 96a4a6d5b2f78b559ef429f793e1899ec8d35edc7f10ac90693632b8a9e2be06
3
+ metadata.gz: 5df0e0954a241e561cfe313fc0f6a8000644e8ebe102a954ba721e81752046a6
4
+ data.tar.gz: 89c96af17e4dc28d2d0953deb411075e662eb7815193517634b08242d9a31761
5
5
  SHA512:
6
- metadata.gz: 404af36fd19249124ab8bf8ce3f765c03f8e72ef9d6c1138424704233caf543c7ce2cf8ea7a86ece144407597bfba895cdb140ef277aa71042201a77221c974c
7
- data.tar.gz: 4b788801e5c6e73e259f0de5b4c137aa5dcce5a7e681dae1d21b2c403118cdafdf0870c22bd80be350c25f943e100930c0f8296927898196e0c812e0f1f66254
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), [two](https://github.com/evilmartians/evil_chat)
20
- - [Dockerized Node.js application](https://github.com/bibendi/yt-graphql-react-event-booking-api)
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
- ### Precompiled binary
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 file `dip.yml` should be placed in a project root directory.
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
- `dip.yml` reference will be written soon.
107
- Also, you can check out examples in the top.
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: '4.1'
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
- bash:
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 al available run commands.
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('../lib', __dir__)
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 'pry-byebug' if Dip.debug?
8
+ require "pry-byebug" if ENV["DIP_ENV"] == "debug"
13
9
  rescue LoadError
14
- puts "pry-byebug not found!"
10
+ # do nothing
15
11
  end
16
12
 
17
- Signal.trap('INT') do
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(Dip::Config.exist? ? config.environment : {})
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(test debug).each do |key|
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 'thor'
4
- require 'dip/run_vars'
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 start(argv)
17
- super Dip::RunVars.call(argv, ENV)
18
+ def exit_on_failure?
19
+ true
18
20
  end
19
- end
20
21
 
21
- stop_on_unknown_option! :up
22
+ def start(argv)
23
+ argv = Dip::RunVars.call(argv, ENV)
22
24
 
23
- def method_missing(cmd, *args)
24
- if Dip.config.interaction.key?(cmd.to_sym)
25
- self.class.start(["run", cmd.to_s, *args])
26
- else
27
- super
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
- def respond_to_missing?(cmd)
32
- Dip.config.interaction.key?(cmd.to_sym)
33
- end
35
+ stop_on_unknown_option! :run
34
36
 
35
- desc 'version', 'dip version'
37
+ desc "version", "dip version"
36
38
  def version
37
- require_relative 'version'
39
+ require_relative "version"
38
40
  puts Dip::VERSION
39
41
  end
40
- map %w(--version -v) => :version
42
+ map %w[--version -v] => :version
41
43
 
42
- desc 'ls', 'List available run commands'
44
+ desc "ls", "List available run commands"
43
45
  def ls
44
- require_relative 'commands/list'
46
+ require_relative "commands/list"
45
47
  Dip::Commands::List.new.execute
46
48
  end
47
49
 
48
- desc 'compose CMD [OPTIONS]', 'Run docker-compose commands'
50
+ desc "compose CMD [OPTIONS]", "Run docker-compose commands"
49
51
  def compose(*argv)
50
- require_relative 'commands/compose'
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 all services [OPTIONS]", "Run `docker-compose down` command"
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 'CMD or dip run CMD [OPTIONS]', 'Run configured command in a docker-compose service'
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
- require_relative 'commands/run'
72
- Dip::Commands::Run.new(*argv).execute
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: '-h', type: :boolean,
77
- desc: 'Display usage information'
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, ['provision']
94
+ invoke :help, ["provision"]
81
95
  else
82
- require_relative 'commands/provision'
96
+ require_relative "commands/provision"
83
97
  Dip::Commands::Provision.new.execute
84
98
  end
85
99
  end
86
100
 
87
- require_relative 'cli/ssh'
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 'cli/dns'
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 'cli/nginx'
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 'cli/console'
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dip
4
+ class CLI
5
+ class Base < Thor
6
+ def self.exit_on_failure?
7
+ true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
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 < Thor
9
+ class Console < Base
9
10
  desc "start", "Integrate Dip into current shell"
10
- method_option :help, aliases: '-h', type: :boolean,
11
- desc: 'Display usage information'
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, ['start']
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: '-h', type: :boolean,
24
- desc: 'Display usage information'
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, ['inject']
28
+ invoke :help, ["inject"]
28
29
  else
29
30
  Dip::Commands::Console::Inject.new.execute
30
31
  end