building 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/building +50 -0
- data/lib/building.rb +99 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2edfe6caacb030124aec94fd0875516f4de2907f
|
4
|
+
data.tar.gz: 7b945e7cf653c8f8f9b522f0fe72e641e82cb498
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e6f7b9300342d0535cdbf068085e575cbd1789f18794890a334363d2361f4d821083967a0e32207c58753e6ed138d46ef8fa7a0b89afaf53d13b832fafcdee0
|
7
|
+
data.tar.gz: 5d09dc19ad2a6592ef4759b6e69c88d81b476ca1a8eec521ca6e741bb6e4b984616d58408e9abaebe8865293a9e01feaba7c2429a6a48298a92f59762299e824
|
data/bin/building
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "building"))
|
4
|
+
|
5
|
+
BUILDING_BANNER = "Usage: building [options] CONTAINER_NAME [TAG]"
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
opt_parser = OptionParser.new do |opts|
|
10
|
+
opts.banner = BUILDING_BANNER
|
11
|
+
|
12
|
+
opts.on("-o", "--output FIGCONF", "Output a fig configuration file") do |fig|
|
13
|
+
options[:fig] = fig
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on("-f", "--from FROM", "Change the default FROM (progrium/buildstep)") do |from|
|
17
|
+
options[:from] = from
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-d", "--dockerfile DOCKERFILE", "External Dockerfile to append to the building generated Dockerfile") do |file|
|
21
|
+
options[:file] = file
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-i", "--include CMD", "Extra commands during the image build") do |includes|
|
25
|
+
options[:includes] = includes
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-b", "--buildpack URL", "Add an external Buildpack URL") do |buildpack_url|
|
29
|
+
options[:buildpack_url] = buildpack_url
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("-p", "--p PORT", "Run the container after it is built on a certain port") do |port|
|
33
|
+
options[:port] = port
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
37
|
+
puts opts
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
opt_parser.parse!
|
44
|
+
|
45
|
+
if ARGV[0].nil?
|
46
|
+
puts opt_parser
|
47
|
+
exit -1
|
48
|
+
end
|
49
|
+
|
50
|
+
puts Building.convert(ARGV[0], ARGV[1], options)
|
data/lib/building.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Building
|
5
|
+
def self.convert(app_name, tag, options={})
|
6
|
+
Building.new(app_name, tag, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(app_name, tag, options={})
|
10
|
+
@app_name = app_name
|
11
|
+
@tag = tag || "latest"
|
12
|
+
@buildpack_url = options[:buildpack_url]
|
13
|
+
@includes = options[:includes]
|
14
|
+
@file = options[:file]
|
15
|
+
@from = options[:from]
|
16
|
+
@fig = options[:fig]
|
17
|
+
@port = options[:port]
|
18
|
+
|
19
|
+
create_dockerfile
|
20
|
+
build_container
|
21
|
+
|
22
|
+
if @port
|
23
|
+
run_container(@port)
|
24
|
+
else
|
25
|
+
explain_container(8080)
|
26
|
+
end
|
27
|
+
|
28
|
+
if @fig
|
29
|
+
build_fig
|
30
|
+
end
|
31
|
+
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_dockerfile
|
36
|
+
File.open("Dockerfile" , "w") do |file|
|
37
|
+
file << "FROM #{@from || "ctlc/buildstep:ubuntu13.10"}\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
if @buildpack_url
|
41
|
+
File.open("Dockerfile" , "a") do |file|
|
42
|
+
file << <<-eof
|
43
|
+
RUN git clone --depth 1 #{@buildpack_url} /build/buildpacks/#{@buildpack_url.split("/").last.sub(".git","")}
|
44
|
+
RUN echo #{@buildpack_url} >> /build/buildpacks.txt
|
45
|
+
eof
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if @includes
|
50
|
+
File.open("Dockerfile" , "a") do |file|
|
51
|
+
file << "RUN #{@includes}\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if @file
|
56
|
+
File.open("Dockerfile" , "a") do |file|
|
57
|
+
file << IO.read(@file)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
File.open("Dockerfile" , "a") do |file|
|
62
|
+
file << <<-eof
|
63
|
+
ADD . /app
|
64
|
+
RUN /build/builder
|
65
|
+
CMD /start web
|
66
|
+
eof
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_fig
|
71
|
+
File.open(@fig , "w") do |file|
|
72
|
+
file << <<-eof
|
73
|
+
web:
|
74
|
+
image: #{@app_name}:#{@tag}
|
75
|
+
command: /start web
|
76
|
+
environment:
|
77
|
+
PORT: #{@port || 8080}
|
78
|
+
ports:
|
79
|
+
- #{@port || 8080}
|
80
|
+
eof
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_container
|
85
|
+
pid = fork { exec "docker build -t #{@app_name}:#{@tag} ." }
|
86
|
+
Process.waitpid(pid)
|
87
|
+
end
|
88
|
+
|
89
|
+
def explain_container(port)
|
90
|
+
run = "docker run -d -p #{port} -e \"PORT=#{port}\" #{@app_name}:#{@tag}"
|
91
|
+
puts "\nTo run your app, try something like this:\n\n\t#{run}\n\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
def run_container(port)
|
95
|
+
run = "\ndocker run -d -p #{port} -e \"PORT=#{port}\" #{@app_name}:#{@tag}"
|
96
|
+
puts "#{run}"
|
97
|
+
exec run
|
98
|
+
end
|
99
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: building
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Carlson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Build a Docker container for any app using Heroku Buildpacks
|
14
|
+
email: lucas@rufy.com
|
15
|
+
executables:
|
16
|
+
- building
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/building
|
21
|
+
- lib/building.rb
|
22
|
+
homepage: http://github.com/CenturyLinkLabs/building
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements:
|
41
|
+
- bundler
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.2.0
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Build a Docker container for any app using Heroku Buildpacks
|
47
|
+
test_files: []
|