Class: Building
- Inherits:
-
Object
- Object
- Building
- Defined in:
- lib/building.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_container ⇒ Object
- #build_fig ⇒ Object
- #create_dockerfile ⇒ Object
- #explain_container(port) ⇒ Object
-
#initialize(app_name, tag, options = {}) ⇒ Building
constructor
A new instance of Building.
- #run_container(port) ⇒ Object
Constructor Details
#initialize(app_name, tag, options = {}) ⇒ Building
Returns a new instance of Building.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/building.rb', line 9 def initialize(app_name, tag, ={}) @app_name = app_name @tag = tag || "latest" @buildpack_url = [:buildpack_url] @includes = [:includes] @file = [:file] @from = [:from] @fig = [:fig] @port = [:port] create_dockerfile build_container if @port run_container(@port) else explain_container(8080) end if @fig build_fig end exit 0 end |
Class Method Details
Instance Method Details
#build_container ⇒ Object
84 85 86 87 |
# File 'lib/building.rb', line 84 def build_container pid = fork { exec "docker build -t #{@app_name}:#{@tag} ." } Process.waitpid(pid) end |
#build_fig ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/building.rb', line 70 def build_fig File.open(@fig , "w") do |file| file << <<-eof web: image: #{@app_name}:#{@tag} command: /start web environment: PORT: #{@port || 8080} ports: - #{@port || 8080} eof end end |
#create_dockerfile ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/building.rb', line 35 def create_dockerfile File.open("Dockerfile" , "w") do |file| file << "FROM #{@from || "ctlc/buildstep:ubuntu13.10"}\n" end if @buildpack_url File.open("Dockerfile" , "a") do |file| file << <<-eof RUN git clone --depth 1 #{@buildpack_url} /build/buildpacks/#{@buildpack_url.split("/").last.sub(".git","")} RUN echo #{@buildpack_url} >> /build/buildpacks.txt eof end end if @includes File.open("Dockerfile" , "a") do |file| file << "RUN #{@includes}\n" end end if @file File.open("Dockerfile" , "a") do |file| file << IO.read(@file) end end File.open("Dockerfile" , "a") do |file| file << <<-eof ADD . /app RUN /build/builder CMD /start web eof end end |
#explain_container(port) ⇒ Object
89 90 91 92 |
# File 'lib/building.rb', line 89 def explain_container(port) run = "docker run -d -p #{port} -e \"PORT=#{port}\" #{@app_name}:#{@tag}" puts "\nTo run your app, try something like this:\n\n\t#{run}\n\n" end |
#run_container(port) ⇒ Object
94 95 96 97 98 |
# File 'lib/building.rb', line 94 def run_container(port) run = "\ndocker run -d -p #{port} -e \"PORT=#{port}\" #{@app_name}:#{@tag}" puts "#{run}" exec run end |