diff --git a/.gitignore b/.gitignore index bb7bfae..0cb6eeb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ /pkg/ /spec/reports/ /tmp/ -.vagrant/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..04a6796 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: ruby +sudo: required +services: +- docker +rvm: +- 2.3 +env: +- IMAGE=centos:7 +- IMAGE=debian:jessie +bundler_args: "--jobs=4" +cache: bundler +before_install: +- gem update --system --no-document +- gem install bundler --no-document +before_script: +- docker run --privileged -d --name container-with-service $IMAGE /sbin/init +script: +- bundle exec itamae docker --node-yaml=recipes/node.yml recipes/install.rb --container=container-with-service --tag itamae-plugin:latest +- DOCKER_CONTAINER=container-with-service bundle exec rspec +branches: + only: + - master +notifications: + email: false + slack: + secure: M93HeWW+fQk+PrzI2mdtnlVkpiMVfQcfujFXl76ly0EtLS3V9p5KKHSyduQ2t7j/KOoRVF+86sEdPZJg16Ha+Y9pVE2oAs7SMv57rT9HaoQtzf5kZo64eCy63+iV+jUZ4U+NitrtNM1vELKyOsSgAq/KJblq9U67Wto3lOsRec7rskwlkjRwqV4TQElqbA1h4oyWyQG0SMKNnmKYV6TFC0/UNjnYLkxNY3btcOB/PYURxfcwbZk9IU+7id2MM4uG8cBVGSjqOglYOWdpWxTCJpZ6YQGdmXsICa38D/Y3crEHLcUAE4DkaPHpTSVdjVm0kvQlUDuLOmHe+Eh4lm6zy8NCMpyO80/C74/OQQdQgDkohKFI8RX/BZnKdQAmZZf8cIdfe4pF4cZGB8mzGcBcpSBApQHEXZyuJF5u9clNW6+Cdo8jtps0c7Nqg3NWebpUCqwiTVR95Dr820sO6wtIlqlNB5AaNpHzefFoxd42pRm5+Ua9rDuoDuRyhVuWcUQCOn9ScqjhsY9q1UIRbgF03ILgDFmFTu/ClaJ7tOtAtE9n7IsibNf87o2Lz+rNQUrIzIZUo7vElrCub0RhgZFy9+sfplHyIR5CBD4y/9Ca6KoB06vzyb3Y7ElXwIifwbGQ3EQZdAWV6V7slVP83+ahHD+K0E+EPLzAqaDum0MkeqI= diff --git a/README.md b/README.md index 816f6ae..aad18ea 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,9 @@ Itamae plugin to install [Consul](https://www.consul.io/) with init scripts [![Gem Version](https://badge.fury.io/rb/itamae-plugin-recipe-consul.svg)](https://badge.fury.io/rb/itamae-plugin-recipe-consul) +[![Build Status](https://travis-ci.org/sue445/itamae-plugin-recipe-consul.svg?branch=master)](https://travis-ci.org/sue445/itamae-plugin-recipe-consul) [![Dependency Status](https://gemnasium.com/badges/github.com/sue445/itamae-plugin-recipe-consul.svg)](https://gemnasium.com/github.com/sue445/itamae-plugin-recipe-consul) -[![wercker status](https://app.wercker.com/status/1d28d36364b4f79161fc248c6c934072/m/master "wercker status")](https://app.wercker.com/project/bykey/1d28d36364b4f79161fc248c6c934072) - ## Supported * CentOS 6 (init.d) * CentOS 7+ (systemd) @@ -87,18 +86,16 @@ After checking out the repo, run `bin/setup` to install dependencies. You can al To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Testing -requirements [Vagrant](https://www.vagrantup.com/) +requirements [Docker](https://www.docker.com/) e.g) test on CentOS 7.0 ```sh -vagrant up centos7 -bundle exec rake itamae:centos7 -bundle exec rake spec:centos7 +docker run --privileged -d --name container-with-service centos:7 /sbin/init +bundle exec itamae docker --node-yaml=recipes/node.yml recipes/install.rb --container=container-with-service --tag itamae-plugin:latest +DOCKER_CONTAINER=container-with-service bundle exec rspec ``` -Avairable hosts are defined in [Vagrantfile](Vagrantfile) and [Rakefile](Rakefile) - ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/itamae-plugin-recipe-consul. diff --git a/Rakefile b/Rakefile index 03f3a67..2995527 100644 --- a/Rakefile +++ b/Rakefile @@ -1,30 +1 @@ require "bundler/gem_tasks" -require "rspec/core/rake_task" - -task :spec => "spec:all" - -HOSTS = %w(centos7 debian8) - -namespace :spec do - task :all => HOSTS - - HOSTS.each do |host| - desc "Run serverspec to #{host}" - RSpec::Core::RakeTask.new(host.to_sym) do |t| - puts "Running tests to #{host} ..." - ENV["TARGET_HOST"] = host - t.pattern = "spec/**/*_spec.rb" - end - end -end - -namespace :itamae do - task :all => HOSTS - - HOSTS.each do |host| - desc "Run itamae to #{host}" - task host do - sh "itamae ssh --host=#{host} --vagrant --node-yaml=recipes/node.yml recipes/install.rb" - end - end -end diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 29e519d..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,106 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# All Vagrant configuration is done below. The "2" in Vagrant.configure -# configures the configuration version (we support older styles for -# backwards compatibility). Please don't change it unless you know what -# you're doing. -Vagrant.configure(2) do |config| - config.vm.provider :digital_ocean do |provider, override| - override.vm.box = "digital_ocean" - override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box" - provider.token = ENV["DIGITALOCEAN_ACCESS_TOKEN"] - provider.region = "nyc3" - provider.size = "512MB" - - if ENV["WERCKER"] == "true" - override.vm.synced_folder ".", "/vagrant", disabled: true - provider.ssh_key_name = "wercker-#{ENV['WERCKER_GIT_REPOSITORY']}" - override.ssh.private_key_path = "~/.ssh/id_rsa.vagrant" - else - provider.ssh_key_name = "local" - override.ssh.private_key_path = "~/.ssh/id_rsa" - end - end - - config.vm.define :centos7 do |c| - c.vm.box = "centos/7" - c.vm.provider :digital_ocean do |provider, override| - provider.image = "centos-7-x64" - end - c.vm.hostname = 'itamae-consul-centos7' - c.vm.hostname += "-#{ENV['WERCKER_RUN_ID']}" if ENV['WERCKER_RUN_ID'] - end - - config.vm.define :debian8 do |c| - c.vm.box = "debian/jessie64" - c.vm.provider :digital_ocean do |provider, override| - provider.image = "debian-8-x64" - end - c.vm.hostname = 'itamae-consul-debian8' - c.vm.hostname += "-#{ENV['WERCKER_RUN_ID']}" if ENV['WERCKER_RUN_ID'] - end - - # The most common configuration options are documented and commented below. - # For a complete reference, please see the online documentation at - # https://docs.vagrantup.com. - - # Every Vagrant development environment requires a box. You can search for - # boxes at https://atlas.hashicorp.com/search. - # config.vm.box = "base" - - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network "forwarded_port", guest: 80, host: 8080 - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - # config.vm.network "private_network", ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider "virtualbox" do |vb| - # # Display the VirtualBox GUI when booting the machine - # vb.gui = true - # - # # Customize the amount of memory on the VM: - # vb.memory = "1024" - # end - # - # View the documentation for the provider you are using for more - # information on available options. - - # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies - # such as FTP and Heroku are also available. See the documentation at - # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| - # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" - # end - - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - # config.vm.provision "shell", inline: <<-SHELL - # sudo apt-get update - # sudo apt-get install -y apache2 - # SHELL -end diff --git a/ci/build.sh b/ci/build.sh deleted file mode 100755 index 3ada7fe..0000000 --- a/ci/build.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -xe - -readonly HOST=$1 - -vagrant up $HOST --provider=digital_ocean -bundle exec rake itamae:$HOST -bundle exec rake spec:$HOST diff --git a/ci/setup.sh b/ci/setup.sh deleted file mode 100755 index d969058..0000000 --- a/ci/setup.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -xe - -wget https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4_x86_64.rpm -rpm -i vagrant_1.8.4_x86_64.rpm -vagrant plugin install vagrant-digitalocean - -# NOTE: vagrant v1.8.4 depends on bundler v1.12.5 -# https://github.com/mitchellh/vagrant/blob/v1.8.4/vagrant.gemspec#L23 -gem uninstall bundler --all --force -gem install bundler -v 1.12.5 --no-document - - -mkdir -m 700 -p $HOME/.ssh - -######################### -# put ssh keys -set +x - -echo -e "$DIGITALOCEAN_KEY_PRIVATE" > $HOME/.ssh/id_rsa.vagrant -echo -e "$DIGITALOCEAN_KEY_PUBLIC" > $HOME/.ssh/id_rsa.vagrant.pub - -set -x -######################### - -chmod 600 $HOME/.ssh/id_rsa.vagrant diff --git a/itamae-plugin-recipe-consul.gemspec b/itamae-plugin-recipe-consul.gemspec index 8d56030..6d91f53 100644 --- a/itamae-plugin-recipe-consul.gemspec +++ b/itamae-plugin-recipe-consul.gemspec @@ -22,6 +22,7 @@ Gem::Specification.new do |spec| spec.add_dependency "itamae" spec.add_development_dependency "bundler" + spec.add_development_dependency "docker-api" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "serverspec" end diff --git a/recipes/install.rb b/recipes/install.rb index 7f6807a..d6309f3 100644 --- a/recipes/install.rb +++ b/recipes/install.rb @@ -1 +1,6 @@ +case node[:platform] +when "debian", "ubuntu" + execute "apt-get update" +end + include_recipe "consul" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a53a385..385127f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,41 +1,17 @@ require 'serverspec' -require 'net/ssh' -require 'tempfile' - -set :backend, :ssh - -if ENV['ASK_SUDO_PASSWORD'] - begin - require 'highline/import' - rescue LoadError - fail "highline is not available. Try installing it." - end - set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false } -else - set :sudo_password, ENV['SUDO_PASSWORD'] -end - -host = ENV['TARGET_HOST'] - -`vagrant up #{host}` - -config = Tempfile.new('', Dir.tmpdir) -config.write(`vagrant ssh-config #{host}`) -config.close - -options = Net::SSH::Config.for(host, [config.path]) +require 'docker' -options[:user] ||= Etc.getlogin +set :backend, :docker -set :host, options[:host_name] || host -set :ssh_options, options +set :docker_image, ENV['DOCKER_IMAGE'] +set :docker_container, ENV['DOCKER_CONTAINER'] # Disable sudo # set :disable_sudo, true # Set environment variables -# set :env, :LANG => 'C', :LC_MESSAGES => 'C' +# set :env, :LANG => 'C', :LC_MESSAGES => 'C' # Set PATH # set :path, '/sbin:/usr/local/sbin:$PATH' diff --git a/wercker.yml b/wercker.yml deleted file mode 100644 index 20e5072..0000000 --- a/wercker.yml +++ /dev/null @@ -1,61 +0,0 @@ -# This references the default Ruby container from -# the Docker Hub. -# https://registry.hub.docker.com/_/ruby/ -# If you want to use a specific version you would use a tag: -# ruby:2.2.2 -box: drecom/centos-ruby:2.3.1 -# You can also use services such as databases. Read more on our dev center: -# http://devcenter.wercker.com/docs/services/index.html -# services: - # - postgres - # http://devcenter.wercker.com/docs/services/postgresql.html - - # - mongodb - # http://devcenter.wercker.com/docs/services/mongodb.html - -default: &default - after-steps: - - script: - name: set variables - code: | - # NOTE: override .ruby-version in pretty-slack-notify - export RBENV_VERSION=2.3.1 - - - script: - name: remove all vms - code: vagrant destroy -f - - - wantedly/pretty-slack-notify: - webhook_url: $SLACK_WEBHOOK_URL - username: wercker_build - -build: - steps: - -build-centos7: - <<: *default - steps: - - script: - name: setup - code: ./ci/setup.sh - - - bundle-install: - jobs: 4 - - - script: - name: build CentOS 7 - code: ./ci/build.sh centos7 - -build-debian8: - <<: *default - steps: - - script: - name: setup - code: ./ci/setup.sh - - - bundle-install: - jobs: 4 - - - script: - name: build Debian 8 - code: ./ci/build.sh debian8