Skip to content

Commit 234bbad

Browse files
authored
Merge pull request #181 from Temikus/release_2.0
Release 2.0
2 parents a86df95 + 37b93a1 commit 234bbad

26 files changed

+101
-183
lines changed

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ Style/EmptyLinesAroundBlockBody:
1111
Enabled: false
1212

1313
Style/StringLiterals:
14+
Enabled: false
15+
16+
Style/IfUnlessModifier:
1417
Enabled: false

.rubocop_todo.yml

-12
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ Lint/RescueException:
7474
Exclude:
7575
- 'lib/vagrant-google/action/read_state.rb'
7676

77-
# Offense count: 1
78-
Lint/RescueWithoutErrorClass:
79-
Exclude:
80-
- 'lib/vagrant-google/action/run_instance.rb'
81-
8277
# Offense count: 1
8378
# Cop supports --auto-correct.
8479
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
@@ -138,13 +133,6 @@ Naming/FileName:
138133
- 'lib/vagrant-google.rb'
139134
- 'vagrant-spec.config.rb'
140135

141-
# Offense count: 1
142-
# Cop supports --auto-correct.
143-
# Configuration parameters: AutoCorrect.
144-
Performance/HashEachMethods:
145-
Exclude:
146-
- 'lib/vagrant-google/action/sync_folders.rb'
147-
148136
# Offense count: 4
149137
# Cop supports --auto-correct.
150138
# Configuration parameters: EnforcedStyle, SupportedStyles.

CHANGELOG.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
# 2.0.0 (Release Date TBD)
1+
# 2.0.0 (March 2018)
22

33
* Update to use fog-google gem v1
4-
* Drop support for configuration option `google_key_location`(GCP P12 key)
5-
* Add new configuration option `labels` for setting [labels](https://cloud.google.com/compute/docs/labeling-resources) on GCE instances
4+
* Add new configuration option `labels` for setting [labels](https://cloud.google.com/compute/docs/labeling-resources)
5+
on GCE instances
6+
* Fix disk cleanup issue causing the disk to be marked as created before insertion
7+
* Test environment fixups to avoid 'Encoded files can't be read outside of the Vagrant installer.'
8+
* Breaking changes:
9+
* Drop support for configuration option `google_key_location`(GCP P12 key)
10+
* `image` parameter no longer defaults to an arbitrary image and must be
11+
specified at runtime
12+
* Rsync behavior now consistent with Vagrant's default, removed old rsync code
613

714
# 1.0.0 (July 2017)
815
# 0.2.5 (October 2016)

README.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ The maintainers for this plugin are @temikus(primary), @erjohnso(backup).
1818
* Boot Google Compute Engine instances.
1919
* SSH into the instances.
2020
* Provision the instances with any built-in Vagrant provisioner.
21-
* Minimal synced folder support via `rsync`.
21+
* Synced folder support via Vagrant's
22+
[rsync action](https://www.vagrantup.com/docs/synced-folders/rsync.html).
2223
* Define zone-specific configurations so Vagrant can manage machines in
2324
multiple zones.
2425

@@ -88,7 +89,9 @@ Vagrant.configure("2") do |config|
8889
google.google_project_id = "YOUR_GOOGLE_CLOUD_PROJECT_ID"
8990
google.google_client_email = "YOUR_SERVICE_ACCOUNT_EMAIL_ADDRESS"
9091
google.google_json_key_location = "/path/to/your/private-key.json"
91-
92+
93+
google.image_family = 'ubuntu-1604-lts'
94+
9295
override.ssh.username = "USERNAME"
9396
override.ssh.private_key_path = "~/.ssh/id_rsa"
9497
#override.ssh.private_key_path = "~/.ssh/google_compute_engine"
@@ -99,10 +102,11 @@ end
99102

100103
And then run `vagrant up --provider=google`.
101104

102-
This will start a Debian 8 (Jessie) instance in the `us-central1-f` zone,
103-
with an `n1-standard-1` machine, and the `"default"` network within your
104-
project. And assuming your SSH information (see below) was filled in properly
105-
within your Vagrantfile, SSH and provisioning will work as well.
105+
This will start a latest version of Ubuntu 16.04 LTS instance in the
106+
`us-central1-f` zone, with an `n1-standard-1` machine, and the `"default"`
107+
network within your project. And assuming your SSH information (see below) was
108+
filled in properly within your Vagrantfile, SSH and provisioning will work as
109+
well.
106110

107111
Note that normally a lot of this boilerplate is encoded within the box file,
108112
but the box file used for the quick start, the "google" box, has no
@@ -171,6 +175,9 @@ This provider exposes quite a few provider-specific configuration options:
171175
* `google_project_id` - The Project ID for your Google Cloud Platform account.
172176
(Can also be configured with `GOOGLE_PROJECT_ID` environment variable.)
173177
* `image` - The image name to use when booting your instance.
178+
* `image_family` - Specify an "image family" to pull the latest image from. For example: `centos-7`
179+
will pull the most recent CentOS 7 image. For more info, refer to
180+
[Google Image documentation](https://cloud.google.com/compute/docs/images#image_families).
174181
* `instance_group` - Unmanaged instance group to add the machine to. If one
175182
doesn't exist it will be created.
176183
* `instance_ready_timeout` - The number of seconds to wait for the instance
@@ -235,7 +242,7 @@ Vagrant.configure("2") do |config|
235242

236243
google.zone_config "us-central1-f" do |zone1f|
237244
zone1f.name = "testing-vagrant"
238-
zone1f.image = "debian-8-jessie-v20160923"
245+
zone1f.image = "debian-8-jessie-v20180307"
239246
zone1f.machine_type = "n1-standard-4"
240247
zone1f.zone = "us-central1-f"
241248
zone1f.metadata = {'custom' => 'metadata', 'testing' => 'foobarbaz'}
@@ -261,13 +268,9 @@ emit a warning, but will otherwise boot the GCE machine.
261268

262269
## Synced Folders
263270

264-
There is minimal support for synced folders. Upon `vagrant up`,
265-
`vagrant reload`, and `vagrant provision`, the Google provider will use
266-
`rsync` (if available) to uni-directionally sync the folder to the remote
267-
machine over SSH.
268-
269-
This is good enough for all built-in Vagrant provisioners (`shell`, `chef`, and
270-
`puppet`) to work!
271+
Since plugin version 2.0, this is implemented via built-in `SyncedFolders` action.
272+
See Vagrant's [rsync action](https://www.vagrantup.com/docs/synced-folders/rsync.html)
273+
documentation for more info.
271274

272275
## Development
273276

example_boxes/gce-test/Vagrantfile

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ Vagrant.configure("2") do |config|
2020
override.ssh.username = ENV['GOOGLE_SSH_USER']
2121
override.ssh.private_key_path = ENV['GOOGLE_SSH_KEY_LOCATION']
2222
end
23+
_google.image_family = "debian-9"
2324
end
2425
end

google-test.box

27 Bytes
Binary file not shown.

google.box

3 Bytes
Binary file not shown.

lib/vagrant-google/action.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def self.action_provision
6666
end
6767

6868
b2.use Provision
69-
b2.use SyncFolders
69+
b2.use SyncedFolders
7070
end
7171
end
7272
end
@@ -134,7 +134,7 @@ def self.action_up
134134
b1.use Call, IsTerminated do |env2, b2|
135135
if env2[:result]
136136
b2.use Provision
137-
b2.use SyncFolders
137+
b2.use SyncedFolders
138138
b2.use WarnNetworks
139139
b2.use WarnSshKeys
140140
b2.use StartInstance
@@ -145,7 +145,7 @@ def self.action_up
145145
end
146146
else
147147
b1.use Provision
148-
b1.use SyncFolders
148+
b1.use SyncedFolders
149149
b1.use WarnNetworks
150150
b1.use WarnSshKeys
151151
b1.use RunInstance
@@ -186,7 +186,6 @@ def self.action_reload
186186
autoload :RunInstance, action_root.join("run_instance")
187187
autoload :StartInstance, action_root.join("start_instance")
188188
autoload :StopInstance, action_root.join("stop_instance")
189-
autoload :SyncFolders, action_root.join("sync_folders")
190189
autoload :TerminateInstance, action_root.join("terminate_instance")
191190
autoload :TimedProvision, action_root.join("timed_provision")
192191
autoload :WarnNetworks, action_root.join("warn_networks")

lib/vagrant-google/action/assign_instance_groups.rb

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def call(env)
5656
# Add the machine to instance group
5757
env[:ui].info(I18n.t("vagrant_google.instance_group_add"))
5858

59+
# Fixup with add_instance_group_instance after adding to fog
60+
# See https://github.com/fog/fog-google/issues/308
5961
response = env[:google_compute].add_instance_group_instances(
6062
instance_group_name,
6163
zone,

lib/vagrant-google/action/connect_google.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def call(env)
4747

4848
# If the key is not found, try expanding from root location (see #159)
4949
def find_key(location, env)
50-
if File.file?(location)
51-
return location
50+
if File.file?(File.expand_path(location))
51+
return File.expand_path(location)
5252
else
5353
return File.expand_path(location, env[:root_path])
5454
end

lib/vagrant-google/action/run_instance.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
8181
env[:ui].info(" -- Subnetwork: #{subnetwork}") if subnetwork
8282
env[:ui].info(" -- Metadata: '#{metadata}'")
8383
env[:ui].info(" -- Labels: '#{labels}'")
84-
env[:ui].info(" -- Tags: '#{tags}'")
84+
env[:ui].info(" -- Network tags: '#{tags}'")
8585
env[:ui].info(" -- IP Forward: #{can_ip_forward}")
8686
env[:ui].info(" -- Use private IP: #{use_private_ip}")
8787
env[:ui].info(" -- External IP: #{external_ip}")
@@ -138,8 +138,8 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
138138
zone_name: zone,
139139
source_image: image
140140
)
141-
disk_created_by_vagrant = true
142141
disk.wait_for { disk.ready? }
142+
disk_created_by_vagrant = true
143143
else
144144
disk = env[:google_compute].disks.get(disk_name, zone)
145145
if disk.nil?
@@ -210,7 +210,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
210210
end
211211
end
212212
@logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
213-
env[:ui].info(I18n.t("vagrant_google.ready_ssh"))
213+
env[:ui].info(I18n.t("vagrant_google.ready_ssh")) unless env[:interrupted]
214214
end
215215

216216
# Terminate the instance if we were interrupted

lib/vagrant-google/action/sync_folders.rb

-106
This file was deleted.

lib/vagrant-google/action/terminate_instance.rb

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def call(env)
2828

2929
# Destroy the server and remove the tracking ID
3030
# destroy() is called with 'false' to disable asynchronous execution.
31+
# TODO: Add "override_async" option for faster test
32+
# TODO: Look at fog logic for possibly making sync faster
3133
env[:ui].info(I18n.t("vagrant_google.terminating"))
3234
server.destroy(false) unless server.nil?
3335
env[:machine].id = nil

lib/vagrant-google/config.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def initialize(zone_specific=false)
196196
# image and machine type name for zones. Example:
197197
#
198198
# google.zone_config "us-central1-f" do |zone|
199-
# zone.image = "debian-7-wheezy-v20150127"
199+
# zone.image = "ubuntu-1604-xenial-v20180306"
200200
# zone.machine_type = "n1-standard-4"
201201
# end
202202
#
@@ -259,14 +259,8 @@ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
259259
@google_json_key_location = ENV['GOOGLE_JSON_KEY_LOCATION'] if @google_json_key_location == UNSET_VALUE
260260
@google_project_id = ENV['GOOGLE_PROJECT_ID'] if @google_project_id == UNSET_VALUE
261261

262-
# Image must be nil, since we can't default that
263-
if @image == UNSET_VALUE
264-
if @image_family == UNSET_VALUE
265-
@image = "debian-8-jessie-v20160511"
266-
else
267-
@image = nil
268-
end
269-
end
262+
# Default image is nil
263+
@image = nil if @image == UNSET_VALUE
270264

271265
# Default image family is nil
272266
@image_family = nil if @image_family == UNSET_VALUE
@@ -361,14 +355,16 @@ def validate(machine)
361355
if @zone
362356
config = get_zone_config(@zone)
363357

358+
# TODO: Check why provider-level settings are validated in the zone config
364359
errors << I18n.t("vagrant_google.config.google_project_id_required") if \
365360
config.google_project_id.nil?
366361
errors << I18n.t("vagrant_google.config.google_client_email_required") if \
367362
config.google_client_email.nil?
368363
errors << I18n.t("vagrant_google.config.google_key_location_required") if \
369364
config.google_json_key_location.nil?
370365
errors << I18n.t("vagrant_google.config.private_key_missing") unless \
371-
File.exist?(config.google_json_key_location.to_s)
366+
File.exist?(File.expand_path(config.google_json_key_location.to_s)) or
367+
File.exist?(File.expand_path(config.google_json_key_location.to_s, machine.env.root_path))
372368

373369
if config.preemptible
374370
errors << I18n.t("vagrant_google.config.auto_restart_invalid_on_preemptible") if \

lib/vagrant-google/provider.rb

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ module Google
1919
class Provider < Vagrant.plugin("2", :provider)
2020
def initialize(machine)
2121
@machine = machine
22+
23+
# Turn off NFS/SMB functionality by default, so machine always uses
24+
# rsync, see https://github.com/mitchellh/vagrant-google/issues/94
25+
@machine.config.nfs.functional = false unless ENV.has_key?('VAGRANT_GOOGLE_ENABLE_NFS')
26+
@machine.config.smb.functional = false unless ENV.has_key?('VAGRANT_GOOGLE_ENABLE_SMB')
2227
end
2328

2429
def action(name)

lib/vagrant-google/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
# limitations under the License.
1414
module VagrantPlugins
1515
module Google
16-
VERSION = "1.0.0".freeze
16+
VERSION = "2.0.0".freeze
1717
end
1818
end

0 commit comments

Comments
 (0)