-
Notifications
You must be signed in to change notification settings - Fork 16
Config + hook approach for restarting docker #54
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
# vagrant-service-manager | ||
|
||
Provides setup information, including environment | ||
variables and certificates, required to access | ||
services provided by an [Atomic Developer Bundle | ||
(ADB)](https://github.com/projectatomic/adb-atomic-developer-bundle). | ||
This plugin makes it easier to use the ADB with host-based tools | ||
such as Eclipse and the docker and kubernetes CLI commands. | ||
Details on this usage pattern can be found in the [ADB | ||
Documentation](https://github.com/projectatomic/adb-atomic-developer-bundle/blob/master/docs/using.rst). | ||
This plugin provides setup information, including environment variables and certificates, required to access services provided by an [Atomic Developer Bundle (ADB)](https://github.com/projectatomic/adb-atomic-developer-bundle). This plugin makes it easier to use the ADB with host-based tools such as Eclipse and the docker and kubernetes CLI commands. Details on this usage pattern can be found in the [ADB Documentation](https://github.com/projectatomic/adb-atomic-developer-bundle/blob/master/docs/using.rst). | ||
|
||
##Objective | ||
|
||
|
@@ -27,16 +20,28 @@ producing complex, multi-container applications. | |
|
||
## Quick Start | ||
|
||
1. Install `vagrant-service-manager` plugin | ||
1. Install `vagrant-service-manager` plugin: | ||
|
||
vagrant plugin install vagrant-service-manager | ||
|
||
2. Get the [Vagrantfile](Vagrantfile) | ||
and start the ADB using `vagrant up`. | ||
[More](https://github.com/projectatomic/adb-atomic-developer-bundle/blob/master/docs/installing.rst) | ||
documentation on setting up ADB. | ||
2. Get a Vagrantfile for your box. Users of the | ||
[Atomic Developer Bundle (ADB)](https://github.com/projectatomic/adb-atomic-developer-bundle) should download a [Vagrantfile from the repository](https://github.com/projectatomic/adb-atomic-developer-bundle/tree/master/components). | ||
|
||
3. Run the plugin to get environment variables and certificates | ||
3. Enable your desired service(s) in [Vagrantfile](Vagrantfile) as: | ||
|
||
config.servicemanager.services = 'openshift' | ||
|
||
*Note* | ||
|
||
* `docker` is default service and does not require above configuration. | ||
* Enable multiple services as comma separated list. Eg: 'docker, openshift' | ||
|
||
5. Start the ADB using `vagrant up`. Users of the ADB may wish to consult the | ||
[Installation Documentation](https://github.com/projectatomic/adb-atomic-developer-bundle/blob/master/docs/installing.rst). | ||
|
||
6. Run the plugin to get environment variables and certificates: | ||
|
||
$ vagrant service-manager env docker | ||
|
||
# Copying TLS certificates to /home/nshaikh/vagrant/adb1.7/.vagrant/machines/default/virtualbox/docker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's update with newer output that shows the full command. Perhaps we should do a |
||
# Set the following environment variables to enable access to the | ||
|
@@ -48,7 +53,7 @@ documentation on setting up ADB. | |
# run following command to configure your shell: | ||
# eval "$(vagrant service-manager env docker)" | ||
|
||
4. Begin using your host-based tools. | ||
7. Begin using your host-based tools. | ||
|
||
## Exit codes | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
unless Vagrant.has_plugin?("vagrant-service-manager") | ||
$stderr.puts <<-MSG | ||
vagrant-service-manager plugin is required for projectatomic/adb. | ||
Kindly install the plugin: `$ vagrant plugin install vagrant-service-manager` | ||
MSG | ||
exit 126 | ||
end | ||
|
||
Vagrant.configure(2) do |config| | ||
|
||
config.vm.box = "projectatomic/adb" | ||
|
||
config.vm.network "private_network", type: "dhcp" | ||
|
||
# This is the default setup | ||
# config.servicemanager.services = 'docker' | ||
|
||
# Enable multiple services as comma separated list. | ||
# config.servicemanager.services = 'docker, openshift' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'set' | ||
|
||
module Vagrant | ||
module ServiceManager | ||
SERVICES = ['docker', 'openshift'] | ||
|
||
class Config < Vagrant.plugin('2', :config) | ||
attr_accessor :services | ||
|
||
DEFAULTS = { | ||
services: 'docker' | ||
} | ||
|
||
def initialize | ||
super | ||
@services = UNSET_VALUE | ||
end | ||
|
||
def finalize! | ||
DEFAULTS.each do |name, value| | ||
if instance_variable_get('@' + name.to_s) == UNSET_VALUE | ||
instance_variable_set '@' + name.to_s, value | ||
end | ||
end | ||
end | ||
|
||
def validate(machine) | ||
errors = _detected_errors | ||
errors.concat(validate_services) | ||
{ "servicemanager" => errors } | ||
end | ||
|
||
private | ||
|
||
def validate_services | ||
errors = [] | ||
|
||
unless is_supported_services? | ||
errors << "services should be subset of #{SERVICES.inspect}.}" | ||
end | ||
|
||
errors | ||
end | ||
|
||
def is_supported_services? | ||
@services.split(',').map(&:strip).to_set.subset?(SERVICES.to_set) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Loads all services | ||
Dir["#{File.dirname(__FILE__)}/services/*.rb"].each { |f| require_relative f } | ||
|
||
module Vagrant | ||
module ServiceManager | ||
class Plugin < Vagrant.plugin('2') | ||
|
@@ -8,6 +11,15 @@ class Plugin < Vagrant.plugin('2') | |
require_relative 'command' | ||
Command | ||
end | ||
|
||
config 'servicemanager' do | ||
require_relative 'config' | ||
Config | ||
end | ||
|
||
action_hook(:servicemanager, :machine_action_up) do |hook| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should only run when a config.service-manager line is in the Vagrantfile, otherwise it runs on every box I start whether it should or not. The only other way is to detect ADB and CDK which we can't do afaik right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After adding the guest detection capability, this is resolved. Now, it will only run against supported [ADB / CDK] boxes and |
||
hook.append(Service::Docker) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Vagrant | ||
module ServiceManager | ||
SUPPORTED_BOXES = ['adb', 'cdk'] | ||
|
||
module Service | ||
class Docker | ||
def initialize(app, env) | ||
@app = app | ||
@machine = env[:machine] | ||
@ui = env[:ui] | ||
end | ||
|
||
def call(env) | ||
if SUPPORTED_BOXES.include? @machine.guest.capability(:flavor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this inside of the docker hook and not at a higher level? This structure means that every time we add a new service we have to write this same code again. I am going to LGTM this, but I am opening an issue to get this fixed as we need to get openshift, etc. added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed @bexelbie . Will work on it. |
||
command = "sudo rm /etc/docker/ca.pem && sudo systemctl restart docker" | ||
@machine.communicate.execute(command) do |type, data| | ||
if type == :stderr | ||
@ui.error(data) | ||
exit 126 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good! |
||
end | ||
end | ||
end | ||
|
||
@app.call(env) | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module VagrantPlugins | ||
module GuestRedHat | ||
module Cap | ||
class Flavor | ||
def self.flavor(machine) | ||
machine.communicate.sudo("grep VARIANT_ID /etc/os-release") do |type, data| | ||
if type == :stderr | ||
@env.ui.error(data) | ||
exit 126 | ||
end | ||
return data.chomp.gsub(/"/, '').split("=").last | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'vagrant' | ||
|
||
module VagrantPlugins | ||
module GuestRedHat | ||
class Plugin < Vagrant.plugin('2') | ||
guest_capability('redhat', 'flavor') do | ||
require_relative 'cap/flavor' | ||
Cap::Flavor | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "service-manager" to match the plugin name, imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bexelbie : Here, it is not accepting
-
based name.