miniexec 0.0.5 → 0.0.6
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 +4 -4
- data/bin/miniexec +7 -4
- data/lib/miniexec.rb +11 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e5abfbd093e75a0bb48a481b1ce13cddaf849680faf63f02839d151847daf25
|
4
|
+
data.tar.gz: c759f6ec46d9bbe5812988cdd76706afb2aca6d9d7d7064294f848814ae26bb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d3604262b29677b356b0ddaffb581b3527183ce084bed754f286bff5c4cf3e9b980af47048796975cb040b974adb77c58f21ffa1fb54b9cf13bedde15f50f7
|
7
|
+
data.tar.gz: cd413fee962e6795592637a8c2278c6e9d24b9066a448c2b9c20a6b5b1542dce2007fd9960ad85b038edbb7ddb5d472ab4654104d3314fed66764d9dcaa15740
|
data/bin/miniexec
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
lib = File.expand_path('../lib', __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'miniexec'
|
5
7
|
require 'optparse'
|
8
|
+
require 'pry'
|
6
9
|
|
7
10
|
options = {
|
8
11
|
binds: [],
|
9
|
-
env: {}
|
12
|
+
env: {},
|
13
|
+
path: '.',
|
14
|
+
docker: ENV['DOCKER_HOST'] || '/run/docker.sock'
|
10
15
|
}
|
11
16
|
|
12
17
|
OptionParser.new do |opts|
|
@@ -34,17 +39,15 @@ OptionParser.new do |opts|
|
|
34
39
|
end
|
35
40
|
opts.on('-d', '--docker-url URL',
|
36
41
|
'Location of the docker socket') do |sock|
|
37
|
-
options[:docker] = sock
|
42
|
+
options[:docker] = sock
|
38
43
|
end
|
39
44
|
end.parse!
|
40
45
|
|
41
46
|
raise OptionParser::MissingArgument, 'Specify a job with -j' if options[:job].nil?
|
42
|
-
raise OptionParser::MissingArgument, 'Specify a job with -p' if options[:path].nil?
|
43
47
|
|
44
48
|
MiniExec.config(project_path: options[:path])
|
45
49
|
exec = MiniExec.new options[:job],
|
46
50
|
docker_url: options[:docker],
|
47
51
|
binds: options[:binds],
|
48
52
|
env: options[:env]
|
49
|
-
|
50
53
|
exec.run_job
|
data/lib/miniexec.rb
CHANGED
@@ -8,7 +8,6 @@ class MiniExec
|
|
8
8
|
require 'tempfile'
|
9
9
|
require 'yaml'
|
10
10
|
require 'git'
|
11
|
-
require 'pry'
|
12
11
|
# Class instance variables
|
13
12
|
@project_path = '.'
|
14
13
|
@workflow_file = '.gitlab-ci.yml'
|
@@ -43,16 +42,15 @@ class MiniExec
|
|
43
42
|
configure_logger
|
44
43
|
Docker.options[:read_timeout] = 6000
|
45
44
|
Docker.url = docker_url if docker_url
|
46
|
-
binding.pry
|
47
45
|
end
|
48
46
|
|
49
47
|
def run_job
|
50
48
|
script_path = "/tmp/#{@job['name']}.sh"
|
51
|
-
@logger.
|
49
|
+
@logger.info "Fetching image #{@image}"
|
52
50
|
Docker::Image.create(fromImage: @image)
|
53
|
-
@logger.
|
51
|
+
@logger.info 'Image fetched'
|
54
52
|
Dir.chdir(@project_path) do
|
55
|
-
@logger.
|
53
|
+
@logger.info 'Creating container'
|
56
54
|
container = Docker::Container.create(
|
57
55
|
Cmd: ['/bin/bash', script_path],
|
58
56
|
Image: @image,
|
@@ -61,7 +59,7 @@ class MiniExec
|
|
61
59
|
)
|
62
60
|
container.store_file(script_path, @script)
|
63
61
|
container.start({ Binds: [@binds] })
|
64
|
-
container.tap(&:start).attach { |_, chunk|
|
62
|
+
container.tap(&:start).attach { |_, chunk| puts chunk }
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
@@ -101,8 +99,8 @@ class MiniExec
|
|
101
99
|
end
|
102
100
|
|
103
101
|
def variables
|
104
|
-
globals = @workflow['variables']
|
105
|
-
job_locals = @job['variables']
|
102
|
+
globals = @workflow['variables'] || {}
|
103
|
+
job_locals = @job['variables'] || {}
|
106
104
|
globals.merge job_locals
|
107
105
|
end
|
108
106
|
|
@@ -111,13 +109,13 @@ class MiniExec
|
|
111
109
|
@logger.formatter = proc do |severity, _, _, msg|
|
112
110
|
"[#{severity}]: #{msg}\n"
|
113
111
|
end
|
114
|
-
@logger.level = ENV['LOGLEVEL'] || Logger::
|
112
|
+
@logger.level = ENV['LOGLEVEL'] || Logger::INFO
|
115
113
|
end
|
116
114
|
|
117
115
|
def compile_script
|
118
|
-
before_script = @job['before_script'] ||
|
119
|
-
script = @job['script'] ||
|
120
|
-
after_script = @job['after_script'] ||
|
121
|
-
|
116
|
+
before_script = @job['before_script'] || ''
|
117
|
+
script = @job['script'] || ''
|
118
|
+
after_script = @job['after_script'] || ''
|
119
|
+
[before_script, script, after_script].flatten.join("\n").strip
|
122
120
|
end
|
123
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miniexec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Pugh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A minimal interpretor/executor for .gitlab-ci.yml
|
14
14
|
email: pugh@s3kr.it
|