dockerfile2bash 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dockerfile2bash.gemspec +2 -1
- data/lib/dockerfile2bash.rb +23 -7
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9c633936731960c4cf35eb14144e5b815c8b291
|
4
|
+
data.tar.gz: cf21d1b038b052ac0700977a5894186bc9c8a8c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7942ccb417cde2902f4347f5dda183a0f9b3c8f33f84e036265d15b411383638d6bdcc6e620088e85c760415bdf7b7b9371b352539b1ca940081dc6fce573b11
|
7
|
+
data.tar.gz: 9d3d809c1bd42fe247985ebc30024b6f1a09252f2e27b5faa1d1bcda30dab1180afe50cf078ffbbb1b0b25376ca1c15ee965abf65657209978719051b26470f9
|
data/dockerfile2bash.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Dockerfile2bash::VERSION
|
8
8
|
spec.authors = ["B1nj0y"]
|
9
9
|
spec.email = ["idegorepl@gmail.com"]
|
10
|
-
|
10
|
+
spec.date = '2018-01-30'
|
11
11
|
spec.summary = %q{Parse and Convert a Dockerfile to Bash.}
|
12
12
|
spec.description = %q{The Gem can be used to parse and convert a Dockerfile to a Bash script.}
|
13
13
|
spec.homepage = "https://github.com/beijingrb/dockerfile2bash"
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = %w[df2sh]
|
18
18
|
spec.require_paths = %w[lib]
|
19
19
|
|
20
|
+
spec.add_dependency "rest-client", "~> 2.0"
|
20
21
|
spec.add_development_dependency "bundler", "~> 1.16.a"
|
21
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
23
|
end
|
data/lib/dockerfile2bash.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'rest-client'
|
2
3
|
|
3
4
|
class Dockerfile2bash
|
4
|
-
VERSION = '0.1.
|
5
|
+
VERSION = '0.1.4'
|
5
6
|
attr_reader :commands
|
6
7
|
FIELDS = %w(from user run add copy arg env expose cmd onbuild)
|
7
8
|
|
8
9
|
def initialize(dockerfile)
|
9
10
|
@dockerfile = dockerfile
|
10
|
-
@content =
|
11
|
+
@content = get_content
|
11
12
|
@commands = []
|
12
13
|
end
|
13
14
|
|
14
15
|
def parse
|
16
|
+
return unless @content || @content.empty?
|
15
17
|
@content.gsub!("\\\n", "")
|
16
18
|
lines = @content.split(/\r?\n+/) || []
|
17
19
|
|
18
|
-
lines.each do |
|
20
|
+
lines.each do |line|
|
19
21
|
# ignore blank and comment lines
|
20
|
-
next if /^\s*$/ =~
|
21
|
-
next if /^\s*#/ =~
|
22
|
-
segments =
|
22
|
+
next if /^\s*$/ =~ line
|
23
|
+
next if /^\s*#/ =~ line
|
24
|
+
segments = line.split(" ", 2)
|
23
25
|
next if segments.length < 2 or !FIELDS.include?(segments[0].downcase)
|
24
26
|
|
25
27
|
case segments[0].downcase!
|
@@ -63,7 +65,7 @@ class Dockerfile2bash
|
|
63
65
|
|
64
66
|
def generate_bash()
|
65
67
|
return unless @commands
|
66
|
-
bash = "#!/bin/bash \n\n# The script is generated from a Dockerfile via Dockerfile2bash(v#{VERSION})\n# By B1nj0y <idegorepl@gmail.com>\n\n"
|
68
|
+
bash = "#!/usr/bin/env bash \n\n# The script is generated from a Dockerfile via Dockerfile2bash(v#{VERSION})\n# By B1nj0y <idegorepl@gmail.com>\n\n"
|
67
69
|
@commands.each do |cmd|
|
68
70
|
case cmd.keys[0]
|
69
71
|
when "from"
|
@@ -80,4 +82,18 @@ class Dockerfile2bash
|
|
80
82
|
end
|
81
83
|
bash
|
82
84
|
end
|
85
|
+
|
86
|
+
def get_content
|
87
|
+
if @dockerfile =~ /^https:\/\/raw\.githubusercontent\.com\/.+$/
|
88
|
+
content = RestClient.get(@dockerfile)
|
89
|
+
elsif @dockerfile =~ /^https:\/\/github\.com\/(.+)$/
|
90
|
+
# convert to its corresponding raw url
|
91
|
+
url = "https://raw.githubusercontent.com/#{$1.sub('/blob/', '/')}"
|
92
|
+
content = RestClient.get(url)
|
93
|
+
else
|
94
|
+
# local file
|
95
|
+
content = File.read(@dockerfile)
|
96
|
+
end
|
97
|
+
content
|
98
|
+
end
|
83
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerfile2bash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- B1nj0y
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|