./container.rb Container
Last active
January 3, 2016 13:19
-
-
Save ranjib/8469150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name 'chef' | |
from 'ubuntu' | |
run 'apt-get install curl -y' | |
run 'curl -L https://www.opscode.com/chef/install.sh | sudo bash' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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