vagrant-proxyconf 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29246610a402d179b8e3ac8f2d4f5761ffa37a0d
4
- data.tar.gz: d35190d33063c461b8a4cf5551493b5d9c7d3673
3
+ metadata.gz: 89c3334da0f5ca851a92f23dc388327d47dee03a
4
+ data.tar.gz: 743404cd2300188be2c8fccf0dda4894b2ba8523
5
5
  SHA512:
6
- metadata.gz: ca2472979189cd4471b56e2a350796d496323616e1dff2cff864a6a8f092096a385556f999eea8dc418d23e71a56dd55cb738d47ca3973bc4bddc26cb9418737
7
- data.tar.gz: '049c14499abe8e93de88abee505026e6a68c0ca7f062a5d9ad370a51c296684b7e17d647d0205db43b84c270b50aee2c29bfda1e624fa9f0edb63d627c398d08'
6
+ metadata.gz: 2298453a51c191d77e4b927ac5be44d4d15aff00fce6a14a4c532dfb85587f7686966ae374f538583fb3ece529724990e902be06af337979f54b0cf3af5c70af
7
+ data.tar.gz: 375908939f9f242efcd9d4e3b41a610017be5b9e55680d4e09b71620561f55750d0de9508b257c7c8c271881835f28703d3ecfb6113bdbd9922ffd6f14bec728
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle
2
2
  /.yardoc
3
+ .vagrant
3
4
  /Gemfile.lock
4
5
  /doc
5
6
  /tmp
data/.travis.yml CHANGED
@@ -17,10 +17,6 @@ matrix:
17
17
  - env: VAGRANT_VERSION=v2.0.4
18
18
  - env: VAGRANT_VERSION=v1.9.8
19
19
  rvm: 2.3.4
20
- - env:
21
- - VAGRANT_VERSION=v1.8.7
22
- - BUNDLER_VERSION=1.12.5
23
- rvm: 2.2.5
24
20
  - env: VAGRANT_VERSION=master
25
21
  allow_failures:
26
22
  - env: VAGRANT_VERSION=master
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ # 2.0.2 / _Not released yet_
2
+
3
+ # 2.0.1 / 2019-03-31
4
+
5
+ Improvements:
6
+
7
+ - Check for existence of HTTP_PROXY and HTTPS_PROXY environment variables.
8
+ If neither are set this plugin is automatically disabled.
9
+ - Correctly uses the Tempfile pattern now via commit. 8ee2a2bb146aeb9fb1b27c80814e9000eff34aa1
10
+
11
+ Bug fixes:
12
+ - Docker proxy conf not set the first time the provisioner is used (trusty64) - #155
13
+ - Proxy doesn't work for Docker with systemd - #172
14
+ - Provisioning of docker fails - #180
15
+ - Docker provider: Guest-specific operations were attempted on a machine that is not ready for guest communication. - #181
16
+ - Provisioning of docker fails issue 180. - #182
17
+ - vagrant-proxyconf running on Win10 and provisioning with Docker. - #186
18
+ - Cannot force to write but without configuration. - #188
19
+
1
20
  # 2.0.0 / 2019-01-03
2
21
 
3
22
  Improvements:
data/Gemfile CHANGED
@@ -27,7 +27,10 @@ gem 'rspec-its', '~> 1.0'
27
27
 
28
28
  group :development do
29
29
  gem 'guard-rspec'
30
+ gem 'pry'
31
+ gem 'rb-readline'
30
32
  gem 'redcarpet'
33
+ gem 'serverspec'
31
34
  gem 'yard', '~> 0.9.11'
32
35
  end
33
36
 
data/README.md CHANGED
@@ -267,6 +267,36 @@ VAGRANT_APT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up
267
267
  An excellent Vagrant plugin that shares various cache directories among similar VM instances. Should work fine together with vagrant-proxyconf.
268
268
 
269
269
 
270
+ ## Installing a pre-release version
271
+
272
+ * A [released](https://rubygems.org/gems/vagrant-proxyconf) pre-release version:
273
+
274
+ ```
275
+ vagrant plugin install --plugin-source https://rubygems.org/ --plugin-prerelease vagrant-proxyconf
276
+ ```
277
+
278
+ * Development version from git repository:
279
+
280
+ ```
281
+ git clone https://github.com/tmatilai/vagrant-proxyconf.git
282
+ cd vagrant-proxyconf
283
+
284
+ # Optionally check out other than the master branch
285
+ git checkout <branch>
286
+
287
+ # If you don't have Ruby installed, you can use <path/to/vagrant>/embedded/bin/gem>.
288
+ # If you have Docker you can use the Ruby image:
289
+ # docker run -it --rm -v ${PWD}:/usr/src/myapp -w /usr/src/myapp ruby:2.6 gem build vagrant-proxyconf.gemspec
290
+ gem build vagrant-proxyconf.gemspec
291
+
292
+ vagrant plugin install vagrant-proxyconf-*.gem
293
+ ```
294
+
295
+ Paths to Vagrant's embedded gem:
296
+ * Linux: `/opt/vagrant/embedded/bin/gem`
297
+ * OS X: `/Applications/Vagrant/embedded/bin/gem`
298
+
299
+
270
300
  ## Development Known Issues
271
301
 
272
302
 
@@ -9,13 +9,15 @@ RUN yum clean all && \
9
9
  curl \
10
10
  device-mapper-persistent-data \
11
11
  git \
12
+ initscripts \
12
13
  lvm2 \
13
14
  openssh-clients \
14
15
  openssh-server \
15
16
  rsync \
16
17
  sudo \
17
18
  wget \
18
- yum-utils && \
19
+ yum-utils \
20
+ xfsprogs && \
19
21
  yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && \
20
22
  yum clean expire-cache && \
21
23
  yum install -y docker-ce && \
@@ -31,10 +33,13 @@ RUN yum clean all && \
31
33
  mkdir -p /home/vagrant/.ssh && \
32
34
  touch /home/vagrant/.ssh/authorized_keys
33
35
 
36
+ VOLUME [ "/sys/fs/cgroup" ]
37
+
34
38
  RUN grep -q 'OHlnVYCzRdK8jlqm8tehUc9c9WhQ==' /home/vagrant/.ssh/authorized_keys || echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==" >> /home/vagrant/.ssh/authorized_keys && \
35
39
  chmod 0600 /home/vagrant/.ssh/authorized_keys && \
36
40
  chown vagrant:vagrant /home/vagrant/.ssh/authorized_keys
37
41
 
38
42
  # -e write logs to stderr
39
43
  # -D run in foreground
40
- CMD ["/usr/sbin/sshd", "-e", "-D"]
44
+ # CMD ["/usr/sbin/sshd", "-e", "-D"]
45
+ CMD ["/usr/sbin/init"]
@@ -133,9 +133,6 @@ Vagrant.configure('2') do |config|
133
133
  config.vm.define "default" do |default|
134
134
  # set this to true, if you want to use a global proxy
135
135
  default.proxy.enabled = false if !GLOBAL_PROXY_HOST
136
- default.proxy.enabled = {
137
- :apt => false
138
- }
139
136
 
140
137
  default.vm.box = BOX
141
138
 
@@ -143,6 +140,17 @@ Vagrant.configure('2') do |config|
143
140
  default.vm.provision :shell, path: 'install-debian.sh'
144
141
 
145
142
  default.vm.network "private_network", ip: "70.70.70.10"
143
+
144
+ default.vm.provider :virtualbox do |vb, override|
145
+ # override.proxy.enabled = ENABLE_PROXY
146
+ vb.cpus = 1
147
+ vb.memory = 1024
148
+
149
+ vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] if config.vm.box =~ /xenial|bionic/
150
+
151
+ vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
152
+ vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
153
+ end
146
154
  end
147
155
 
148
156
  config.vm.define "centos7-client" do |centos7|
@@ -152,16 +160,37 @@ Vagrant.configure('2') do |config|
152
160
  centos7.vm.network "private_network", ip: "70.70.70.20"
153
161
 
154
162
  centos7.vm.provision :shell, path: 'install-c7.sh'
155
- end
156
163
 
157
- config.vm.provider :virtualbox do |vb, override|
158
- # override.proxy.enabled = ENABLE_PROXY
159
- vb.cpus = 1
160
- vb.memory = 1024
164
+ config.vm.provider :virtualbox do |vb, override|
165
+ # override.proxy.enabled = ENABLE_PROXY
166
+ vb.cpus = 1
167
+ vb.memory = 1024
161
168
 
162
- vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] if config.vm.box =~ /xenial|bionic/
169
+ vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] if config.vm.box =~ /xenial|bionic/
163
170
 
164
- vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
165
- vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
171
+ vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
172
+ vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
173
+ end
166
174
  end
175
+
176
+ # config.vm.define "centos7-client" do |centos7|
177
+ # centos7.proxy.enabled = config.proxy.enabled
178
+ #
179
+ # centos7.vm.provider :docker do |d|
180
+ # d.build_dir = '.'
181
+ # d.dockerfile = 'Dockerfile'
182
+ # d.has_ssh = true
183
+ # # d.pull = true
184
+ #
185
+ # if SUPPORTS_DOCKER_IN_DOCKER
186
+ # d.volumes = [
187
+ # "#{DOCKER_SOCKET}:#{DOCKER_SOCKET}",
188
+ # ]
189
+ # d.create_args = [
190
+ # '--privileged',
191
+ # ]
192
+ # end
193
+ # end
194
+ # end
195
+
167
196
  end
@@ -41,17 +41,18 @@ module VagrantPlugins
41
41
  return @docker_client_config_path if @docker_client_config_path
42
42
  return if !supports_config_json?
43
43
 
44
- @docker_client_config_path = "/tmp/vagrant-proxyconf-docker-config.json"
44
+ @docker_client_config_path = tempfile(Hash.new)
45
45
 
46
46
  @machine.communicate.tap do |comm|
47
47
  if comm.test("[ -f /etc/docker/config.json ]")
48
- comm.download("/etc/docker/config.json", @docker_client_config_path)
49
- else
50
- File.write(@docker_client_config_path, Hash.new)
48
+ logger.info('Downloading file /etc/docker/config.json')
49
+ comm.sudo("chmod 0644 /etc/docker/config.json")
50
+ comm.download("/etc/docker/config.json", @docker_client_config_path.path)
51
+ logger.info("Downloaded /etc/docker/config.json to #{@docker_client_config_path.path}")
51
52
  end
52
53
  end
53
54
 
54
- @docker_client_config_path
55
+ @docker_client_config_path = @docker_client_config_path.path
55
56
  end
56
57
 
57
58
  def update_docker_client_config
@@ -65,24 +66,39 @@ module VagrantPlugins
65
66
  'default' => {}
66
67
  }
67
68
  else
68
- data['proxies'] = {
69
- 'default' => {
70
- 'httpProxy' => config.http,
71
- 'httpsProxy' => config.https,
72
- 'noProxy' => config.no_proxy,
73
- }
74
- }
69
+
70
+ data['proxies'] = {} unless data.key?('proxies')
71
+ data['proxies']['default'] = {} unless data['proxies'].key?('default')
72
+
73
+ data['proxies']['default'].delete('httpProxy')
74
+ data['proxies']['default'].delete('httpsProxy')
75
+ data['proxies']['default'].delete('noProxy')
76
+
77
+ unless config.http == false || config.http == "" || config.http.nil?
78
+ data['proxies']['default']['httpProxy'] = config.http
79
+ end
80
+
81
+ unless config.https == false || config.https == "" || config.https.nil?
82
+ data['proxies']['default']['httpsProxy'] = config.https
83
+ end
84
+
85
+ unless config.no_proxy == false || config.no_proxy == "" || config.no_proxy.nil?
86
+ data['proxies']['default']['noProxy'] = config.no_proxy
87
+ end
88
+
75
89
  end
76
90
 
77
91
  config_json = JSON.pretty_generate(data)
78
92
 
79
- File.write(@docker_client_config_path, config_json)
93
+ @docker_client_config_path = tempfile(config_json)
80
94
 
81
95
  @machine.communicate.tap do |comm|
82
- comm.upload(@docker_client_config_path, @docker_client_config_path)
83
- comm.sudo("mv #{@docker_client_config_path} /etc/docker/config.json")
96
+ comm.upload(@docker_client_config_path.path, "/tmp/vagrant-proxyconf-docker-config.json")
97
+ comm.sudo("mkdir -p /etc/docker")
98
+ comm.sudo("chown root:root /etc/docker")
99
+ comm.sudo("mv /tmp/vagrant-proxyconf-docker-config.json /etc/docker/config.json")
84
100
  comm.sudo("chown root:root /etc/docker/config.json")
85
- comm.sudo("rm -f #{@docker_client_config_path}")
101
+ comm.sudo("rm -f /tmp/vagrant-proxyconf-docker-config.json")
86
102
 
87
103
  comm.sudo("sed -i.bak -e '/^DOCKER_CONFIG/d' /etc/environment")
88
104
  if !disabled?
@@ -90,8 +106,6 @@ module VagrantPlugins
90
106
  end
91
107
  end
92
108
 
93
- File.unlink(@docker_client_config_path) if File.exists?(@docker_client_config_path)
94
-
95
109
  config_json
96
110
  end
97
111
 
@@ -164,9 +178,12 @@ module VagrantPlugins
164
178
  end
165
179
 
166
180
  def service_restart_command
167
- ["systemctl restart #{docker}",
181
+ [
182
+ "kill -HUP `pgrep -f '#{docker}'`",
183
+ "systemctl restart #{docker}",
168
184
  "service #{docker} restart",
169
- "/etc/init.d/#{docker} restart"].join(' || ')
185
+ "/etc/init.d/#{docker} restart",
186
+ ].join(' || ')
170
187
  end
171
188
 
172
189
  def docker_sed_script
@@ -15,8 +15,25 @@ module VagrantPlugins
15
15
 
16
16
  private
17
17
 
18
+ def has_proxy_env_var?(var='HTTP_PROXY')
19
+ var_not_in_env = ENV[var].nil? || ENV[var] == ''
20
+ return false if var_not_in_env
21
+
22
+ true
23
+ end
24
+
25
+ def plugin_disabled?(config)
26
+ config.enabled == false || config.enabled == '' || config.enabled.nil? || config.enabled == {}
27
+ end
28
+
18
29
  def plugin_enabled?(config)
19
- config.enabled != false && config.enabled != ''
30
+ return false if plugin_disabled?(config)
31
+
32
+ # check for existence of HTTP_PROXY and HTTPS_PROXY environment variables
33
+ has_proxy_var = has_proxy_env_var?('HTTP_PROXY') || has_proxy_env_var?('HTTPS_PROXY')
34
+ return false if has_proxy_var == false
35
+
36
+ true
20
37
  end
21
38
  end
22
39
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProxyConf
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
5
5
  end
@@ -12,17 +12,19 @@ def mock_write_docker_config(machine)
12
12
  allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/default/docker.new")
13
13
  allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/default/docker.new")
14
14
  allow(machine).to receive_message_chain(:communicate, :sudo).with("mv -f /etc/default/docker.new /etc/default/docker")
15
- allow(machine).to receive_message_chain(:communicate, :sudo).with("systemctl restart docker || service docker restart || /etc/init.d/docker restart")
15
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("kill -HUP `pgrep -f 'docker'` || systemctl restart docker || service docker restart || /etc/init.d/docker restart")
16
16
  allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf /etc/default/docker.new")
17
17
  end
18
18
 
19
- def mock_update_docker_client_config(machine, config_path)
20
- allow(machine).to receive_message_chain(:communicate, :upload).with(config_path, config_path)
21
- allow(machine).to receive_message_chain(:communicate, :sudo).with("mv #{config_path} /etc/docker/config.json")
19
+ def mock_update_docker_client_config(machine)
20
+ allow(machine).to receive_message_chain(:communicate, :upload)
21
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mv /tmp/vagrant-proxyconf-docker-config.json /etc/docker/config.json")
22
22
  allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/docker/config.json")
23
- allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f #{config_path}")
23
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf-docker-config.json")
24
24
  allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -i.bak -e '/^DOCKER_CONFIG/d' /etc/environment")
25
25
  allow(machine).to receive_message_chain(:communicate, :sudo).with("echo DOCKER_CONFIG=/etc/docker >> /etc/environment")
26
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mkdir -p /etc/docker")
27
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/docker")
26
28
  end
27
29
 
28
30
 
@@ -87,7 +89,7 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
87
89
  allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
88
90
 
89
91
  mock_write_docker_config(machine)
90
- mock_update_docker_client_config(machine, fixture)
92
+ mock_update_docker_client_config(machine)
91
93
 
92
94
  # update_docker_client_config mock
93
95
  allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
@@ -95,7 +97,7 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
95
97
  @docker_proxy = docker_proxy
96
98
  end
97
99
 
98
- context 'when /etc/docker/config.json has proxy configuration' do
100
+ context 'and when /etc/docker/config.json has proxy configuration' do
99
101
  before :each do
100
102
  fixture = fixture_file("docker_client_config_json_enabled_proxy")
101
103
  configure_docker_proxy(fixture)
@@ -140,12 +142,13 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
140
142
  allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
141
143
 
142
144
  allow(machine).to receive_message_chain(:communicate, :test).with("[ -f /etc/docker/config.json ]").and_return(true)
143
- allow(machine).to receive_message_chain(:communicate, :download).with("/etc/docker/config.json", "/tmp/vagrant-proxyconf-docker-config.json")
145
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/docker/config.json")
146
+ allow(machine).to receive_message_chain(:communicate, :download)
144
147
 
145
148
  docker_proxy.send(:docker_client_config_path)
146
149
  end
147
150
 
148
- it { is_expected.to eq "/tmp/vagrant-proxyconf-docker-config.json" }
151
+ it { expect(File.exists?(subject)).to eq true }
149
152
  end
150
153
 
151
154
  context "when /etc/docker/config.json does not exist" do
@@ -161,10 +164,9 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
161
164
  docker_proxy.send(:docker_client_config_path)
162
165
  end
163
166
 
164
- it { is_expected.to eq "/tmp/vagrant-proxyconf-docker-config.json" }
165
167
  it do
166
- expect(File.exists?("/tmp/vagrant-proxyconf-docker-config.json")).to eq true
167
- expect(File.read("/tmp/vagrant-proxyconf-docker-config.json")).to eq "{}"
168
+ expect(File.exists?(subject)).to eq true
169
+ expect(File.read(subject)).to eq "{}"
168
170
  end
169
171
  end
170
172
  end
@@ -226,7 +228,7 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
226
228
  allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
227
229
  allow(docker_proxy).to receive(:disabled?).and_return(true)
228
230
 
229
- mock_update_docker_client_config(machine, config_path)
231
+ mock_update_docker_client_config(machine)
230
232
 
231
233
  expected = JSON.pretty_generate(
232
234
  {
@@ -265,7 +267,7 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
265
267
  allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
266
268
  allow(docker_proxy).to receive(:disabled?).and_return(false)
267
269
 
268
- mock_update_docker_client_config(machine, config_path)
270
+ mock_update_docker_client_config(machine)
269
271
  expected = JSON.pretty_generate(
270
272
  {
271
273
  "proxies" => {
@@ -339,7 +341,7 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
339
341
  mock_write_docker_config(machine)
340
342
 
341
343
  # mock update_docker_client_config
342
- mock_update_docker_client_config(machine, config_path)
344
+ mock_update_docker_client_config(machine)
343
345
 
344
346
  docker_proxy.send(:unconfigure_machine)
345
347
  end
@@ -380,7 +382,7 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
380
382
  allow(docker_proxy).to receive(:disabled?).and_return(true)
381
383
 
382
384
  mock_write_docker_config(machine)
383
- mock_update_docker_client_config(machine, config_path)
385
+ mock_update_docker_client_config(machine)
384
386
 
385
387
  docker_proxy.send(:unconfigure_machine)
386
388
  end