dip 7.8.0 → 8.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -94
- data/lib/dip/cli/infra.rb +74 -0
- data/lib/dip/cli.rb +10 -14
- data/lib/dip/commands/compose.rb +10 -11
- data/lib/dip/commands/infra/service.rb +38 -0
- data/lib/dip/commands/infra.rb +82 -0
- data/lib/dip/commands/runners/docker_compose_runner.rb +1 -1
- data/lib/dip/config.rb +4 -1
- data/lib/dip/version.rb +1 -1
- data/lib/dip.rb +4 -0
- metadata +23 -8
- data/lib/dip/cli/nginx.rb +0 -72
- data/lib/dip/commands/nginx.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62ac96c33784899b925107b213950d7304f29edcf5d3d5d7787c061a63fd8502
|
4
|
+
data.tar.gz: c2d7dff0d4d8bc168e8afa55ff76e20aabda37cde9308abedfcc8de0494579d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45b7eb4d3220ce5ce109c45a3a84e5248d7a8b9aead0542c6543f005298fa31eeb93a741c9beef19b9f098b9693257fd91c6c32c910cfe1a8317503124f251cc
|
7
|
+
data.tar.gz: 0160da43d5ed98e5cae351050926fc87941317dfb55854b8e7a9f97c6f79d50e06b5a9e1db72ae41a43f65cbdf0cc0272df14ef1b10adb27024cba4b8b2e076c
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Development-environment CLI program providing the native-like interaction with a
|
|
14
14
|
## Presentations and examples
|
15
15
|
|
16
16
|
- [Local development with Docker containers](https://slides.com/bibendi/dip)
|
17
|
-
- Dockerized Ruby on Rails
|
17
|
+
- [Dockerized Ruby on Rails application](https://SberMarket-Tech/outbox-example-apps)
|
18
18
|
- Dockerized Node.js application: [one](https://github.com/bibendi/twinkle.js), [two](https://github.com/bibendi/yt-graphql-react-event-booking-api)
|
19
19
|
- [Dockerized Ruby gem](https://github.com/bibendi/schked)
|
20
20
|
- [Dockerizing Ruby and Rails development](https://evilmartians.com/chronicles/ruby-on-whales-docker-for-ruby-rails-development)
|
@@ -22,7 +22,13 @@ Development-environment CLI program providing the native-like interaction with a
|
|
22
22
|
|
23
23
|
[![asciicast](https://asciinema.org/a/210236.svg)](https://asciinema.org/a/210236)
|
24
24
|
|
25
|
-
##
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
```sh
|
28
|
+
gem install dip
|
29
|
+
```
|
30
|
+
|
31
|
+
### Integration with shell
|
26
32
|
|
27
33
|
Dip can be injected into the current shell (ZSH or Bash).
|
28
34
|
|
@@ -53,14 +59,6 @@ VERSION=20180515103400 rails db:migrate:down
|
|
53
59
|
You could add this `eval` at the end of your `~/.zshrc`, or `~/.bashrc`, or `~/.bash_profile`.
|
54
60
|
After that, it will be automatically applied when you open your preferred terminal.
|
55
61
|
|
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
62
|
## Usage
|
65
63
|
|
66
64
|
```sh
|
@@ -242,19 +240,16 @@ services:
|
|
242
240
|
|
243
241
|
The container will run using the same user ID as your host machine.
|
244
242
|
|
245
|
-
|
246
243
|
### dip run
|
247
244
|
|
248
245
|
Run commands defined within the `interaction` section of dip.yml
|
249
246
|
|
250
247
|
A command will be executed by specified runner. Dip has three types of them:
|
251
248
|
|
252
|
-
- `docker
|
249
|
+
- `docker compose` runner — used when the `service` option is defined.
|
253
250
|
- `kubectl` runner — used when the `pod` option is defined.
|
254
251
|
- `local` runner — used when the previous ones are not defined.
|
255
252
|
|
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
253
|
```sh
|
259
254
|
dip run rails c
|
260
255
|
dip run rake db:migrate
|
@@ -306,7 +301,7 @@ Run commands each by each from `provision` section of dip.yml
|
|
306
301
|
|
307
302
|
### dip compose
|
308
303
|
|
309
|
-
Run
|
304
|
+
Run Docker Compose commands that are configured according to the application's dip.yml:
|
310
305
|
|
311
306
|
```sh
|
312
307
|
dip compose COMMAND [OPTIONS]
|
@@ -314,6 +309,35 @@ dip compose COMMAND [OPTIONS]
|
|
314
309
|
dip compose up -d redis
|
315
310
|
```
|
316
311
|
|
312
|
+
### dip infra
|
313
|
+
|
314
|
+
Runs shared Docker Compose services that are used by the current application. Useful for microservices.
|
315
|
+
|
316
|
+
There are several official infrastructure services available:
|
317
|
+
- [dip-postgres](https://github.com/bibendi/dip-postgres)
|
318
|
+
- [dip-kafka](https://github.com/bibendi/dip-kafka)
|
319
|
+
- [dip-nginx](https://github.com/bibendi/dip-nginx)
|
320
|
+
|
321
|
+
```yaml
|
322
|
+
# dip.yml
|
323
|
+
infra:
|
324
|
+
foo:
|
325
|
+
git: https://github.com/owner/foo.git
|
326
|
+
ref: latest # default, optional
|
327
|
+
bar:
|
328
|
+
path: ~/path/to/bar
|
329
|
+
```
|
330
|
+
|
331
|
+
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`.
|
332
|
+
|
333
|
+
Available CLI commands:
|
334
|
+
|
335
|
+
- `dip infra update` pulls updates from sources
|
336
|
+
- `dip infra up` starts all infra services
|
337
|
+
- `dip infra up -n kafka` starts a specific infra service
|
338
|
+
- `dip infra down` stops all infra services
|
339
|
+
- `dip infra down -n kafka` stops a specific infra service
|
340
|
+
|
317
341
|
### dip ktl
|
318
342
|
|
319
343
|
Run kubectl commands that are configured according to the application's dip.yml:
|
@@ -358,88 +382,10 @@ dip ssh up -u 1000
|
|
358
382
|
|
359
383
|
This especially helpful if you have something like this in your docker-compose.yml:
|
360
384
|
|
361
|
-
```
|
385
|
+
```yml
|
362
386
|
services:
|
363
387
|
web:
|
364
388
|
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
389
|
```
|
444
390
|
|
445
391
|
## 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
|
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
|
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
|
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
|
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
|
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
|
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
|
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/
|
125
|
-
desc "
|
126
|
-
subcommand :
|
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)"
|
data/lib/dip/commands/compose.rb
CHANGED
@@ -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
|
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
|
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
|
-
|
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
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:
|
4
|
+
version: 8.0.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bibendi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-07 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
|
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/
|
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
|
@@ -213,12 +228,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
228
|
version: '2.7'
|
214
229
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
230
|
requirements:
|
216
|
-
- - "
|
231
|
+
- - ">"
|
217
232
|
- !ruby/object:Gem::Version
|
218
|
-
version:
|
233
|
+
version: 1.3.1
|
219
234
|
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
|
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
|
data/lib/dip/commands/nginx.rb
DELETED
@@ -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
|