Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.0 #181

Merged
merged 17 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ Style/EmptyLinesAroundBlockBody:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/IfUnlessModifier:
Enabled: false
12 changes: 0 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ Lint/RescueException:
Exclude:
- 'lib/vagrant-google/action/read_state.rb'

# Offense count: 1
Lint/RescueWithoutErrorClass:
Exclude:
- 'lib/vagrant-google/action/run_instance.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Expand Down Expand Up @@ -138,13 +133,6 @@ Naming/FileName:
- 'lib/vagrant-google.rb'
- 'vagrant-spec.config.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/HashEachMethods:
Exclude:
- 'lib/vagrant-google/action/sync_folders.rb'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand Down
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# 2.0.0 (Release Date TBD)
# 2.0.0 (March 2018)

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

# 1.0.0 (July 2017)
# 0.2.5 (October 2016)
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The maintainers for this plugin are @temikus(primary), @erjohnso(backup).
* Boot Google Compute Engine instances.
* SSH into the instances.
* Provision the instances with any built-in Vagrant provisioner.
* Minimal synced folder support via `rsync`.
* Synced folder support via Vagrant's
[rsync action](https://www.vagrantup.com/docs/synced-folders/rsync.html).
* Define zone-specific configurations so Vagrant can manage machines in
multiple zones.

Expand Down Expand Up @@ -88,7 +89,9 @@ Vagrant.configure("2") do |config|
google.google_project_id = "YOUR_GOOGLE_CLOUD_PROJECT_ID"
google.google_client_email = "YOUR_SERVICE_ACCOUNT_EMAIL_ADDRESS"
google.google_json_key_location = "/path/to/your/private-key.json"


google.image_family = 'ubuntu-1604-lts'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion ... it would be nice if the new image_family config option was also added to the Configuration section of the README.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanmalloy Nicely spotted! Thanks!

Added.


override.ssh.username = "USERNAME"
override.ssh.private_key_path = "~/.ssh/id_rsa"
#override.ssh.private_key_path = "~/.ssh/google_compute_engine"
Expand All @@ -99,10 +102,11 @@ end

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

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

Note that normally a lot of this boilerplate is encoded within the box file,
but the box file used for the quick start, the "google" box, has no
Expand Down Expand Up @@ -235,7 +239,7 @@ Vagrant.configure("2") do |config|

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

## Synced Folders

There is minimal support for synced folders. Upon `vagrant up`,
`vagrant reload`, and `vagrant provision`, the Google provider will use
`rsync` (if available) to uni-directionally sync the folder to the remote
machine over SSH.

This is good enough for all built-in Vagrant provisioners (`shell`, `chef`, and
`puppet`) to work!
Since plugin version 2.0, this is implemented via built-in `SyncedFolders` action.
See Vagrant's [rsync action](https://www.vagrantup.com/docs/synced-folders/rsync.html)
documentation for more info.

## Development

Expand Down
1 change: 1 addition & 0 deletions example_boxes/gce-test/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Vagrant.configure("2") do |config|
override.ssh.username = ENV['GOOGLE_SSH_USER']
override.ssh.private_key_path = ENV['GOOGLE_SSH_KEY_LOCATION']
end
_google.image_family = "debian-9"
end
end
Binary file modified google-test.box
Binary file not shown.
Binary file modified google.box
Binary file not shown.
7 changes: 3 additions & 4 deletions lib/vagrant-google/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def self.action_provision
end

b2.use Provision
b2.use SyncFolders
b2.use SyncedFolders
end
end
end
Expand Down Expand Up @@ -134,7 +134,7 @@ def self.action_up
b1.use Call, IsTerminated do |env2, b2|
if env2[:result]
b2.use Provision
b2.use SyncFolders
b2.use SyncedFolders
b2.use WarnNetworks
b2.use WarnSshKeys
b2.use StartInstance
Expand All @@ -145,7 +145,7 @@ def self.action_up
end
else
b1.use Provision
b1.use SyncFolders
b1.use SyncedFolders
b1.use WarnNetworks
b1.use WarnSshKeys
b1.use RunInstance
Expand Down Expand Up @@ -186,7 +186,6 @@ def self.action_reload
autoload :RunInstance, action_root.join("run_instance")
autoload :StartInstance, action_root.join("start_instance")
autoload :StopInstance, action_root.join("stop_instance")
autoload :SyncFolders, action_root.join("sync_folders")
autoload :TerminateInstance, action_root.join("terminate_instance")
autoload :TimedProvision, action_root.join("timed_provision")
autoload :WarnNetworks, action_root.join("warn_networks")
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-google/action/assign_instance_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def call(env)
# Add the machine to instance group
env[:ui].info(I18n.t("vagrant_google.instance_group_add"))

# Fixup with add_instance_group_instance after adding to fog
# See https://github.com/fog/fog-google/issues/308
response = env[:google_compute].add_instance_group_instances(
instance_group_name,
zone,
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-google/action/connect_google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def call(env)

# If the key is not found, try expanding from root location (see #159)
def find_key(location, env)
if File.file?(location)
return location
if File.file?(File.expand_path(location))
return File.expand_path(location)
else
return File.expand_path(location, env[:root_path])
end
Expand Down
6 changes: 3 additions & 3 deletions lib/vagrant-google/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
env[:ui].info(" -- Subnetwork: #{subnetwork}") if subnetwork
env[:ui].info(" -- Metadata: '#{metadata}'")
env[:ui].info(" -- Labels: '#{labels}'")
env[:ui].info(" -- Tags: '#{tags}'")
env[:ui].info(" -- Network tags: '#{tags}'")
env[:ui].info(" -- IP Forward: #{can_ip_forward}")
env[:ui].info(" -- Use private IP: #{use_private_ip}")
env[:ui].info(" -- External IP: #{external_ip}")
Expand Down Expand Up @@ -138,8 +138,8 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
zone_name: zone,
source_image: image
)
disk_created_by_vagrant = true
disk.wait_for { disk.ready? }
disk_created_by_vagrant = true
else
disk = env[:google_compute].disks.get(disk_name, zone)
if disk.nil?
Expand Down Expand Up @@ -210,7 +210,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
end
end
@logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
env[:ui].info(I18n.t("vagrant_google.ready_ssh"))
env[:ui].info(I18n.t("vagrant_google.ready_ssh")) unless env[:interrupted]
end

# Terminate the instance if we were interrupted
Expand Down
106 changes: 0 additions & 106 deletions lib/vagrant-google/action/sync_folders.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/vagrant-google/action/terminate_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def call(env)

# Destroy the server and remove the tracking ID
# destroy() is called with 'false' to disable asynchronous execution.
# TODO: Add "override_async" option for faster test
# TODO: Look at fog logic for possibly making sync faster
env[:ui].info(I18n.t("vagrant_google.terminating"))
server.destroy(false) unless server.nil?
env[:machine].id = nil
Expand Down
16 changes: 6 additions & 10 deletions lib/vagrant-google/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def initialize(zone_specific=false)
# image and machine type name for zones. Example:
#
# google.zone_config "us-central1-f" do |zone|
# zone.image = "debian-7-wheezy-v20150127"
# zone.image = "ubuntu-1604-xenial-v20180306"
# zone.machine_type = "n1-standard-4"
# end
#
Expand Down Expand Up @@ -259,14 +259,8 @@ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
@google_json_key_location = ENV['GOOGLE_JSON_KEY_LOCATION'] if @google_json_key_location == UNSET_VALUE
@google_project_id = ENV['GOOGLE_PROJECT_ID'] if @google_project_id == UNSET_VALUE

# Image must be nil, since we can't default that
if @image == UNSET_VALUE
if @image_family == UNSET_VALUE
@image = "debian-8-jessie-v20160511"
else
@image = nil
end
end
# Default image is nil
@image = nil if @image == UNSET_VALUE

# Default image family is nil
@image_family = nil if @image_family == UNSET_VALUE
Expand Down Expand Up @@ -361,14 +355,16 @@ def validate(machine)
if @zone
config = get_zone_config(@zone)

# TODO: Check why provider-level settings are validated in the zone config
errors << I18n.t("vagrant_google.config.google_project_id_required") if \
config.google_project_id.nil?
errors << I18n.t("vagrant_google.config.google_client_email_required") if \
config.google_client_email.nil?
errors << I18n.t("vagrant_google.config.google_key_location_required") if \
config.google_json_key_location.nil?
errors << I18n.t("vagrant_google.config.private_key_missing") unless \
File.exist?(config.google_json_key_location.to_s)
File.exist?(File.expand_path(config.google_json_key_location.to_s)) or
File.exist?(File.expand_path(config.google_json_key_location.to_s, machine.env.root_path))

if config.preemptible
errors << I18n.t("vagrant_google.config.auto_restart_invalid_on_preemptible") if \
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-google/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module Google
class Provider < Vagrant.plugin("2", :provider)
def initialize(machine)
@machine = machine

# Turn off NFS/SMB functionality by default, so machine always uses
# rsync, see https://github.com/mitchellh/vagrant-google/issues/94
@machine.config.nfs.functional = false unless ENV.has_key?('VAGRANT_GOOGLE_ENABLE_NFS')
@machine.config.smb.functional = false unless ENV.has_key?('VAGRANT_GOOGLE_ENABLE_SMB')
end

def action(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-google/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# limitations under the License.
module VagrantPlugins
module Google
VERSION = "1.0.0".freeze
VERSION = "2.0.0".freeze
end
end
2 changes: 1 addition & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ en:
name_required: |-
An instance name must be specified via "name" option.
image_required: |-
An image must be specified via "image" option.
An image must be specified via "image" or "image_family" option.
google_key_location_required: |-
A private key pathname is required via:
"google_json_key_location" (for JSON keys)
Expand Down
Loading