Skip to content

Instantly share code, notes, and snippets.

@ranjib
Last active January 3, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranjib/8469150 to your computer and use it in GitHub Desktop.
Save ranjib/8469150 to your computer and use it in GitHub Desktop.
./container.rb Container
name 'chef'
from 'ubuntu'
run 'apt-get install curl -y'
run 'curl -L https://www.opscode.com/chef/install.sh | sudo bash'
#!/usr/bin/env ruby
require 'lxc'
class ContainerFile
attr_reader :ct
def name(n)
@ct = LXC::Container.new(n)
end
def from(type)
ct.create(type)
ct.start
end
def run(command)
ret = ct.attach(wait:true) do
system(command)
end
raise "Faile to execute command #{command}" unless ret == 0
end
def cp(src, dest)
ct_dest = File.join(ct.config_path , ct.name, 'rootfs', dest)
FileUtils.cp_r(src, ct_dest)
end
end
if $0 == __FILE__
unless ARGV.empty?
f = ContainerFile.new
f.instance_eval(File.read(ARGV[0]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment