djin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Dockerfile +41 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +87 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/djin.gemspec +35 -0
- data/djin.yml +7 -0
- data/docker-compose.yml +6 -0
- data/examples/djin.yml +27 -0
- data/exe/djin +7 -0
- data/lib/djin.rb +36 -0
- data/lib/djin/cli.rb +21 -0
- data/lib/djin/entities/task.rb +14 -0
- data/lib/djin/entities/types.rb +5 -0
- data/lib/djin/executor.rb +16 -0
- data/lib/djin/extensions/custom_predicates.rb +18 -0
- data/lib/djin/extensions/hash_extensions.rb +9 -0
- data/lib/djin/interpreter.rb +81 -0
- data/lib/djin/task_contract.rb +75 -0
- data/lib/djin/version.rb +3 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43fa5ed070cc953adb7ad4864322e97cf8ef59d9fc514d65d2a4f8800a3f1a0a
|
4
|
+
data.tar.gz: 0ade4fdef165250abfbb8c80f46d6f67ec89eb7a2f60482402f5b0609ee12425
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7d80c7af51b9ce35249c5b57d2820947d43d5872a9ef59d619e47969dabfb1b0055888b650be5e7ea15444786eebe7d518543db0f180c0afe568992a162af64
|
7
|
+
data.tar.gz: 2968f433099a2df4b4449b45f2a94dfa889976e1bdb17dc96ebcca0c8c52f7b099426f5d0bdbac0921b4527bc96e8d0c0a29edf0b14c92d2921e44debff2a832
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
FROM ruby:2.6.5-alpine AS builder
|
2
|
+
|
3
|
+
ENV BUILD_PACKAGES build-base git
|
4
|
+
|
5
|
+
RUN mkdir /bundle
|
6
|
+
|
7
|
+
RUN apk update && \
|
8
|
+
apk upgrade && \
|
9
|
+
apk add $BUILD_PACKAGES && \
|
10
|
+
rm -rf /var/cache/apk/*
|
11
|
+
|
12
|
+
COPY djin.gemspec Gemfile Gemfile.lock ./
|
13
|
+
|
14
|
+
COPY lib/djin/version.rb lib/djin/version.rb
|
15
|
+
|
16
|
+
RUN gem install bundler -v 2.0.2
|
17
|
+
|
18
|
+
RUN bundle install
|
19
|
+
|
20
|
+
FROM ruby:2.6.5-alpine
|
21
|
+
|
22
|
+
WORKDIR /usr/src/djin
|
23
|
+
|
24
|
+
COPY --from=builder /usr/local/bundle/ /usr/local/bundle
|
25
|
+
|
26
|
+
RUN gem install bundler -v 2.0.2
|
27
|
+
|
28
|
+
ENV DEPENDENCIES git
|
29
|
+
|
30
|
+
RUN apk update && \
|
31
|
+
apk upgrade && \
|
32
|
+
apk add $DEPENDENCIES && \
|
33
|
+
rm -rf /var/cache/apk/*
|
34
|
+
|
35
|
+
COPY . .
|
36
|
+
|
37
|
+
RUN rake install
|
38
|
+
|
39
|
+
WORKDIR /usr/src/project
|
40
|
+
|
41
|
+
ENTRYPOINT ["/usr/src/verto/docker-entrypoint.sh"]
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
djin (0.1.0)
|
5
|
+
dry-cli (~> 0.5.0)
|
6
|
+
dry-struct (~> 1.3.0)
|
7
|
+
dry-validation (~> 1.4.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
byebug (11.1.1)
|
13
|
+
concurrent-ruby (1.1.6)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
dry-cli (0.5.1)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
dry-configurable (0.11.3)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
dry-core (~> 0.4, >= 0.4.7)
|
20
|
+
dry-equalizer (~> 0.2)
|
21
|
+
dry-container (0.7.2)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
24
|
+
dry-core (0.4.9)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
dry-equalizer (0.3.0)
|
27
|
+
dry-inflector (0.2.0)
|
28
|
+
dry-initializer (3.0.3)
|
29
|
+
dry-logic (1.0.6)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
dry-core (~> 0.2)
|
32
|
+
dry-equalizer (~> 0.2)
|
33
|
+
dry-schema (1.4.3)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
dry-configurable (~> 0.8, >= 0.8.3)
|
36
|
+
dry-core (~> 0.4)
|
37
|
+
dry-equalizer (~> 0.2)
|
38
|
+
dry-initializer (~> 3.0)
|
39
|
+
dry-logic (~> 1.0)
|
40
|
+
dry-types (~> 1.2)
|
41
|
+
dry-struct (1.3.0)
|
42
|
+
dry-core (~> 0.4, >= 0.4.4)
|
43
|
+
dry-equalizer (~> 0.3)
|
44
|
+
dry-types (~> 1.3)
|
45
|
+
ice_nine (~> 0.11)
|
46
|
+
dry-types (1.3.1)
|
47
|
+
concurrent-ruby (~> 1.0)
|
48
|
+
dry-container (~> 0.3)
|
49
|
+
dry-core (~> 0.4, >= 0.4.4)
|
50
|
+
dry-equalizer (~> 0.3)
|
51
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
52
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
53
|
+
dry-validation (1.4.2)
|
54
|
+
concurrent-ruby (~> 1.0)
|
55
|
+
dry-container (~> 0.7, >= 0.7.1)
|
56
|
+
dry-core (~> 0.4)
|
57
|
+
dry-equalizer (~> 0.2)
|
58
|
+
dry-initializer (~> 3.0)
|
59
|
+
dry-schema (~> 1.4, >= 1.4.3)
|
60
|
+
ice_nine (0.11.2)
|
61
|
+
rake (10.5.0)
|
62
|
+
rspec (3.9.0)
|
63
|
+
rspec-core (~> 3.9.0)
|
64
|
+
rspec-expectations (~> 3.9.0)
|
65
|
+
rspec-mocks (~> 3.9.0)
|
66
|
+
rspec-core (3.9.1)
|
67
|
+
rspec-support (~> 3.9.1)
|
68
|
+
rspec-expectations (3.9.0)
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
+
rspec-support (~> 3.9.0)
|
71
|
+
rspec-mocks (3.9.1)
|
72
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
+
rspec-support (~> 3.9.0)
|
74
|
+
rspec-support (3.9.2)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
ruby
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
bundler (~> 2.0)
|
81
|
+
byebug
|
82
|
+
djin!
|
83
|
+
rake (~> 10.0)
|
84
|
+
rspec (~> 3.0)
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Carlos Atkinson
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Djin
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Djin is distributed as a Ruby Gem, to install simple run:
|
6
|
+
|
7
|
+
$ gem install djin
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
To use djin first you need to create a djin.yml file:
|
12
|
+
|
13
|
+
```yaml
|
14
|
+
# With a docker image
|
15
|
+
script:
|
16
|
+
docker:
|
17
|
+
image: "ruby:2.6"
|
18
|
+
run:
|
19
|
+
commands:
|
20
|
+
- "ruby /scripts/my_ruby_script.rb"
|
21
|
+
options: "--rm -v $(pwd)/my_ruby_script.rb:/scripts/my_ruby_script.rb"
|
22
|
+
|
23
|
+
# Using a docker-compose service
|
24
|
+
test:
|
25
|
+
docker-compose:
|
26
|
+
service: app
|
27
|
+
run:
|
28
|
+
command: rspec
|
29
|
+
options: "--rm"
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
After that you can run djin {{task_name}}, like djin script or djin test
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
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.
|
38
|
+
|
39
|
+
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).
|
40
|
+
|
41
|
+
# TODO:
|
42
|
+
|
43
|
+
1. Add depends_on to run dependent tasks
|
44
|
+
2. Adds a -f option to load custom djin files
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/catks/djin.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "djin"
|
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__)
|
data/bin/setup
ADDED
data/djin.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "djin/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "djin"
|
7
|
+
spec.version = Djin::VERSION
|
8
|
+
spec.authors = ["Carlos Atkinson"]
|
9
|
+
spec.email = ["carlos.atks@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{djin is a make-like utility for docker containers}
|
12
|
+
spec.homepage = "https://github.com/catks/djin"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
#spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
17
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency "dry-struct", "~> 1.3.0"
|
29
|
+
spec.add_dependency "dry-cli", "~> 0.5.0"
|
30
|
+
spec.add_dependency "dry-validation", "~> 1.4.0"
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "byebug"
|
35
|
+
end
|
data/djin.yml
ADDED
data/docker-compose.yml
ADDED
data/examples/djin.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
default:
|
3
|
+
docker:
|
4
|
+
image: "ruby:2.5"
|
5
|
+
run:
|
6
|
+
- "ruby -e 'puts \\\" Hello\\\"'"
|
7
|
+
test:
|
8
|
+
docker-compose:
|
9
|
+
service: app
|
10
|
+
run:
|
11
|
+
command: rspec
|
12
|
+
options: "--rm"
|
13
|
+
|
14
|
+
script:
|
15
|
+
docker:
|
16
|
+
image: "ruby:2.6"
|
17
|
+
run:
|
18
|
+
commands:
|
19
|
+
- "ruby /scripts/my_ruby_script.rb"
|
20
|
+
options: "--rm -v $(pwd)/my_ruby_script.rb:/scripts/my_ruby_script.rb"
|
21
|
+
|
22
|
+
|
23
|
+
with_build:
|
24
|
+
docker:
|
25
|
+
build: .
|
26
|
+
run:
|
27
|
+
- "ruby -e 'puts \" Hello\"'"
|
data/exe/djin
ADDED
data/lib/djin.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "djin/version"
|
2
|
+
require "pathname"
|
3
|
+
require "yaml"
|
4
|
+
require "dry-struct"
|
5
|
+
require "dry-validation"
|
6
|
+
require "dry/cli"
|
7
|
+
require "djin/extensions/hash_extensions"
|
8
|
+
require "djin/extensions/custom_predicates"
|
9
|
+
require "djin/entities/types"
|
10
|
+
require "djin/entities/task"
|
11
|
+
require "djin/interpreter"
|
12
|
+
require "djin/executor"
|
13
|
+
require "djin/cli"
|
14
|
+
require "djin/task_contract"
|
15
|
+
|
16
|
+
module Djin
|
17
|
+
class Error < StandardError; end
|
18
|
+
# Your code goes here...
|
19
|
+
|
20
|
+
def self.load_tasks!(path = Pathname.getwd.join('djin.yml'))
|
21
|
+
abort 'Error: djin.yml not found' unless path.exist?
|
22
|
+
|
23
|
+
djin_file = YAML.load(path.read)
|
24
|
+
@tasks = Djin::Interpreter.load!(djin_file)
|
25
|
+
|
26
|
+
CLI.load_tasks!(@tasks)
|
27
|
+
|
28
|
+
rescue Djin::Interpreter::InvalidSyntax => ex
|
29
|
+
abort(ex.message)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.tasks
|
33
|
+
@tasks || []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/lib/djin/cli.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Djin
|
2
|
+
class CLI
|
3
|
+
extend Dry::CLI::Registry
|
4
|
+
|
5
|
+
def self.load_tasks!(tasks)
|
6
|
+
tasks.each do |task|
|
7
|
+
command = Class.new(Dry::CLI::Command) do
|
8
|
+
desc "Runs: #{task.command}"
|
9
|
+
|
10
|
+
define_method(:task) { task }
|
11
|
+
|
12
|
+
def call(**options)
|
13
|
+
Executor.new.call(task)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
register task.name, command
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Djin
|
2
|
+
class Task < Dry::Struct
|
3
|
+
attribute :name, Types::String
|
4
|
+
attribute :description, Types::String.optional.default(nil)
|
5
|
+
attribute :build_command, Types::String.optional.default(nil)
|
6
|
+
attribute :command, Types::String
|
7
|
+
|
8
|
+
def ==(other)
|
9
|
+
name == other.name &&
|
10
|
+
command == other.command &&
|
11
|
+
build_command == other.build_command
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Djin
|
2
|
+
module CustomPredicates
|
3
|
+
refine Dry::Logic::Predicates::Methods do
|
4
|
+
def is_one_of?(value, *options)
|
5
|
+
options.map do |option|
|
6
|
+
return option.call(value) if respond_to?(:call)
|
7
|
+
|
8
|
+
value.is_a?(option)
|
9
|
+
end.any?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
refine Dry::Logic::Predicates do
|
14
|
+
extend Dry::Logic::Predicates::Methods
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Djin
|
2
|
+
class Interpreter
|
3
|
+
using Djin::HashExtensions
|
4
|
+
|
5
|
+
RESERVED_WORDS = %w[_version _default_options].freeze
|
6
|
+
|
7
|
+
InvalidSyntax = Class.new(StandardError)
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def load!(params)
|
11
|
+
task_params = params.except(*RESERVED_WORDS)
|
12
|
+
contract = TaskContract.new
|
13
|
+
|
14
|
+
task_params.map do |task_name, options|
|
15
|
+
result = contract.call(options)
|
16
|
+
|
17
|
+
raise InvalidSyntax, result.errors.to_h if result.failure?
|
18
|
+
|
19
|
+
command, build_command = build_commands(options, task_name: task_name)
|
20
|
+
Djin::Task.new(name: task_name, build_command: build_command, command: command)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_commands(params, task_name:)
|
27
|
+
# Validate that only one ot the two is passed
|
28
|
+
docker_params = params['docker']
|
29
|
+
docker_compose_params = params['docker-compose']
|
30
|
+
|
31
|
+
return build_docker_commands(docker_params, task_name: task_name) if docker_params
|
32
|
+
build_docker_compose_commands(docker_compose_params) if docker_compose_params
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_docker_commands(params, task_name:)
|
36
|
+
current_folder_name = Pathname.getwd.basename.to_s
|
37
|
+
image = params['image'] || "djin_#{current_folder_name}_#{task_name}"
|
38
|
+
|
39
|
+
build_params = params['build']
|
40
|
+
|
41
|
+
if build_params.is_a?(Hash)
|
42
|
+
build_context = build_params['context']
|
43
|
+
build_options = build_params['options']
|
44
|
+
end
|
45
|
+
|
46
|
+
build_context ||= build_params
|
47
|
+
|
48
|
+
run_command, run_options = build_run_params(params['run'])
|
49
|
+
|
50
|
+
command = %Q{docker run #{run_options} #{image} sh -c "#{run_command}"}.squeeze(' ')
|
51
|
+
|
52
|
+
build_command = "docker build #{build_context} #{build_options} -t #{image}".squeeze(' ') if build_context
|
53
|
+
|
54
|
+
[command, build_command]
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_docker_compose_commands(params)
|
58
|
+
service = params['service']
|
59
|
+
|
60
|
+
compose_options = params['options']
|
61
|
+
|
62
|
+
run_command, run_options = build_run_params(params['run'])
|
63
|
+
|
64
|
+
[%Q{docker-compose #{compose_options} run #{run_options} #{service} sh -c "#{run_command}"}.squeeze(' '), nil]
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_run_params(run_params)
|
68
|
+
run_command = run_params
|
69
|
+
|
70
|
+
if run_params.is_a?(Hash)
|
71
|
+
run_command = run_params['commands']
|
72
|
+
run_options = run_params['options']
|
73
|
+
end
|
74
|
+
|
75
|
+
run_command = run_command.join(' && ') if run_command.is_a?(Array)
|
76
|
+
|
77
|
+
[run_command, run_options]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Djin
|
2
|
+
class TaskContract < Dry::Validation::Contract
|
3
|
+
NOT_EMPTY = -> (value) { ! value.empty? }
|
4
|
+
OK = -> (_) { true }
|
5
|
+
|
6
|
+
BuildSchema = Dry::Schema.Params do
|
7
|
+
required(:context).filled(:string)
|
8
|
+
required(:options).filled(:string)
|
9
|
+
end
|
10
|
+
|
11
|
+
RunSchema = Dry::Schema.Params do
|
12
|
+
required(:commands).filled
|
13
|
+
required(:options).filled(:string)
|
14
|
+
end
|
15
|
+
|
16
|
+
DockerSchema = Dry::Schema.Params do
|
17
|
+
optional(:image).maybe(:string)
|
18
|
+
optional(:build)
|
19
|
+
required(:run).filled
|
20
|
+
end
|
21
|
+
|
22
|
+
DockerComposeSchema = Dry::Schema.Params do
|
23
|
+
required(:service).filled(:string)
|
24
|
+
optional(:options).filled(:string)
|
25
|
+
required(:run).filled
|
26
|
+
end
|
27
|
+
|
28
|
+
params do
|
29
|
+
optional(:docker).filled do
|
30
|
+
hash(DockerSchema)
|
31
|
+
end
|
32
|
+
optional(:"docker-compose").filled do
|
33
|
+
hash(DockerComposeSchema)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
rule(:docker, :"docker-compose") do
|
38
|
+
key.failure('docker or docker-compose key is required') unless values[:docker] || values[:"docker-compose"]
|
39
|
+
end
|
40
|
+
|
41
|
+
rule(:'docker-compose',docker: [:image, :build]) do
|
42
|
+
key.failure('image or build param is required for docker tasks') unless values.dig(:docker, :image) || values.dig(:docker, :build) || values[:'docker-compose']
|
43
|
+
end
|
44
|
+
|
45
|
+
rule(docker: :build) do
|
46
|
+
result, errors = validate_for(value, Hash => BuildSchema, String => NOT_EMPTY, NilClass => OK)
|
47
|
+
|
48
|
+
key.failure(errors) unless result
|
49
|
+
end
|
50
|
+
|
51
|
+
rule(:'docker-compose' => :run) do
|
52
|
+
result, errors = validate_for(value, Hash => RunSchema, Array => NOT_EMPTY, NilClass => OK)
|
53
|
+
|
54
|
+
key.failure(errors) unless result
|
55
|
+
end
|
56
|
+
|
57
|
+
rule(docker: :run) do
|
58
|
+
result, errors = validate_for(value, Hash => RunSchema, Array => NOT_EMPTY, NilClass => OK)
|
59
|
+
|
60
|
+
key.failure(errors) unless result
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def validate_for(value, validations)
|
66
|
+
validations.default_proc = proc { proc { false } }
|
67
|
+
|
68
|
+
result = validations[value.class].call(value)
|
69
|
+
return [result, nil] if result == true
|
70
|
+
return [result, "invalid #{value.class}"] if result == false
|
71
|
+
|
72
|
+
[result.success?, result.errors.messages.join]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/djin/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: djin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Atkinson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-struct
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-cli
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-validation
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- carlos.atks@gmail.com
|
114
|
+
executables:
|
115
|
+
- djin
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Dockerfile
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- djin.gemspec
|
131
|
+
- djin.yml
|
132
|
+
- docker-compose.yml
|
133
|
+
- examples/djin.yml
|
134
|
+
- exe/djin
|
135
|
+
- lib/djin.rb
|
136
|
+
- lib/djin/cli.rb
|
137
|
+
- lib/djin/entities/task.rb
|
138
|
+
- lib/djin/entities/types.rb
|
139
|
+
- lib/djin/executor.rb
|
140
|
+
- lib/djin/extensions/custom_predicates.rb
|
141
|
+
- lib/djin/extensions/hash_extensions.rb
|
142
|
+
- lib/djin/interpreter.rb
|
143
|
+
- lib/djin/task_contract.rb
|
144
|
+
- lib/djin/version.rb
|
145
|
+
homepage: https://github.com/catks/djin
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubygems_version: 3.0.3
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: djin is a make-like utility for docker containers
|
168
|
+
test_files: []
|