dockerfile2bash 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
+ SHA1:
3
+ metadata.gz: 1ebb79b52f4a7ebb88c4be553cfc301d747d2d61
4
+ data.tar.gz: 7696a028ed25bda19b1d48d0dcdcfdc4c4ed9a88
5
+ SHA512:
6
+ metadata.gz: 2e1fb14444a516c150245de6783ed19c75f0a0e11d407c31134fec06fa806f1881a1d29ae319c10e1da1b463f281dd201ac87791278b5a502c6a952429bfac2e
7
+ data.tar.gz: e9684bb6e922d1575e7fb129eca2ccd23953c5a786a66c0bdccb00fd146f8100a9e77d5913129d62de5a8a8b895c4fa7784e4079692ed1d9e59287e1c789a09e
@@ -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 idegorepl@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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Dockerfile2bash - Parse and Convert a Dockerfile to Bash script
2
+
3
+ `Dockerfile2bash` is used to parse a Dockerfile and convert it to a Bash script eventually. Maybe you can use it to convert massive Dockerfiles to shell scripts used in a metal installation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dockerfile2bash'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dockerfile2bash
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'dockerfile2bash'
25
+
26
+ parser = Dockerfile2bash.new(<your_Dockerfile_path>)
27
+ # parse it at first
28
+ parser.parse
29
+ # you can check the parse results
30
+ puts parser.commands
31
+ # then convert it to a Bash script
32
+ puts parser.generate_bash
33
+ ```
34
+
35
+ ### Commandline tool
36
+
37
+ The example bash scripts in the folder are generated by a command `df2sh`, released with Dockerfile2bash. After installation the command will be available in your shell path.
38
+
39
+ ```bash
40
+ df2sh /path/to/your/Dockerfile [output_bash_filename]
41
+ ```
42
+
43
+ `out.sh` will be used as output filename in current directory if the `output_bash_filename` is omitted.
44
+
45
+ And here some example generated scripts: [examples](./examples).
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ 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).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/beijingrb/dockerfile2bash. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+
61
+ ## Code of Conduct
62
+
63
+ Everyone interacting in the dockerfile2bash project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/beijingrb/dockerfile2bash/blob/master/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dockerfile2bash"
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/df2sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dockerfile2bash'
4
+
5
+ puts <<USAGE if ARGV.length < 1
6
+ df2sh is a command provided by Dockerfile2bash.
7
+
8
+ Usage: df2sh <dockerfile_path> [output_bash_filename]
9
+
10
+ "out.sh" will be used as output filename if the output_bash_filename is omitted.
11
+
12
+ USAGE
13
+
14
+ begin
15
+ parser = Dockerfile2bash.new(ARGV[0])
16
+ filename = File.join(Dir.pwd, ARGV[1]) if ARGV[1]
17
+ filename ||= "./out.sh"
18
+
19
+ parser.parse
20
+ script = parser.generate_bash
21
+ File.write(filename, script)
22
+ puts "success to convert a bash file: #{filename}"
23
+ rescue
24
+ puts "convertion failed"
25
+ end
data/bin/setup ADDED
@@ -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,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "dockerfile2bash"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dockerfile2bash"
7
+ spec.version = Dockerfile2bash::VERSION
8
+ spec.authors = ["B1nj0y"]
9
+ spec.email = ["idegorepl@gmail.com"]
10
+
11
+ spec.summary = %q{Parse and Convert a Dockerfile to Bash.}
12
+ spec.description = %q{The Gem can be used to parse and convert a Dockerfile to a Bash script.}
13
+ spec.homepage = "https://github.com/beijingrb/dockerfile2bash"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = %w[dockerfile2bash.gemspec] + Dir["*.md", "bin/*", "lib/**/*.rb", "examples/*.sh"]
17
+ spec.executables = %w[df2sh]
18
+ spec.require_paths = %w[lib]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.16.a"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+
3
+ # The script is generated from a Dockerfile via Dockerfile2bash(v0.1.0)
4
+ # By B1nj0y <idegorepl@gmail.com>
5
+
6
+ # The original Dockerfile is from a base image: <ubuntu:14.04>
7
+
8
+ apt-get -y update
9
+ apt-get -y install sudo openssh-server
10
+ apt-get -y install git
11
+ apt-get -y install curl
12
+ apt-get -y install rake
13
+ apt-get -y install ruby2.0 ruby2.0-dev
14
+ apt-get -y install bison
15
+ apt-get -y install libcurl4-openssl-dev
16
+ apt-get -y install libhiredis-dev
17
+ apt-get -y install libmarkdown2-dev
18
+ apt-get -y install libcap-dev
19
+ apt-get -y install libcgroup-dev
20
+ apt-get -y install make
21
+ apt-get -y install libpcre3 libpcre3-dev
22
+ apt-get -y install libmysqlclient-dev
23
+ cd /usr/local/src/ && git clone https://github.com/matsumotory/ngx_mruby.git
24
+ export NGINX_CONFIG_OPT_ENV --with-http_stub_status_module --with-http_ssl_module --prefix=/usr/local/nginx --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module
25
+ echo "export NGINX_CONFIG_OPT_ENV --with-http_stub_status_module --with-http_ssl_module --prefix=/usr/local/nginx --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module" >> ~/.bashrc
26
+ cd /usr/local/src/ngx_mruby && sh build.sh && make install
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+
3
+ # The script is generated from a Dockerfile via Dockerfile2bash(v0.1.0)
4
+ # By B1nj0y <idegorepl@gmail.com>
5
+
6
+ # The original Dockerfile is from a base image: <ubuntu:xenial>
7
+
8
+ RESTY_VERSION="1.13.6.1"
9
+ RESTY_LUAROCKS_VERSION="2.4.3"
10
+ RESTY_OPENSSL_VERSION="1.0.2k"
11
+ RESTY_PCRE_VERSION="8.41"
12
+ RESTY_J="1"
13
+ RESTY_CONFIG_OPTIONS=" --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-ipv6 --with-mail --with-mail_ssl_module --with-md5-asm --with-pcre-jit --with-sha1-asm --with-stream --with-stream_ssl_module --with-threads "
14
+ RESTY_CONFIG_OPTIONS_MORE=""
15
+ _RESTY_CONFIG_DEPS="--with-openssl=/tmp/openssl-${RESTY_OPENSSL_VERSION} --with-pcre=/tmp/pcre-${RESTY_PCRE_VERSION}"
16
+ DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential ca-certificates curl gettext-base libgd-dev libgeoip-dev libncurses5-dev libperl-dev libreadline-dev libxslt1-dev make perl unzip zlib1g-dev && cd /tmp && curl -fSL https://www.openssl.org/source/openssl-${RESTY_OPENSSL_VERSION}.tar.gz -o openssl-${RESTY_OPENSSL_VERSION}.tar.gz && tar xzf openssl-${RESTY_OPENSSL_VERSION}.tar.gz && curl -fSL https://ftp.pcre.org/pub/pcre/pcre-${RESTY_PCRE_VERSION}.tar.gz -o pcre-${RESTY_PCRE_VERSION}.tar.gz && tar xzf pcre-${RESTY_PCRE_VERSION}.tar.gz && curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz && tar xzf openresty-${RESTY_VERSION}.tar.gz && cd /tmp/openresty-${RESTY_VERSION} && ./configure -j${RESTY_J} ${_RESTY_CONFIG_DEPS} ${RESTY_CONFIG_OPTIONS} ${RESTY_CONFIG_OPTIONS_MORE} && make -j${RESTY_J} && make -j${RESTY_J} install && cd /tmp && rm -rf openssl-${RESTY_OPENSSL_VERSION} openssl-${RESTY_OPENSSL_VERSION}.tar.gz openresty-${RESTY_VERSION}.tar.gz openresty-${RESTY_VERSION} pcre-${RESTY_PCRE_VERSION}.tar.gz pcre-${RESTY_PCRE_VERSION} && curl -fSL https://github.com/luarocks/luarocks/archive/${RESTY_LUAROCKS_VERSION}.tar.gz -o luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz && tar xzf luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz && cd luarocks-${RESTY_LUAROCKS_VERSION} && ./configure --prefix=/usr/local/openresty/luajit --with-lua=/usr/local/openresty/luajit --lua-suffix=jit-2.1.0-beta3 --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 && make build && make install && cd /tmp && rm -rf luarocks-${RESTY_LUAROCKS_VERSION} luarocks-${RESTY_LUAROCKS_VERSION}.tar.gz && DEBIAN_FRONTEND=noninteractive apt-get autoremove -y && ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log && ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log
17
+ export PATH=$PATH:/usr/local/openresty/luajit/bin/:/usr/local/openresty/nginx/sbin/:/usr/local/openresty/bin/
18
+ echo "export PATH=$PATH:/usr/local/openresty/luajit/bin/:/usr/local/openresty/nginx/sbin/:/usr/local/openresty/bin/" >> ~/.bashrc
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+
3
+ class Dockerfile2bash
4
+ VERSION = '0.1.0'
5
+ attr_reader :commands
6
+ FIELDS = %w(from user run add copy arg env expose cmd onbuild)
7
+
8
+ def initialize(dockerfile)
9
+ @dockerfile = dockerfile
10
+ @content = File.read(@dockerfile)
11
+ @commands = []
12
+ end
13
+
14
+ def parse
15
+ @content.gsub!("\\\n", "")
16
+ lines = @content.split(/\r?\n+/) || []
17
+
18
+ lines.each do |ln|
19
+ # ignore blank and comment lines
20
+ next if /^\s*$/ =~ ln
21
+ next if /^\s*#/ =~ ln
22
+ segments = ln.split(" ", 2)
23
+ next if segments.length < 2 or !FIELDS.include?(segments[0].downcase)
24
+
25
+ case segments[0].downcase!
26
+ when "from", "user", "run", "env", "expose", "copy", "add"
27
+ @commands << { segments[0] => segments[1] }
28
+ when "cmd"
29
+ @commands << { "cmd" => (JSON.parse(segments[1]) || []).join(" ") }
30
+ when "arg"
31
+ args = segments[1].split("=", 2)
32
+ if args.length == 2
33
+ @commands << { "arg" => args }
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def generate_bash()
40
+ return unless @commands
41
+ bash = "#!/bin/bash \n\n# The script is generated from a Dockerfile via Dockerfile2bash(v#{VERSION})\n# By B1nj0y <idegorepl@gmail.com>\n\n"
42
+ @commands.each do |cmd|
43
+ case cmd.keys[0]
44
+ when "from"
45
+ bash << "# The original Dockerfile is from a base image: <#{cmd["from"]}> \n\n"
46
+ when "run"
47
+ bash << cmd["run"] << "\n"
48
+ when "arg"
49
+ bash << cmd["arg"].join("=") << "\n"
50
+ when "env"
51
+ env_str = "export " << cmd["env"]
52
+ bash << env_str << "\n"
53
+ bash << "echo \"#{env_str}\" >> ~/.bashrc" << "\n"
54
+ end
55
+ end
56
+ bash
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dockerfile2bash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - B1nj0y
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.16.a
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.a
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: The Gem can be used to parse and convert a Dockerfile to a Bash script.
42
+ email:
43
+ - idegorepl@gmail.com
44
+ executables:
45
+ - df2sh
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CODE_OF_CONDUCT.md
50
+ - README.md
51
+ - bin/console
52
+ - bin/df2sh
53
+ - bin/setup
54
+ - dockerfile2bash.gemspec
55
+ - examples/ngx_mruby-install.sh
56
+ - examples/openresty-install.sh
57
+ - lib/dockerfile2bash.rb
58
+ homepage: https://github.com/beijingrb/dockerfile2bash
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Parse and Convert a Dockerfile to Bash.
82
+ test_files: []