Commit ab1ef830 by Tsubasa Namiki

Remove EC2 provisioning

It was separated another repository.
https://github.com/namikingsoft/ec2docker
parent 9463b212
AWS_SSH_USERNAME="ec2-user"
AWS_SSH_KEY=${HOME}/.ssh/vagrant.pem
AWS_ACCESS_KEY_ID="REPLACE_ME"
AWS_SECRET_ACCESS_KEY="REPLACE_ME"
AWS_KEYPAIR_NAME="REPLACE_ME"
AWS_SECURITY_GROUP="REPLACE_ME"
--color
--format documentation
# A sample Gemfile
source "https://rubygems.org"
gem "rake"
gem "itamae"
gem "serverspec"
gem "parallel"
\ No newline at end of file
require 'rake'
require 'parallel'
require 'rspec/core/rake_task'
task :spec => 'spec:all'
task :provision => 'provision:all'
task :default => [:provision, :spec]
task :test do
`vagrant ssh-config`.scan /^Host (\w+)/ do |result|
host = result[0]
node = host
node = 'default' unless File.exist? "provision/nodes/#{node}.yaml"
p node
end
end
namespace :spec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end
task :all => targets
task :default => :all
targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end
namespace :provision do
task :default => :all
task :all do
commands = []
`vagrant ssh-config`.scan /^Host (\w+)/ do |result|
host = result[0]
node = "provision/nodes/#{node}.yaml"
node = "provision/nodes/default.yaml" unless File.exist? node
main = "provision/entrypoint.rb"
commands.push "itamae ssh --vagrant --host #{host} -y #{node} #{main}"
end
Parallel.each commands, in_threads: commands.length do |command|
sh command
end
end
end
# -*- mode: ruby -*-
# vi: set ft=ruby :
Dotenv.load
# change default provider to digital_ocean
ENV['VAGRANT_DEFAULT_PROVIDER'] = "aws"
# Vagrantfile API/syntax version.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :restyaboard, primary: true do |restyaboard|
restyaboard.vm.provider :aws do |provider, override|
override.vm.hostname = "restyaboard"
override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
override.vm.box = "aws"
override.ssh.username = ENV['AWS_SSH_USERNAME']
override.ssh.private_key_path = ENV['AWS_SSH_KEY']
override.ssh.pty = true
provider.access_key_id = ENV['AWS_ACCESS_KEY_ID']
provider.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
provider.keypair_name = ENV['AWS_KEYPAIR_NAME']
provider.region = "ap-northeast-1" # Tokyo
provider.availability_zone = "ap-northeast-1c" # Tokyo
provider.ami = "ami-cbf90ecb" # Tokyo Amazon Linux AMI 2015.03 (64-bit)
provider.instance_type = "t2.micro"
provider.instance_ready_timeout = 120
provider.terminate_on_shutdown = false
provider.security_groups = [ENV['AWS_SECURITY_GROUP']]
provider.tags = {"Name" => "restyaboard"}
# synced folder
override.vm.synced_folder ".", "/vagrant", disabled: true
end
end
end
package "docker" do
action :install
end
execute "install docker-compose" do
command "pip install -U docker-compose"
not_if "test -e /usr/local/bin/docker-compose"
end
link "/usr/bin/docker-compose" do
to "/usr/local/bin/docker-compose"
not_if "test -e /usr/bin/docker-compose"
end
service "docker" do
action [:enable, :start]
end
package 'ntp' do
action :install
end
service 'ntpd' do
action [:enable, :start]
end
execute "update yum repo" do
command <<-EOL
yum -y update
date >> /var/log/yum-update
EOL
not_if "test -e /var/log/yum-update"
end
package 'git'
\ No newline at end of file
execute "setting localtime" do
command <<-EOL
mv /etc/localtime /etc/localtime.org
ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
EOL
not_if "test -e /etc/localtime.org"
end
file "/etc/sysconfig/clock" do
action :edit
block do |content|
content.gsub! /^ZONE=.*$/, 'ZONE="Asia/Tokyo"'
content.gsub! /^UTC=true$/, ''
end
not_if "grep -e 'Tokyo' /etc/sysconfig/clock"
end
\ No newline at end of file
node["recipes"] = node["recipes"] || []
node["recipes"].each do |recipe|
include_recipe recipe
end
\ No newline at end of file
---
recipes:
- roles/base.rb
- roles/restyaboard.rb
\ No newline at end of file
include_recipe "../cookbooks/ntp/default.rb"
include_recipe "../cookbooks/timezone/default.rb"
include_recipe "../cookbooks/packages/default.rb"
\ No newline at end of file
include_recipe "../cookbooks/docker/default.rb"
directory "/dockerfile"
directory "/dockerfile/restyaboard"
remote_directory "/dockerfile/restyaboard" do
action :create
source "../../restyaboard"
end
remote_file "/dockerfile/docker-compose.yml" do
source "../../docker-compose.yml"
end
execute "docker up" do
command "COMPOSE_API_VERSION=1.18 docker-compose up -d"
cwd "/dockerfile"
not_if "docker ps | grep restyaboard"
end
\ No newline at end of file
require 'spec_helper'
describe service('docker') do
it { should be_enabled }
it { should be_running }
end
describe port(1234) do
it { should be_listening }
end
require 'serverspec'
require 'net/ssh'
require 'tempfile'
set :backend, :ssh
set :request_pty, true
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])
options[:user] ||= Etc.getlogin
set :host, options[:host_name] || host
set :ssh_options, options
# Disable sudo
# set :disable_sudo, true
# Set environment variables
# set :env, :LANG => 'C', :LC_MESSAGES => 'C'
# Set PATH
# set :path, '/sbin:/usr/local/sbin:$PATH'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment