devup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e885b9167bbbc4432a625936f195ac3e32b22f64a4e66d9550601842e03acf27
4
+ data.tar.gz: 7fb6a19655af1d35d74d8a83e6e1a9e223eb7a64c66e74b46d6ff76167149a61
5
+ SHA512:
6
+ metadata.gz: c29cd7e9dc282abe8e0214e979a1a2e2e166a1ffa525a51b6a9bb9fefcc51d2ddf6888d95c43801f39b8a670aaac929c5bee884490c6f4eb18f7d8a2c47d33d1
7
+ data.tar.gz: 4fa1e807c42c4173bd0c1f3b8f8057e8eba280257927263ac3d5240a6b348fcae1b83136ff001d925ba463670a5d28887a6c90169bf8878546e00d9e09458100
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.byebug_history
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # Editor config
15
+ .vimrc
16
+
17
+ spec/dummy/.env.services
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ ruby-2.7.1
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.7.1
5
+ services:
6
+ - docker
7
+ env:
8
+ - BUNDLER_VERSION=2.1.4
9
+ before_install:
10
+ - gem install bundler -v $BUNDLER_VERSION
11
+ deploy:
12
+ provider: rubygems
13
+ api_key:
14
+ secure: iW1wt+qHBevHwDXPugjmkDAtmKDTAQMuC7NCg7Sipvj+bw6u34mbGuiab+3rNcsVr9njrveZTDSZ1gScYIowQTM7v/aw/AzOsHhfNFhQzGgOvllDn48yaFa83P9Jlv4pJ3MQjaPSj7hCWAiD9ysvcwlFl24TcllkxGzXvBsjW5EIkzBPLv5SliXi5rqRCplVW4DPQwWlcEJoMSsgNIJ9ztnRqdl7qIYoQrHebCIoy561pZMH/5jqRg6SD6EH8bDRXMXx690+HoeXfgZkiRH1DJuJv1M0YHtKnxM7yUCn78VQyEBSGICn8j8JP4hmvCqQrXl3hq7X2vH/ffHpDFSfG92Xi+SJwXxPY0zy+oSP3i5lpa+2goLpN1c0LcLFMLU3W10awyAwzv8EMq1ToZlbQ1qnBDydWBvpl4NB/TmMQopZYXgwRoWORhjod8ZzaTapewjwx4CJCim0QZXDxMuF1Uzdn+Jt+LEf/HGto0Txl4vMAwSqUfwDgr+f3m5s8airxhgpzGPWPEwH+DpV/GtI33U45iUHCXZwWRopizKf4pBkIUSLKSAC6RY+54qVJBPkz1jplKy83Oj5W8I6XBYdGSWJGrNhWEDsd8t7g2kaw0gUSEz1NbiJRv/JsdMuH6OwOSQoJPU2UW+7N60Eyu0UpqttkI3tclSqmtuNTJCnSS0=
15
+ on:
16
+ tags: true
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sergei.udalov@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in devup.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "standard"
9
+ gem "simplecov", require: false
10
+ gem "byebug"
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devup (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ byebug (11.1.3)
11
+ diff-lcs (1.3)
12
+ docile (1.3.2)
13
+ jaro_winkler (1.5.4)
14
+ json (2.3.0)
15
+ parallel (1.19.1)
16
+ parser (2.7.1.0)
17
+ ast (~> 2.4.0)
18
+ rainbow (3.0.0)
19
+ rake (12.3.3)
20
+ rexml (3.1.9)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.2)
26
+ rspec-support (~> 3.9.3)
27
+ rspec-expectations (3.9.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.3)
34
+ rubocop (0.80.1)
35
+ jaro_winkler (~> 1.5.1)
36
+ parallel (~> 1.10)
37
+ parser (>= 2.7.0.1)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ rexml
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 1.7)
42
+ rubocop-performance (1.5.2)
43
+ rubocop (>= 0.71.0)
44
+ ruby-progressbar (1.10.1)
45
+ simplecov (0.17.1)
46
+ docile (~> 1.1)
47
+ json (>= 1.8, < 3)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.2)
50
+ standard (0.2.4)
51
+ rubocop (~> 0.80.1)
52
+ rubocop-performance (~> 1.5.2)
53
+ unicode-display_width (1.6.1)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ byebug
60
+ devup!
61
+ rake (~> 12.0)
62
+ rspec (~> 3.0)
63
+ simplecov
64
+ standard
65
+
66
+ BUNDLED WITH
67
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Sergei O. Udalov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Devup
2
+
3
+ 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/devup`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'devup'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install devup
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sergio-fry/devup. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sergio-fry/devup/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Devup project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sergio-fry/devup/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "devup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require_relative "lib/devup/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "devup"
5
+
6
+ spec.version = Devup::VERSION
7
+ spec.version = "#{spec.version}-alpha-#{ENV["TRAVIS_BUILD_NUMBER"]}" if ENV["TRAVIS"]
8
+
9
+ spec.authors = ["Sergei O. Udalov"]
10
+ spec.email = ["sergei@udalovs.ru"]
11
+
12
+ spec.summary = "A tool to manage docker-compose for developmnet"
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/sergio-fry/devup"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
17
+
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "devup"
4
+
5
+ devup = Devup::Environment.new pwd: `pwd`
6
+
7
+ # TODO: use dry-cli here
8
+ case ARGV[0]
9
+ when "down"
10
+ devup.down
11
+ else
12
+ devup.up
13
+ end
@@ -0,0 +1,11 @@
1
+ require "devup/version"
2
+ require "devup/environment"
3
+
4
+ module Devup
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+
8
+ def self.root
9
+ Pathname.new File.dirname(__dir__)
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ require "yaml"
2
+
3
+ module Devup
4
+ class Compose
5
+ attr_reader :path, :project
6
+
7
+ def initialize(path, project: "devup")
8
+ @path = path
9
+ @project = project
10
+ end
11
+
12
+ def services
13
+ config["services"].keys
14
+ end
15
+
16
+ def service_ports(name)
17
+ config["services"][name]["ports"]
18
+ end
19
+
20
+ def up
21
+ exec "up -d --remove-orphans"
22
+ end
23
+
24
+ def stop
25
+ exec "stop"
26
+ end
27
+
28
+ def rm
29
+ exec "rm -f"
30
+ end
31
+
32
+ def exec(cmd)
33
+ `docker-compose -p #{project} -f #{path} #{cmd}`
34
+ end
35
+
36
+ private
37
+
38
+ def config
39
+ YAML.safe_load(config_content)
40
+ end
41
+
42
+ def config_content
43
+ File.read(path)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ require "yaml"
2
+
3
+ require "devup/compose"
4
+ require "devup/service"
5
+
6
+ module Devup
7
+ class Environment
8
+ attr_reader :pwd, :compose
9
+
10
+ def initialize(pwd:, compose: nil)
11
+ @pwd = pwd.to_s.strip
12
+ @compose = compose || Compose.new(root.join("docker-compose.yml"), project: project)
13
+ end
14
+
15
+ def project
16
+ pwd.split("/")[-1].strip
17
+ end
18
+
19
+ def vars
20
+ compose.services.map { |name| Service.new(compose, name) }.map { |service|
21
+ res = []
22
+
23
+ res << {"#{service.name}_HOST".upcase => "0.0.0.0"}
24
+
25
+ if service.ports.size > 0
26
+ res << {"#{service.name}_PORT".upcase => service.ports.first.to}
27
+
28
+ service.ports.each do |port|
29
+ res << {"#{service.name}_PORT_#{port.from}".upcase => port.to}
30
+ end
31
+ end
32
+
33
+ res
34
+ }.flatten
35
+ end
36
+
37
+ def up
38
+ compose.up
39
+ write_dotenv
40
+ end
41
+
42
+ def down
43
+ compose.stop
44
+ compose.rm
45
+ clear_dotenv
46
+ end
47
+
48
+ def root
49
+ Pathname.new pwd
50
+ end
51
+
52
+ private
53
+
54
+ def write_dotenv
55
+ File.open(root.join(".env.services"), "w") { |f| f.write dotenv }
56
+ end
57
+
58
+ def clear_dotenv
59
+ File.open(root.join(".env.services"), "w") { |f| f.write "" }
60
+ end
61
+
62
+ def dotenv
63
+ vars.reduce({}, :merge).map { |k, v| "#{k}=#{v}" }.join("\n")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,21 @@
1
+ require "ostruct"
2
+
3
+ module Devup
4
+ class Service
5
+ attr_reader :compose, :name
6
+
7
+ def initialize(compose, name)
8
+ @compose = compose
9
+ @name = name
10
+ end
11
+
12
+ def ports
13
+ compose.service_ports(name).map { |el| el.to_s.split(":")[-1] }.map do |from|
14
+ OpenStruct.new(
15
+ from: from,
16
+ to: compose.exec("port #{name} #{from}").split(":")[-1].strip
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Devup
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergei O. Udalov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - sergei@udalovs.ru
16
+ executables:
17
+ - devup
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".ruby-version"
24
+ - ".travis.yml"
25
+ - ".vimrc"
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - bin/console
33
+ - bin/setup
34
+ - devup.gemspec
35
+ - exe/devup
36
+ - lib/devup.rb
37
+ - lib/devup/compose.rb
38
+ - lib/devup/environment.rb
39
+ - lib/devup/service.rb
40
+ - lib/devup/version.rb
41
+ homepage: https://github.com/sergio-fry/devup
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://github.com/sergio-fry/devup
46
+ source_code_uri: https://github.com/sergio-fry/devup
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.1.2
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: A tool to manage docker-compose for developmnet
66
+ test_files: []