dockdev 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5b6df05dd817ea0242093d22aefcfb2abf7ffce458eb096f2a95b08beeece48
4
+ data.tar.gz: f6a396ac3028121f65f8cb14213856d328af4b4da871f6e642dafb5ad9b3d049
5
+ SHA512:
6
+ metadata.gz: e8f5c9eaa0b9bdef3bc8f9a9c2dc27416947200be9ae66c60f66b683e527af4652c523c3d928d83c05ce21f36504620662bde7094c35b4e6f6b925748404445a
7
+ data.tar.gz: 67c4b265a8c47afa0d5003f3412ece1789c1376c140e2040932409490e59aed6c0d571dd1d3d6da605f689220e676902fca5b8735b7d5faed055b6e60a3ab81b
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ DisabledByDefault: true
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Dockdev
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dockdev`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dockdev.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
9
+ require 'release/gem'
data/exe/dockdev ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # end result is there is one container created and
4
+ # start will always go into that container until it is
5
+ # destroy
6
+ # Taking the vagrant model
7
+
8
+ require_relative '../lib/dockdev'
9
+
10
+ contName = ARGV.first || File.basename(Dir.getwd)
11
+ cmd = ARGV[1]
12
+
13
+ begin
14
+ Dockdev.with_running_container(contName, command: cmd, root: Dir.getwd)
15
+ rescue StandardError => ex
16
+ STDERR.puts ex.message
17
+ end
18
+
19
+
@@ -0,0 +1,55 @@
1
+
2
+ require 'docker/cli'
3
+
4
+ module Dockdev
5
+ class Container
6
+
7
+ def initialize(name)
8
+ @cont_name = name
9
+ @cmd_fact = Docker::Cli::CommandFactory.new
10
+ end
11
+
12
+ def name
13
+ @cont_name
14
+ end
15
+
16
+ def has_container?
17
+ res = @cmd_fact.find_from_all_container(@cont_name, exact_name: true).run
18
+ if res.success?
19
+ not res.is_out_stream_empty?
20
+ else
21
+ raise Error, "Command find from all container failed with error : #{res.err_stream}"
22
+ end
23
+ end
24
+
25
+ def running?
26
+ res = @cmd_fact.find_running_container(@cont_name, exact_name: true).run
27
+ if res.success?
28
+ not res.is_out_stream_empty?
29
+ else
30
+ raise Error, "Command to check is container running failed with error : #{res.err_stream}"
31
+ end
32
+ end
33
+
34
+ def attach_and_exec(opts = {})
35
+ optss = {
36
+ tty: true,
37
+ interactive: true
38
+ }
39
+ @cmd_fact.run_command_in_running_container(@cont_name, opts[:command], optss).run
40
+ end
41
+
42
+ def start_with_command(opts = {})
43
+
44
+ res = @cmd_fact.start_container(@cont_name).run
45
+ if res.success? and not res.is_out_stream_empty?
46
+ attach_and_exec(opts)
47
+ else
48
+ raise Error, "Command to start container failed with error : #{res.err_stream}"
49
+ end
50
+
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+
2
+ require 'docker/cli'
3
+
4
+ module Dockdev
5
+ class Image
6
+ include TR::CondUtils
7
+
8
+ def initialize(name)
9
+ @image_name = name
10
+ @cmd_fact = Docker::Cli::CommandFactory.new
11
+ end
12
+
13
+ def has_image?
14
+ res = @cmd_fact.find_image(@image_name).run
15
+ if res.success?
16
+ not res.is_out_stream_empty?
17
+ else
18
+ raise Error, "Error triggered during find existing image : #{res.err_stream}"
19
+ end
20
+ end
21
+
22
+ def new_container(cont_name, opts = {})
23
+ optss = {
24
+ interactive: true,
25
+ tty: true,
26
+ container_name: cont_name
27
+ }
28
+ optss.merge!(opts)
29
+ @cmd_fact.create_container_from_image(@image_name, optss).run
30
+ end
31
+
32
+ def build(dockerfile, opts = {})
33
+ optss = {
34
+ context_root: opts[:root],
35
+ dockerfile: dockerfile
36
+ }
37
+ res = @cmd_fact.build_image(@image_name, optss).run
38
+ if res.success?
39
+ new_container(opts[:container_name], opts)
40
+ else
41
+ raise Error, "Error triggered during find existing image : #{res.err_stream}"
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dockdev
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,27 @@
1
+
2
+
3
+ module Dockdev
4
+ class Workspace
5
+
6
+ def initialize(root = Dir.getwd)
7
+ @root = root
8
+ end
9
+
10
+ def name
11
+ File.dirname(@root)
12
+ end
13
+
14
+ def has_dockerfile?
15
+ Dir.glob(File.join(@root,"Dockerfile")).length > 0
16
+ end
17
+
18
+ def dockerfile
19
+ Dir.glob(File.join(@root,"Dockerfile")).first
20
+ end
21
+
22
+ def has_docker_compose?
23
+ Dir.glob(File.join(@root,"docker-compose.yml")).length > 0
24
+ end
25
+
26
+ end
27
+ end
data/lib/dockdev.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'teLogger'
4
+ require 'toolrack'
5
+ require 'docker/cli'
6
+
7
+ require_relative "dockdev/version"
8
+
9
+ require_relative 'dockdev/workspace'
10
+ require_relative 'dockdev/image'
11
+ require_relative 'dockdev/container'
12
+
13
+
14
+ module Dockdev
15
+ class Error < StandardError; end
16
+ # Your code goes here...
17
+
18
+ def self.with_running_container(contName, opts = {})
19
+
20
+ root = opts[:root]
21
+ cmd = opts[:command]
22
+ cont = Container.new(contName)
23
+ if cont.has_container?
24
+ if cont.running?
25
+ cont.attach_and_exec(command: cmd)
26
+ else
27
+ cont.start_with_command(command: cmd)
28
+ end
29
+ else
30
+ img = Image.new(contName)
31
+ ws = opts[:workspace] || Dir.getwd
32
+ wss = Workspace.new(ws)
33
+ if img.has_image?
34
+ img.new_container(cont.name, command: cmd)
35
+ elsif wss.has_dockerfile?
36
+ img.build(wss.dockerfile)
37
+ img.new_container(cont.name, command: cmd)
38
+ else
39
+ raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n"
40
+ end
41
+ end
42
+ end
43
+ end
data/sig/dockdev.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Dockdev
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dockdev
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: teLogger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: toolrack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.23'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.23'
41
+ - !ruby/object:Gem::Dependency
42
+ name: docker-cli
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: release-gem
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.3
69
+ description: ''
70
+ email:
71
+ - chris@antrapol.com
72
+ executables:
73
+ - dockdev
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - README.md
80
+ - Rakefile
81
+ - exe/dockdev
82
+ - lib/dockdev.rb
83
+ - lib/dockdev/container.rb
84
+ - lib/dockdev/image.rb
85
+ - lib/dockdev/version.rb
86
+ - lib/dockdev/workspace.rb
87
+ - sig/dockdev.rbs
88
+ homepage: ''
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.6.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: ''
110
+ test_files: []