Commit cf80709c authored by Terence Lee's avatar Terence Lee

extract the buildpack into its own image

parent d0ea6f40
FROM heroku/cedar:14
RUN useradd -d /app -m app
USER app
WORKDIR /buildpack
COPY bin/ /buildpack/bin/
COPY scripts/ /buildpack/scripts/
RUN /buildpack/bin/compile /app
ENV HOME /app
ENV PORT 3000
EXPOSE 3000
ONBUILD WORKDIR /app/
ONBUILD COPY . /app/
ONBUILD CMD /app/bin/boot
FROM heroku/cedar:14 FROM hone/static:14
RUN useradd -d /app -m app
USER app
WORKDIR /app
ENV HOME /app
ENV PORT 3000
RUN mkdir -p /app
COPY . /app/
RUN /app/buildpack/bin/compile /app
EXPOSE 3000
CMD /app/bin/boot
require_relative "spec_helper" require_relative "spec_helper"
require_relative "support/buildpack_runner" require_relative "support/app_runner"
require_relative "support/buildpack_builder"
describe "Simple" do describe "Simple" do
let(:bp) { BuildpackRunner.new("hello_world") } let(:debug) { false }
let(:app) { AppRunner.new("hello_world", debug) }
before { BuildpackBuilder.new(debug) }
after do after do
bp.destroy app.destroy
end end
it "should serve out of public_html by default" do it "should serve out of public_html by default" do
response = bp.get("/") response = app.get("/")
expect(response.code).to eq("200") expect(response.code).to eq("200")
expect(response.body.chomp).to eq("Hello World") expect(response.body.chomp).to eq("Hello World")
end end
......
...@@ -5,7 +5,7 @@ require "json" ...@@ -5,7 +5,7 @@ require "json"
require "docker" require "docker"
require_relative "path_helper" require_relative "path_helper"
class BuildpackRunner class AppRunner
include PathHelper include PathHelper
HOST_PORT = "3000" HOST_PORT = "3000"
...@@ -15,14 +15,13 @@ class BuildpackRunner ...@@ -15,14 +15,13 @@ class BuildpackRunner
def initialize(fixture, debug = false) def initialize(fixture, debug = false)
@debug = debug @debug = debug
@image = build_image(fixture) @image = build_image(fixture)
puts @image.id if @debug
@container = Docker::Container.create( @container = Docker::Container.create(
'Image' => @image.id, 'Image' => @image.id,
'HostConfig' => { 'HostConfig' => {
'PortBindings' => { 'PortBindings' => {
"#{CONTAINER_PORT}/tcp" => [{ "#{CONTAINER_PORT}/tcp" => [{
"HostIp" => HOST_IP, "HostIp" => HOST_IP,
"HostPort": HOST_PORT, "HostPort": HOST_PORT,
}] }]
} }
} }
...@@ -59,8 +58,6 @@ class BuildpackRunner ...@@ -59,8 +58,6 @@ class BuildpackRunner
image = nil image = nil
Dir.mktmpdir do |tmpdir| Dir.mktmpdir do |tmpdir|
fixture_path = fixtures_path(fixture)
dest_bp_dir = Pathname.new(File.join(tmpdir, "buildpack"))
print_output = print_output =
if @debug if @debug
-> (chunk) { -> (chunk) {
...@@ -71,11 +68,8 @@ class BuildpackRunner ...@@ -71,11 +68,8 @@ class BuildpackRunner
-> (chunk) { nil } -> (chunk) { nil }
end end
FileUtils.mkdir_p(dest_bp_dir) FileUtils.cp_r(Dir.glob(fixtures_path(fixture) + "*"), tmpdir)
FileUtils.cp_r(buildpack_path("bin"), dest_bp_dir) image = Docker::Image.build_from_dir(tmpdir, 'rm' => true, &print_output)
FileUtils.cp_r(buildpack_path("scripts"), dest_bp_dir)
FileUtils.cp_r(Dir.glob(fixture_path + "*"), tmpdir)
image = Docker::Image.build_from_dir(tmpdir, &print_output)
end end
image image
......
require "tmpdir"
require "fileutils"
require "docker"
require_relative "path_helper"
class BuildpackBuilder
include PathHelper
TAG = "hone/static:14"
def initialize(debug = false)
@debug = debug
@image = build_image
end
def build_image
print_output =
if @debug
-> (chunk) {
json = JSON.parse(chunk)
puts json["stream"]
}
else
-> (chunk) { nil }
end
Docker::Image.build_from_dir(buildpack_path.to_s, 't' => TAG, 'rm' => true, &print_output)
end
end
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