dip 7.8.0 → 8.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: 88f631de08ccd575c2e65930de249fbbba598e0948e8335fd9bbb4adf8a455c8
4
- data.tar.gz: 0d906d4a243285684469524e85a8d494f12a13de58065e1ecf8eaccc6ef85903
3
+ metadata.gz: 027ac4456743eaef5ed3d2a461b15e57fcc13739500ef04bdedfca37b4c6c266
4
+ data.tar.gz: e5cdc4f2597241c242bc91f007ab35a2392feafbf924109f97f48ff330228997
5
5
  SHA512:
6
- metadata.gz: 51aa9e654715ee7836b9d143760dc028e9f06f811e0804decffc48fffcef4816e78c1f302f2d9af3462faad53a53efa755112804e116278372f447192572a06b
7
- data.tar.gz: 12521190b37c170b54abaa319c3ad877999c9471f3936a7d732b2bbaeb776b922c28a8ab7d2ccc13322f73294419156f1d6156ccc35c2e1ac5709ac55d0bc8f2
6
+ metadata.gz: 59685a0ab3f5d1174d58048d021b8f4f12d494aaa09773e0b0cfd05d4a2d12975c594efc7597b67e054912f5e6d75fdbd293ac7ca5ba69ab06af858f93dac1c5
7
+ data.tar.gz: 505a3e3657f17a0c01e1d785bfb23a86982ee42da7a8185ccf753de0116e7f18d082d66d11bac07031e43600c9397a74728de62e0a6d70191f9dbe939080f2da
data/README.md CHANGED
@@ -2,11 +2,9 @@
2
2
  [![Build Status](https://github.com/bibendi/dip/workflows/Ruby/badge.svg?branch=master)](https://github.com/bibendi/dip/actions?query=branch%3Amaster)
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/d0dca854f0930502f7b3/maintainability)](https://codeclimate.com/github/bibendi/dip/maintainability)
4
4
 
5
- # DIP
5
+ <img src="https://raw.githubusercontent.com/bibendi/dip/master/.github/logo.png" alt="dip logo" height="140" />
6
6
 
7
- Docker Interaction Program.
8
-
9
- Development-environment CLI program providing the native-like interaction with a Dockerized application. It creates the feeling that you are working without mind-blowing commands to run the containers.
7
+ The dip is a CLI dev–tool that provides native-like interaction with a Dockerized application. It gives the feeling that you are working without using mind-blowing commands to run containers.
10
8
 
11
9
  <a href="https://evilmartians.com/?utm_source=dip">
12
10
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" height="80" /></a>
@@ -14,7 +12,7 @@ Development-environment CLI program providing the native-like interaction with a
14
12
  ## Presentations and examples
15
13
 
16
14
  - [Local development with Docker containers](https://slides.com/bibendi/dip)
17
- - 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)
15
+ - [Dockerized Ruby on Rails application](https://SberMarket-Tech/outbox-example-apps)
18
16
  - Dockerized Node.js application: [one](https://github.com/bibendi/twinkle.js), [two](https://github.com/bibendi/yt-graphql-react-event-booking-api)
19
17
  - [Dockerized Ruby gem](https://github.com/bibendi/schked)
20
18
  - [Dockerizing Ruby and Rails development](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development)
@@ -22,7 +20,13 @@ Development-environment CLI program providing the native-like interaction with a
22
20
 
23
21
  [![asciicast](https://asciinema.org/a/210236.svg)](https://asciinema.org/a/210236)
24
22
 
25
- ## Integration with shell
23
+ ## Installation
24
+
25
+ ```sh
26
+ gem install dip
27
+ ```
28
+
29
+ ### Integration with shell
26
30
 
27
31
  Dip can be injected into the current shell (ZSH or Bash).
28
32
 
@@ -53,14 +57,6 @@ VERSION=20180515103400 rails db:migrate:down
53
57
  You could add this `eval` at the end of your `~/.zshrc`, or `~/.bashrc`, or `~/.bash_profile`.
54
58
  After that, it will be automatically applied when you open your preferred terminal.
55
59
 
56
- ## Installation
57
-
58
- ```sh
59
- gem install dip
60
- ```
61
-
62
- 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.
63
-
64
60
  ## Usage
65
61
 
66
62
  ```sh
@@ -80,7 +76,7 @@ Also, you can check out examples at the top.
80
76
 
81
77
  ```yml
82
78
  # Required minimum dip version
83
- version: '7.7'
79
+ version: '8.0'
84
80
 
85
81
  environment:
86
82
  COMPOSE_EXT: development
@@ -242,19 +238,16 @@ services:
242
238
 
243
239
  The container will run using the same user ID as your host machine.
244
240
 
245
-
246
241
  ### dip run
247
242
 
248
243
  Run commands defined within the `interaction` section of dip.yml
249
244
 
250
245
  A command will be executed by specified runner. Dip has three types of them:
251
246
 
252
- - `docker-compose` runner — used when the `service` option is defined.
247
+ - `docker compose` runner — used when the `service` option is defined.
253
248
  - `kubectl` runner — used when the `pod` option is defined.
254
249
  - `local` runner — used when the previous ones are not defined.
255
250
 
256
- If you are still using `docker-compose` binary (i.e., prior to Compose V2 changes), a command would be run through it. You can disable using of Compose V2 by passing an environment variable `DIP_COMPOSE_V2=false dip run`.
257
-
258
251
  ```sh
259
252
  dip run rails c
260
253
  dip run rake db:migrate
@@ -306,7 +299,7 @@ Run commands each by each from `provision` section of dip.yml
306
299
 
307
300
  ### dip compose
308
301
 
309
- Run docker-compose commands that are configured according to the application's dip.yml:
302
+ Run Docker Compose commands that are configured according to the application's dip.yml:
310
303
 
311
304
  ```sh
312
305
  dip compose COMMAND [OPTIONS]
@@ -314,6 +307,35 @@ dip compose COMMAND [OPTIONS]
314
307
  dip compose up -d redis
315
308
  ```
316
309
 
310
+ ### dip infra
311
+
312
+ Runs shared Docker Compose services that are used by the current application. Useful for microservices.
313
+
314
+ There are several official infrastructure services available:
315
+ - [dip-postgres](https://github.com/bibendi/dip-postgres)
316
+ - [dip-kafka](https://github.com/bibendi/dip-kafka)
317
+ - [dip-nginx](https://github.com/bibendi/dip-nginx)
318
+
319
+ ```yaml
320
+ # dip.yml
321
+ infra:
322
+ foo:
323
+ git: https://github.com/owner/foo.git
324
+ ref: latest # default, optional
325
+ bar:
326
+ path: ~/path/to/bar
327
+ ```
328
+
329
+ Repositories will be pulled to a `~/.dip/infra` folder. For example, for the `foo` service it would be like this: `~/.dip/infra/foo/latest` and clonned with the following command: `git clone -b <ref> --single-branch <git> --depth 1`.
330
+
331
+ Available CLI commands:
332
+
333
+ - `dip infra update` pulls updates from sources
334
+ - `dip infra up` starts all infra services
335
+ - `dip infra up -n kafka` starts a specific infra service
336
+ - `dip infra down` stops all infra services
337
+ - `dip infra down -n kafka` stops a specific infra service
338
+
317
339
  ### dip ktl
318
340
 
319
341
  Run kubectl commands that are configured according to the application's dip.yml:
@@ -358,88 +380,10 @@ dip ssh up -u 1000
358
380
 
359
381
  This especially helpful if you have something like this in your docker-compose.yml:
360
382
 
361
- ```
383
+ ```yml
362
384
  services:
363
385
  web:
364
386
  user: "1000:1000"
365
-
366
- ```
367
-
368
- ### dip nginx
369
-
370
- Runs Nginx server container based on [nginxproxy/nginx-proxy](https://github.com/nginx-proxy/nginx-proxy) image. An application's docker-compose.yml should contain environment variable `VIRTUAL_HOST` and `VIRTUAL_PATH` and connects to external network `frontend`.
371
-
372
- foo-project/docker-compose.yml
373
-
374
- ```yml
375
- services:
376
- foo-web:
377
- image: company/foo_image
378
- environment:
379
- - VIRTUAL_HOST=*.bar-app.docker
380
- - VIRTUAL_PATH=/
381
- networks:
382
- - default
383
- - frontend
384
- dns: $DIP_DNS
385
-
386
- networks:
387
- frontend:
388
- external:
389
- name: frontend
390
- ```
391
-
392
- baz-project/docker-compose.yml
393
-
394
- ```yml
395
- services:
396
- baz-web:
397
- image: company/baz_image
398
- environment:
399
- - VIRTUAL_HOST=*.bar-app.docker
400
- - VIRTUAL_PATH=/api/v1/baz_service,/api/v2/baz_service
401
- networks:
402
- - default
403
- - frontend
404
- dns: $DIP_DNS
405
-
406
- networks:
407
- frontend:
408
- external:
409
- name: frontend
410
- ```
411
-
412
- ```sh
413
- dip nginx up
414
- cd foo-project && dip compose up
415
- cd baz-project && dip compose up
416
- curl www.bar-app.docker/api/v1/quz
417
- curl www.bar-app.docker/api/v1/baz_service/qzz
418
- ```
419
-
420
- #### Pass SSL certificates
421
-
422
- ```sh
423
- dip nginx up -c $HOME/ssl_certificates
424
- ```
425
-
426
- #### Publish more than one port to localhost
427
-
428
- Just pass a list, separated by a space:
429
-
430
- ```sh
431
- dip nginx up -p 80:80 443:443
432
- ```
433
-
434
- ### dip dns
435
-
436
- Runs a DNS server container based on https://github.com/aacebedo/dnsdock. It is used for container to container requests through Nginx. An application's docker-compose.yml should define `dns` configuration with environment variable `$DIP_DNS` and connect to external network `frontend`. `$DIP_DNS` will be automatically assigned by dip.
437
-
438
- ```sh
439
- dip dns up
440
-
441
- cd foo-project
442
- dip compose exec foo-web curl http://www.bar-app.docker/api/v1/baz_service
443
387
  ```
444
388
 
445
389
  ## Changelog
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "base"
5
+ require_relative "../commands/infra"
6
+ require_relative "../commands/infra/service"
7
+
8
+ module Dip
9
+ class CLI
10
+ class Infra < Base
11
+ desc "update", "Pull infra services updates"
12
+ method_option :help, aliases: "-h", type: :boolean,
13
+ desc: "Display usage information"
14
+ method_option :name, aliases: "-n", type: :array, default: [],
15
+ desc: "Update infra service, all if empty"
16
+ def update
17
+ if options[:help]
18
+ invoke :help, ["update"]
19
+ else
20
+ lookup_services(options[:name]).each do |service|
21
+ Commands::Infra::Update.new(service: service).execute
22
+ end
23
+ end
24
+ end
25
+
26
+ desc "up", "Run infra services"
27
+ method_option :help, aliases: "-h", type: :boolean,
28
+ desc: "Display usage information"
29
+ method_option :name, aliases: "-n", type: :array, default: [],
30
+ desc: "Start specific infra service, all if empty"
31
+ method_option :update, type: :boolean, default: true,
32
+ desc: "Pull infra services updates"
33
+ def up(*compose_argv)
34
+ if options[:help]
35
+ invoke :help, ["up"]
36
+ else
37
+ lookup_services(options[:name]).each do |service|
38
+ if options[:update]
39
+ Commands::Infra::Update.new(service: service).execute
40
+ end
41
+
42
+ Commands::Infra::Up.new(*compose_argv, service: service).execute
43
+ end
44
+ end
45
+ end
46
+
47
+ desc "down", "Stop infra services"
48
+ method_option :help, aliases: "-h", type: :boolean,
49
+ desc: "Display usage information"
50
+ method_option :name, aliases: "-n", type: :array, default: [],
51
+ desc: "Stop specific infra service, all if empty"
52
+ def down(*compose_argv)
53
+ if options[:help]
54
+ invoke :help, ["down"]
55
+ else
56
+ lookup_services(options[:name]).each do |service|
57
+ Commands::Infra::Down.new(*compose_argv, service: service).execute
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def lookup_services(names)
65
+ names = Array(names).map(&:to_sym)
66
+
67
+ Dip.config.infra.each_with_object([]) do |(name, params), memo|
68
+ next if !names.empty? && !names.include?(name)
69
+ memo << Commands::Infra::Service.new(name, **params)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
data/lib/dip/cli.rb CHANGED
@@ -5,7 +5,7 @@ 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
8
+ TOP_LEVEL_COMMANDS = %w[help version ls compose up stop down run provision ssh infra console].freeze
9
9
 
10
10
  class << self
11
11
  # Hackery. Take the run method away from Thor so that we can redefine it.
@@ -47,30 +47,30 @@ module Dip
47
47
  Dip::Commands::List.new.execute
48
48
  end
49
49
 
50
- desc "compose CMD [OPTIONS]", "Run docker-compose commands"
50
+ desc "compose CMD [OPTIONS]", "Run Docker Compose commands"
51
51
  def compose(*argv)
52
52
  require_relative "commands/compose"
53
53
  Dip::Commands::Compose.new(*argv).execute
54
54
  end
55
55
 
56
- desc "build [OPTIONS] SERVICE", "Run `docker-compose build` command"
56
+ desc "build [OPTIONS] SERVICE", "Run `docker compose build` command"
57
57
  def build(*argv)
58
58
  compose("build", *argv)
59
59
  end
60
60
 
61
- desc "up [OPTIONS] SERVICE", "Run `docker-compose up` command"
61
+ desc "up [OPTIONS] SERVICE", "Run `docker compose up` command"
62
62
  def up(*argv)
63
63
  compose("up", *argv)
64
64
  end
65
65
 
66
- desc "stop [OPTIONS] SERVICE", "Run `docker-compose stop` command"
66
+ desc "stop [OPTIONS] SERVICE", "Run `docker compose stop` command"
67
67
  def stop(*argv)
68
68
  compose("stop", *argv)
69
69
  end
70
70
 
71
- desc "down [OPTIONS]", "Run `docker-compose down` command"
71
+ desc "down [OPTIONS]", "Run `docker compose down` command"
72
72
  method_option :help, aliases: "-h", type: :boolean, desc: "Display usage information"
73
- method_option :all, aliases: "-A", type: :boolean, desc: "Shutdown all running docker-compose projects"
73
+ method_option :all, aliases: "-A", type: :boolean, desc: "Shutdown all running Docker Compose projects"
74
74
  def down(*argv)
75
75
  if options[:help]
76
76
  invoke :help, ["down"]
@@ -121,13 +121,9 @@ module Dip
121
121
  desc "ssh", "ssh-agent container commands"
122
122
  subcommand :ssh, Dip::CLI::SSH
123
123
 
124
- require_relative "cli/dns"
125
- desc "dns", "DNS server for automatic docker container discovery"
126
- subcommand :dns, Dip::CLI::DNS
127
-
128
- require_relative "cli/nginx"
129
- desc "nginx", "Nginx reverse proxy server"
130
- subcommand :nginx, Dip::CLI::Nginx
124
+ require_relative "cli/infra"
125
+ desc "infra", "Infrastructure services"
126
+ subcommand :infra, Dip::CLI::Infra
131
127
 
132
128
  require_relative "cli/console"
133
129
  desc "console", "Integrate Dip commands into shell (only ZSH and Bash are supported)"
@@ -21,15 +21,15 @@ module Dip
21
21
  def execute
22
22
  Dip.env["DIP_DNS"] ||= find_dns
23
23
 
24
+ set_infra_env
25
+
24
26
  compose_argv = Array(find_files) + Array(cli_options) + argv
25
27
 
26
28
  if (override_command = compose_command_override)
27
29
  override_command, *override_args = override_command.split(" ")
28
30
  exec_program(override_command, override_args.concat(compose_argv), shell: shell)
29
- elsif compose_v2?
30
- exec_program("docker", compose_argv.unshift("compose"), shell: shell)
31
31
  else
32
- exec_program("docker-compose", compose_argv, shell: shell)
32
+ exec_program("docker", compose_argv.unshift("compose"), shell: shell)
33
33
  end
34
34
  end
35
35
 
@@ -76,17 +76,16 @@ module Dip
76
76
  end
77
77
  end
78
78
 
79
- def compose_v2?
80
- if %w[false no 0].include?(Dip.env["DIP_COMPOSE_V2"]) || Dip.test?
81
- return false
82
- end
83
-
84
- !!exec_subprocess("docker", "compose version", panic: false, out: File::NULL, err: File::NULL)
85
- end
86
-
87
79
  def compose_command_override
88
80
  Dip.env["DIP_COMPOSE_COMMAND"] || config[:command]
89
81
  end
82
+
83
+ def set_infra_env
84
+ Dip.config.infra.each do |name, params|
85
+ service = Commands::Infra::Service.new(name, **params)
86
+ Dip.env[service.network_env_var] = service.network_name
87
+ end
88
+ end
90
89
  end
91
90
  end
92
91
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Dip
6
+ module Commands
7
+ module Infra
8
+ class Service
9
+ attr_reader :name, :git, :ref, :location, :project_name, :network_name, :network_env_var
10
+
11
+ def initialize(name, git: nil, ref: nil, path: nil)
12
+ if git.nil? && path.nil?
13
+ raise ArgumentError, "Infra service `#{name}` configuration error: git or path must be defined"
14
+ end
15
+
16
+ @name = name
17
+ @git = git
18
+ @ref = ref || "latest"
19
+ @location = if git
20
+ "#{Dip.home_path}/infra/#{@name}/#{@ref}"
21
+ else
22
+ File.expand_path(path)
23
+ end
24
+ @project_name = "dip-infra-#{name}-#{@ref}"
25
+ @network_name = "dip-net-#{name}-#{@ref}"
26
+ @network_env_var = "DIP_INFRA_NETWORK_#{@name.to_s.upcase.tr("-", "_")}"
27
+ end
28
+
29
+ def env
30
+ {
31
+ "COMPOSE_PROJECT_NAME" => project_name,
32
+ "DIP_INFRA_NETWORK_NAME" => network_name
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "shellwords"
4
+ require "fileutils"
5
+ require_relative "../command"
6
+
7
+ module Dip
8
+ module Commands
9
+ module Infra
10
+ class Update < Dip::Command
11
+ def initialize(service:)
12
+ @service = service
13
+ end
14
+
15
+ def execute
16
+ return unless @service.git
17
+
18
+ if Dir.exist?(@service.location)
19
+ pull
20
+ else
21
+ clone
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def pull
28
+ Dir.chdir(@service.location) do
29
+ exec_subprocess("git", "checkout .")
30
+ exec_subprocess("git", "pull --rebase")
31
+ end
32
+ end
33
+
34
+ def clone
35
+ FileUtils.mkdir_p(@service.location)
36
+
37
+ Dir.chdir(@service.location) do
38
+ args = [
39
+ "clone",
40
+ "--single-branch",
41
+ "--depth 1",
42
+ "--branch #{Shellwords.escape(@service.ref)}",
43
+ Shellwords.escape(@service.git),
44
+ Shellwords.escape(@service.location)
45
+ ]
46
+ exec_subprocess("git", args)
47
+ end
48
+ end
49
+ end
50
+
51
+ class Up < Dip::Command
52
+ def initialize(*compose_argv, service:)
53
+ @compose_argv = compose_argv.compact
54
+ @service = service
55
+ end
56
+
57
+ def execute
58
+ Dir.chdir(@service.location) do
59
+ exec_subprocess("docker", "network create #{@service.network_name}", panic: false, err: File::NULL)
60
+
61
+ argv = %w[compose up --detach] + @compose_argv
62
+ exec_subprocess("docker", argv, env: @service.env)
63
+ end
64
+ end
65
+ end
66
+
67
+ class Down < Dip::Command
68
+ def initialize(*compose_argv, service:)
69
+ @compose_argv = compose_argv.compact
70
+ @service = service
71
+ end
72
+
73
+ def execute
74
+ Dir.chdir(@service.location) do
75
+ argv = %w[compose down] + @compose_argv
76
+ exec_subprocess("docker", argv, env: @service.env)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -71,7 +71,7 @@ module Dip
71
71
 
72
72
  def update_command_for_profiles
73
73
  # NOTE: When using profiles, the method is always `up`.
74
- # This is because `docker-compose` does not support profiles
74
+ # This is because `docker compose` does not support profiles
75
75
  # for other commands. Also, run options need to be removed
76
76
  # because they are not supported by `up`.
77
77
  command[:compose][:method] = "up"
data/lib/dip/config.rb CHANGED
@@ -17,10 +17,13 @@ module Dip
17
17
  environment: {},
18
18
  compose: {},
19
19
  kubectl: {},
20
+ infra: {},
20
21
  interaction: {},
21
22
  provision: []
22
23
  }.freeze
23
24
 
25
+ TOP_LEVEL_KEYS = %i[environment compose kubectl infra interaction provision].freeze
26
+
24
27
  ConfigKeyMissingError = Class.new(ArgumentError)
25
28
 
26
29
  class ConfigFinder
@@ -95,7 +98,7 @@ module Dip
95
98
  config
96
99
  end
97
100
 
98
- %i[environment compose kubectl interaction provision].each do |key|
101
+ TOP_LEVEL_KEYS.each do |key|
99
102
  define_method(key) do
100
103
  config[key] || (raise config_missing_error(key))
101
104
  end
data/lib/dip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dip
4
- VERSION = "7.8.0"
4
+ VERSION = "8.0.0"
5
5
  end
data/lib/dip.rb CHANGED
@@ -18,6 +18,10 @@ module Dip
18
18
  $PROGRAM_NAME.start_with?("./") ? File.expand_path($PROGRAM_NAME) : "dip"
19
19
  end
20
20
 
21
+ def home_path
22
+ @home_path ||= File.expand_path(ENV.fetch("DIP_HOME", "~/.dip"))
23
+ end
24
+
21
25
  %w[test debug].each do |key|
22
26
  define_method("#{key}?") do
23
27
  ENV["DIP_ENV"] == key
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dip
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.8.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bibendi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-28 00:00:00.000000000 Z
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -156,8 +156,22 @@ dependencies:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
158
  version: '3'
159
+ - !ruby/object:Gem::Dependency
160
+ name: fakefs
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
159
173
  description: DIP - Docker Interaction Process.CLI tool for better development experience
160
- when interacting with docker and docker-compose.
174
+ when interacting with docker and Docker Compose.
161
175
  email:
162
176
  - merkushin.m.s@gmail.com
163
177
  executables:
@@ -173,16 +187,17 @@ files:
173
187
  - lib/dip/cli/base.rb
174
188
  - lib/dip/cli/console.rb
175
189
  - lib/dip/cli/dns.rb
176
- - lib/dip/cli/nginx.rb
190
+ - lib/dip/cli/infra.rb
177
191
  - lib/dip/cli/ssh.rb
178
192
  - lib/dip/command.rb
179
193
  - lib/dip/commands/compose.rb
180
194
  - lib/dip/commands/console.rb
181
195
  - lib/dip/commands/dns.rb
182
196
  - lib/dip/commands/down_all.rb
197
+ - lib/dip/commands/infra.rb
198
+ - lib/dip/commands/infra/service.rb
183
199
  - lib/dip/commands/kubectl.rb
184
200
  - lib/dip/commands/list.rb
185
- - lib/dip/commands/nginx.rb
186
201
  - lib/dip/commands/provision.rb
187
202
  - lib/dip/commands/run.rb
188
203
  - lib/dip/commands/runners/base.rb
@@ -220,5 +235,5 @@ requirements: []
220
235
  rubygems_version: 3.2.32
221
236
  signing_key:
222
237
  specification_version: 4
223
- summary: Ruby gem CLI tool for better interacting docker-compose files.
238
+ summary: Ruby gem CLI tool for better interacting Docker Compose files.
224
239
  test_files: []
data/lib/dip/cli/nginx.rb DELETED
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor"
4
- require_relative "base"
5
- require_relative "../commands/nginx"
6
-
7
- module Dip
8
- class CLI
9
- # See more https://github.com/nginx-proxy/nginx-proxy
10
- class Nginx < Base
11
- desc "up", "Run nginx container"
12
- method_option :help, aliases: "-h", type: :boolean,
13
- desc: "Display usage information"
14
- method_option :name, aliases: "-n", type: :string, default: "nginx",
15
- desc: "Container name"
16
- method_option :socket, aliases: "-s", type: :string, default: "/var/run/docker.sock",
17
- desc: "Path to docker socket"
18
- method_option :net, aliases: "-t", type: :string, default: "frontend",
19
- desc: "Container network name"
20
- method_option :publish, aliases: "-p", type: :array, default: ["80:80"],
21
- desc: "Container port(s). For more than one port, separate them by a space"
22
- method_option :image, aliases: "-i", type: :string, default: "nginxproxy/nginx-proxy:latest",
23
- desc: "Docker image name"
24
- method_option :domain, aliases: "-d", type: :string, default: "docker",
25
- desc: "Top level domain"
26
- method_option :certs, aliases: "-c", type: :string, desc: "Path to ssl certificates"
27
- def up
28
- if options[:help]
29
- invoke :help, ["up"]
30
- else
31
- Dip::Commands::Nginx::Up.new(
32
- name: options.fetch(:name),
33
- socket: options.fetch(:socket),
34
- net: options.fetch(:net),
35
- publish: options.fetch(:publish),
36
- image: options.fetch(:image),
37
- domain: options.fetch(:domain),
38
- certs: options[:certs]
39
- ).execute
40
- end
41
- end
42
-
43
- desc "down", "Stop nginx container"
44
- method_option :help, aliases: "-h", type: :boolean,
45
- desc: "Display usage information"
46
- method_option :name, aliases: "-n", type: :string, default: "nginx",
47
- desc: "Container name"
48
- def down
49
- if options[:help]
50
- invoke :help, ["down"]
51
- else
52
- Dip::Commands::Nginx::Down.new(
53
- name: options.fetch(:name)
54
- ).execute
55
- end
56
- end
57
-
58
- desc "restart", "Stop and start nginx container"
59
- method_option :help, aliases: "-h", type: :boolean,
60
- desc: "Display usage information"
61
- def restart(*args)
62
- if options[:help]
63
- invoke :help, ["restart"]
64
- else
65
- Dip::CLI::Nginx.start(["down"] + args)
66
- sleep 1
67
- Dip::CLI::Nginx.start(["up"] + args)
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "shellwords"
4
- require_relative "../command"
5
-
6
- module Dip
7
- module Commands
8
- module Nginx
9
- class Up < Dip::Command
10
- def initialize(name:, socket:, net:, publish:, image:, domain:, certs:)
11
- @name = name
12
- @socket = socket
13
- @net = net
14
- @publish = publish
15
- @image = image
16
- @domain = domain
17
- @certs = certs
18
- end
19
-
20
- def execute
21
- exec_subprocess("docker", "network create #{@net}", panic: false, err: File::NULL)
22
- exec_subprocess("docker", "run #{container_args} #{@image}")
23
- end
24
-
25
- private
26
-
27
- def container_args
28
- result = %w[--detach]
29
- result << "--volume #{@socket}:/tmp/docker.sock:ro"
30
- result << "--volume #{@certs}:/etc/nginx/certs" unless @certs.to_s.empty?
31
- result << "--restart always"
32
- result << Array(@publish).map { |p| "--publish #{p}" }.join(" ")
33
- result << "--net #{@net}"
34
- result << "--name #{@name}"
35
- result << "--label com.dnsdock.alias=#{@domain}"
36
- result.join(" ")
37
- end
38
- end
39
-
40
- class Down < Dip::Command
41
- def initialize(name:)
42
- @name = name
43
- end
44
-
45
- def execute
46
- exec_subprocess("docker", "stop #{@name}", panic: false, out: File::NULL, err: File::NULL)
47
- exec_subprocess("docker", "rm -v #{@name}", panic: false, out: File::NULL, err: File::NULL)
48
- end
49
- end
50
- end
51
- end
52
- end