wocker 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72b6e3df2fabd741a403a07361c83895c354a6c4b0ddcd2d8ebd5f80648dfe76
4
- data.tar.gz: 976484279f1e8c2991f7ba9d582fd237af6d76e46cc6dd6989c2198a60226bbd
3
+ metadata.gz: 38dcece4d9f2ed8dd4e5af61d2b53d4a3f7e51fe9ee5f81cc387d18f2c1cfc8f
4
+ data.tar.gz: e8a352a9dc447a79d84d44037ecae40097be8ca3c67b6a050b89f09320c93612
5
5
  SHA512:
6
- metadata.gz: 2a32898e6e82410df01e3964dfb73cd537cdf89f216606fb765cc660494074a957bb8180b348e3a0b9098a22d4bf796da48ef727beb4a09ec14ebfa4b18826e6
7
- data.tar.gz: dac571860cfa31c102f073be8d3202f2299d6f5dea7a56ecf14768e3683a316c30df6eb1bb1d12875c1c6ce8452b53a4fd081fa2816b7de903a3f488171e3010
6
+ metadata.gz: 1bfe5f0b3eb772eebeddb8d0e29b6baf257554985b5e13ecc7627748f5ec9de137874b7c07bd8c6cb9aa453c22d5b45c378908270b8a75a2a504aba4e72bfb4e
7
+ data.tar.gz: 36797d42577056e749c41d06a911fe24480949c2b83bc1f4135bc0db155022965b76f5af913e80ce480b7cfdd4a43895c6f5fc3f8ba4c764d10e309061b0b159
data/.gitignore CHANGED
@@ -9,3 +9,7 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ .vagrant
14
+ Wockerfile
15
+ Vagrantfile
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wocker (0.1.0)
4
+ wocker (0.2.0)
5
5
  clamp
6
6
 
7
7
  GEM
@@ -4,10 +4,14 @@ module Wocker
4
4
  module Cli
5
5
  class BuildCommand < Clamp::Command
6
6
  option "--interface", "INTERFACE", "network interface"
7
+ option "--choco", :flag, "install chocolatey"
7
8
 
8
9
  def execute
9
- Wocker::Vagrantfile.run "destroy", "-f"
10
- Wocker::Vagrantfile.run "up", interface: interface
10
+ v = Wocker::Vagrantfile.new interface: interface, choco: choco?
11
+ v.create_from_wockerfile!
12
+
13
+ Wocker::Vagrant.run "destroy", "-f"
14
+ Wocker::Vagrant.run "up"
11
15
  end
12
16
  end
13
17
  end
@@ -6,8 +6,16 @@ module Wocker
6
6
  parameter "COMMAND ...", "command"
7
7
 
8
8
  def execute
9
+ command_list.insert 0, "cd"
10
+ workdir = if Wockerfile.workdir
11
+ Wockerfile.workdir
12
+ else
13
+ "/vagrant"
14
+ end
15
+ command_list.insert 1, "#{workdir};"
16
+
9
17
  cmd = command_list.join " "
10
- Wocker::Vagrantfile.run "winrm", "-c", cmd
18
+ Wocker::Vagrant.run "winrm", "-c", cmd
11
19
  end
12
20
  end
13
21
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wocker
4
+ module Cli
5
+ class InitCommand < Clamp::Command
6
+ def execute
7
+ FileUtils.cp File.join(Wocker.gem_root_path, "templates", "Wockerfile"), "Wockerfile"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,7 +4,7 @@ module Wocker
4
4
  module Cli
5
5
  class PortCommand < Clamp::Command
6
6
  def execute
7
- Wocker::Vagrantfile.run "port"
7
+ Wocker::Vagrant.run "port"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Wocker
4
4
  module Cli
5
5
  class PsCommand < Clamp::Command
6
6
  def execute
7
- Wocker::Vagrantfile.run "status"
7
+ Wocker::Vagrant.run "status"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Wocker
4
4
  module Cli
5
5
  class RestartCommand < Clamp::Command
6
6
  def execute
7
- Wocker::Vagrantfile.run "reload"
7
+ Wocker::Vagrant.run "reload"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Wocker
4
4
  module Cli
5
5
  class RmCommand < Clamp::Command
6
6
  def execute
7
- Wocker::Vagrantfile.run "destroy", "-f"
7
+ Wocker::Vagrant.run "destroy", "-f"
8
8
  end
9
9
  end
10
10
  end
@@ -19,6 +19,7 @@ module Wocker
19
19
  subcommand ["ps"], "ps", PsCommand
20
20
  subcommand ["port"], "port", PortCommand
21
21
  subcommand ["restart"], "restart", RestartCommand
22
+ subcommand ["init"], "init", InitCommand
22
23
 
23
24
  def self.run
24
25
  super
@@ -4,7 +4,7 @@ module Wocker
4
4
  module Cli
5
5
  class StartCommand < Clamp::Command
6
6
  def execute
7
- Wocker::Vagrantfile.run "up"
7
+ Wocker::Vagrant.run "up"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Wocker
4
4
  module Cli
5
5
  class StopCommand < Clamp::Command
6
6
  def execute
7
- Wocker::Vagrantfile.run "suspend"
7
+ Wocker::Vagrant.run "suspend"
8
8
  end
9
9
  end
10
10
  end
data/lib/wocker/cli.rb CHANGED
@@ -15,5 +15,6 @@ require_relative "cli/start_command"
15
15
  require_relative "cli/stop_command"
16
16
  require_relative "cli/ps_command"
17
17
  require_relative "cli/port_command"
18
+ require_relative "cli/init_command"
18
19
 
19
20
  require_relative "cli/root_command"
@@ -0,0 +1,31 @@
1
+ require 'pty'
2
+
3
+ module Wocker
4
+ module Vagrant
5
+ def self.run(*args)
6
+ stderr_reader, stderr_writer = IO.pipe
7
+
8
+ stdout,stdin,pid = PTY.spawn("vagrant", *args, err: stderr_writer.fileno)
9
+ stderr_writer.close
10
+ stdin_thr = Thread.new do
11
+ stdin.close
12
+ end
13
+
14
+ stdout_thr = Thread.new do
15
+ while line = stdout.gets
16
+ print line
17
+ end
18
+ end
19
+
20
+ stderr_thr = Thread.new do
21
+ while line = stderr_reader.gets
22
+ print line
23
+ end
24
+ end
25
+
26
+ stdin_thr.join
27
+ stdout_thr.join
28
+ stderr_thr.join
29
+ end
30
+ end
31
+ end
@@ -1,69 +1,25 @@
1
- require 'open3'
2
- require 'erb'
1
+ require 'fileutils'
3
2
 
4
3
  module Wocker
5
- module Vagrantfile
6
- def self.run *args, interface: nil
7
- wockerfile = Wockerfile.new "Wockerfile"
8
- instructions = wockerfile.parse
9
-
10
- from = instructions["from"]
11
- runs = instructions["runs"]
12
- ports = instructions["ports"]
13
-
14
- self.create from: from, runs: runs, ports: ports, interface: interface
15
-
16
- require "pty"
17
-
18
- stderr_reader, stderr_writer = IO.pipe
19
-
20
- stdout,stdin,pid = PTY.spawn("vagrant", *args, err: stderr_writer.fileno)
21
- stderr_writer.close
22
- stdin_thr = Thread.new do
23
- stdin.close
24
- end
25
-
26
- stdout_thr = Thread.new do
27
- while line = stdout.gets
28
- print line
29
- end
30
- end
31
-
32
- stderr_thr = Thread.new do
33
- while line = stderr_reader.gets
34
- print line
35
- end
36
- end
37
-
38
- stdin_thr.join
39
- stdout_thr.join
40
- stderr_thr.join
41
-
42
- self.remove
4
+ class Vagrantfile
5
+ def initialize(interface: nil, choco: false)
6
+ @interface = interface
7
+ @choco = choco
43
8
  end
44
9
 
45
- private
46
- def self.create(from:, runs:, ports:, interface: nil)
47
- @wocker_from = from
48
- @wocker_runs = runs
49
- @wocker_ports = ports
50
- @wocker_interface = interface
10
+ def create_from_wockerfile! *args
11
+ v = VagrantfileTemplate.new
12
+ v.wocker_from = Wockerfile.from
13
+ v.wocker_runs = Wockerfile.runs
14
+ v.wocker_ports = Wockerfile.ports
15
+ v.wocker_interface = @interface
16
+ v.wocker_installs = []
51
17
 
52
- source_path = File.expand_path(
53
- File.join(
54
- __dir__,
55
- "..","..",
56
- "templates", "Vagrantfile"
57
- ))
58
- vagrantfile_template = File.read source_path
59
- vagrantfile_contents = ERB.new(vagrantfile_template).result(binding)
60
-
61
- File.write "Vagrantfile", vagrantfile_contents
62
- end
18
+ if @choco
19
+ v.wocker_installs << File.join(Wocker.gem_root_path, "scripts", "wocker-install-chocolatey.ps1")
20
+ end
63
21
 
64
- def self.remove
65
- return if ENV["WOCKER_VAGRANTFILE_KEEP"] == "yes"
66
- File.unlink "Vagrantfile"
22
+ File.write "Vagrantfile", v.render(File.read(File.join(Wocker.gem_root_path, "templates", "Vagrantfile")))
67
23
  end
68
24
  end
69
25
  end
@@ -0,0 +1,10 @@
1
+ require 'erb'
2
+ module Wocker
3
+ class VagrantfileTemplate
4
+ attr_accessor :wocker_from, :wocker_interface, :wocker_ports, :wocker_installs, :wocker_runs
5
+
6
+ def render(template)
7
+ ERB.new(template).result(binding)
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Wocker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,23 +1,44 @@
1
- require_relative '../dockerfile_parser'
1
+ require "yaml"
2
2
 
3
3
  module Wocker
4
- class Wockerfile
5
- def initialize(path)
6
- @path = path
4
+ module Wockerfile
5
+ @@ports = []
6
+ @@runs = []
7
+ @@from = nil
8
+ @@workdir = nil
9
+
10
+ def self.ports
11
+ parse
12
+ @@ports
13
+ end
14
+ def self.runs
15
+ parse
16
+ @@runs
17
+ end
18
+ def self.from
19
+ parse
20
+ @@from
21
+ end
22
+ def self.workdir
23
+ parse
24
+ @@workdir
7
25
  end
8
26
 
9
- def parse
10
- contents = File.read @path
27
+ private
28
+ def self.parse
29
+ contents = File.read "Wockerfile"
11
30
  parsed = YAML.load contents
12
- if parsed["ports"]
31
+ @@runs = parsed["runs"]
32
+ @@from = parsed["from"]
33
+ @@workdir = parsed["workdir"]
34
+
35
+ @@ports = if parsed["ports"]
13
36
  ports_split = []
14
37
  parsed["ports"].each do |port|
15
38
  ports_split << port.split(":")
16
39
  end
17
- parsed.delete "ports"
18
- parsed["ports"] = ports_split
40
+ ports_split
19
41
  end
20
- parsed
21
42
  end
22
43
  end
23
44
  end
data/lib/wocker.rb CHANGED
@@ -1,6 +1,16 @@
1
1
  module Wocker
2
+ def self.gem_root_path
3
+ File.expand_path(
4
+ File.join(
5
+ __dir__,
6
+ ".."
7
+ )
8
+ )
9
+ end
2
10
  end
3
11
 
4
12
  require_relative "wocker/version"
5
13
  require_relative "wocker/wockerfile"
14
+ require_relative "wocker/vagrant"
6
15
  require_relative "wocker/vagrantfile"
16
+ require_relative "wocker/vagrantfile_template"
@@ -5,4 +5,3 @@ if (!(Test-Path $ChocoInstallPath)) {
5
5
  }
6
6
 
7
7
  choco feature disable --name showDownloadProgress
8
- $env:Path += ";C:\ProgramData\Chocolatey\bin"
@@ -9,7 +9,7 @@ Vagrant.configure("2") do |config|
9
9
  config.vm.network "public_network", bridge: "<%= @wocker_interface %>"
10
10
  <% end %>
11
11
  <% @wocker_ports.each do |wocker_port| %>
12
- config.vm.network :forwarded_port, guest: <%= wocker_port[0] %>, host: <%= wocker_port[1] %>
12
+ config.vm.network :forwarded_port, guest: <%= wocker_port[0] %>, host: <%= wocker_port[1] %>
13
13
  <% end %>
14
14
  config.vm.provider "virtualbox" do |vb|
15
15
  vb.gui = true
@@ -35,6 +35,10 @@ Vagrant.configure("2") do |config|
35
35
 
36
36
  config.vm.provision "shell", inline: '&netsh "advfirewall" "set" "allprofiles" "state" "off"'
37
37
 
38
+ <% @wocker_installs.each do |wocker_install| %>
39
+ config.vm.provision "shell", path: "<%= wocker_install %>"
40
+ <% end %>
41
+
38
42
  <% @wocker_runs.each do |wocker_run| %>
39
43
  <% if wocker_run["inline"] %>
40
44
  config.vm.provision "shell", inline: '<%= wocker_run["inline"] %>'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-15 00:00:00.000000000 Z
11
+ date: 2018-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -79,31 +79,19 @@ files:
79
79
  - ".ruby-gemset"
80
80
  - ".ruby-version"
81
81
  - ".travis.yml"
82
- - ".vagrant/machines/wocker/virtualbox/action_provision"
83
- - ".vagrant/machines/wocker/virtualbox/action_set_name"
84
- - ".vagrant/machines/wocker/virtualbox/box_meta"
85
- - ".vagrant/machines/wocker/virtualbox/creator_uid"
86
- - ".vagrant/machines/wocker/virtualbox/id"
87
- - ".vagrant/machines/wocker/virtualbox/index_uuid"
88
- - ".vagrant/machines/wocker/virtualbox/synced_folders"
89
- - ".vagrant/machines/wocker/virtualbox/vagrant_cwd"
90
- - ".vagrant/rgloader/loader.rb"
91
82
  - Gemfile
92
83
  - Gemfile.lock
93
84
  - LICENSE.txt
94
85
  - README.md
95
86
  - Rakefile
96
- - Vagrantfile
97
- - Wockerfile
98
87
  - bin/console
99
88
  - bin/setup
100
89
  - exe/wocker
101
- - install-chocolatey.ps1
102
- - lib/dockerfile_parser.rb
103
90
  - lib/wocker.rb
104
91
  - lib/wocker/cli.rb
105
92
  - lib/wocker/cli/build_command.rb
106
93
  - lib/wocker/cli/exec_command.rb
94
+ - lib/wocker/cli/init_command.rb
107
95
  - lib/wocker/cli/port_command.rb
108
96
  - lib/wocker/cli/ps_command.rb
109
97
  - lib/wocker/cli/restart_command.rb
@@ -112,9 +100,12 @@ files:
112
100
  - lib/wocker/cli/start_command.rb
113
101
  - lib/wocker/cli/stop_command.rb
114
102
  - lib/wocker/cli/version_command.rb
103
+ - lib/wocker/vagrant.rb
115
104
  - lib/wocker/vagrantfile.rb
105
+ - lib/wocker/vagrantfile_template.rb
116
106
  - lib/wocker/version.rb
117
107
  - lib/wocker/wockerfile.rb
108
+ - scripts/wocker-install-chocolatey.ps1
118
109
  - templates/Vagrantfile
119
110
  - wocker.gemspec
120
111
  homepage: https://github.com/matti/wocker
@@ -1 +0,0 @@
1
- 1.5:994104c6-3a87-4002-b0fe-95636fdc3e4d
@@ -1 +0,0 @@
1
- 1544907743
@@ -1 +0,0 @@
1
- {"name":"StefanScherer/windows_2019","version":"2018.11.22","provider":"virtualbox","directory":"boxes/StefanScherer-VAGRANTSLASH-windows_2019/2018.11.22/virtualbox"}
@@ -1 +0,0 @@
1
- 994104c6-3a87-4002-b0fe-95636fdc3e4d
@@ -1 +0,0 @@
1
- 8f81c9755061455d8d2494f4d5972017
@@ -1 +0,0 @@
1
- {"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/Users/mpa/Library/Mobile Documents/com~apple~CloudDocs/Documents/dev/wocker","disabled":false,"__vagrantfile":true}}}
@@ -1 +0,0 @@
1
- /Users/mpa/Library/Mobile Documents/com~apple~CloudDocs/Documents/dev/wocker
@@ -1,9 +0,0 @@
1
- # This file loads the proper rgloader/loader.rb file that comes packaged
2
- # with Vagrant so that encoded files can properly run with Vagrant.
3
-
4
- if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
5
- require File.expand_path(
6
- "rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"])
7
- else
8
- raise "Encoded files can't be read outside of the Vagrant installer."
9
- end
data/Vagrantfile DELETED
@@ -1,55 +0,0 @@
1
- # https://github.com/StefanScherer/docker-windows-box/blob/master/Vagrantfile
2
- Vagrant.configure("2") do |config|
3
- config.vm.define "wocker"
4
- config.vm.guest = "windows"
5
-
6
- config.vm.box = "StefanScherer/windows_2019"
7
- config.vm.communicator = "winrm"
8
-
9
-
10
- config.vm.network :forwarded_port, guest: 9516, host: 5555
11
-
12
- config.vm.provider "virtualbox" do |vb|
13
- vb.gui = true
14
- vb.linked_clone = true
15
-
16
- vb.customize ["modifyvm", :id, "--memory", 2048]
17
- vb.customize ["modifyvm", :id, "--cpus", 2]
18
- vb.customize ["modifyvm", :id, "--vram", 128]
19
- vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
20
-
21
- if false
22
- vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
23
- vb.customize ["modifyvm", :id, "--accelerate2dvideo", "on"]
24
- end
25
-
26
- # Guest additions requires optical driver
27
- vb.customize ["storageattach", :id,
28
- "--storagectl", "IDE Controller",
29
- "--port", "0", "--device", "1",
30
- "--type", "dvddrive",
31
- "--medium", "emptydrive"]
32
- end
33
-
34
- config.vm.provision "shell", inline: '&netsh "advfirewall" "set" "allprofiles" "state" "off"'
35
-
36
-
37
-
38
- config.vm.provision "shell", path: 'install-chocolatey.ps1'
39
-
40
-
41
-
42
- config.vm.provision "shell", inline: 'choco install -y ruby'
43
-
44
-
45
-
46
- config.vm.provision "shell", inline: 'choco install -y nircmd'
47
-
48
-
49
-
50
- config.vm.provision "shell", inline: 'gem install delirium-driver'
51
-
52
-
53
-
54
- config.vm.provision :reload
55
- end
data/Wockerfile DELETED
@@ -1,8 +0,0 @@
1
- from: StefanScherer/windows_2019
2
-
3
- runs:
4
- - path: install-chocolatey.ps1
5
- - inline: choco install -y ruby
6
- - inline: choco install -y nircmd
7
- ports:
8
- - 9516:5555
@@ -1,60 +0,0 @@
1
- # Encoding: utf-8
2
- # @author Nikolay Yurin <yurinnick@outlook.com>
3
-
4
- require 'yaml'
5
-
6
- # DockerfileParser main class
7
- class DockerfileParser
8
- @commands = %w(FROM MAINTAINER RUN CMD EXPOSE ENV ADD COPY ENTRYPOINT
9
- VOLUME USER WORKDIR ONBUILD)
10
-
11
- # Parse Dockerfile from specified path
12
- # @return [Array<Hash>] parser Dockerfile
13
- def self.load_file(path)
14
- loads(File.read(path))
15
- end
16
-
17
- def self.loads(s)
18
- dockerfile_array = split_dockerfile(s)
19
- parse_commands(dockerfile_array).each_cons(2).map do |item|
20
- process_steps(dockerfile_array, item[0], item[1][:index])
21
- end
22
- end
23
-
24
- def self.split_dockerfile(str)
25
- str.gsub(/(\s\\\s)+/i, '').gsub("\n", ' ').squeeze(' ').split(' ')
26
- end
27
-
28
- def self.parse_commands(dockerfile_array)
29
- dockerfile_array.each_with_index.map do |cmd, index|
30
- { index: index, command: cmd } if @commands.include?(cmd)
31
- end.compact! << { index: dockerfile_array.length, command: 'EOF' }
32
- end
33
-
34
- def self.process_steps(dockerfile_array, step, next_cmd_index)
35
- { command: step[:command],
36
- params: split_params(
37
- step[:command],
38
- dockerfile_array[step[:index] + 1..next_cmd_index - 1]
39
- )
40
- }
41
- end
42
-
43
- def self.split_params(cmd, params)
44
- case cmd
45
- when 'FROM' then params.join('').split(':')
46
- when 'RUN' then params.join(' ').split(/\s(\&|\;)+\s/).map(&:strip)
47
- when 'ENV' then
48
- { name: params[0], value: params[1..-1].join(' ') }
49
- when 'COPY', 'ADD' then { src: params[0], dst: params[1] }
50
- else
51
- params = params.join(' ') if params.is_a?(Array)
52
- YAML.load(params.to_s)
53
- end
54
- end
55
-
56
- private_class_method :parse_commands
57
- private_class_method :process_steps
58
- private_class_method :split_params
59
- private_class_method :split_dockerfile
60
- end