Skip to content

Commit e46f769

Browse files
committed
Support .cnb, .tgz, and .tar.gz as part of install_buildpacks
1 parent 2a6adba commit e46f769

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

lib/cloud_controller/install_buildpacks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def detected_stack(file, opts)
7575
def buildpack_zip(package, zipfile)
7676
return zipfile if zipfile
7777

78-
job_dir = File.join('/var/vcap/packages', package, '*.zip')
78+
job_dir = File.join('/var/vcap/packages', package, '*[.zip|.cnb|.tgz|.tar.gz]')
7979
Dir[job_dir].first
8080
end
8181

spec/unit/lib/cloud_controller/install_buildpacks_spec.rb

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,74 @@ module VCAP::CloudController
4040
end
4141
end
4242

43+
context 'when a cnb buildpack is specified' do
44+
let(:file) { 'buildpack.cnb' }
45+
let(:buildpack_fields) do
46+
{ name: 'cnb_buildpack', file: file, stack: nil, options: { lifecycle: Lifecycles::CNB } }
47+
end
48+
49+
let(:install_buildpack_config) do
50+
{
51+
install_buildpacks: [
52+
{
53+
'name' => 'cnb_buildpack',
54+
'package' => 'cnb-buildpack-package',
55+
'lifecycle' => 'cnb'
56+
}
57+
]
58+
}
59+
end
60+
61+
before do
62+
expect(Dir).to receive(:[]).with('/var/vcap/packages/cnb-buildpack-package/*[.zip|.cnb|.tgz|.tar.gz]').
63+
and_return([file])
64+
expect(File).to receive(:file?).with(file).
65+
and_return(true)
66+
allow(job_factory).to receive(:plan).with('cnb_buildpack', [buildpack_fields]).and_return([enqueued_job1])
67+
allow(Jobs::Enqueuer).to receive(:new).and_return(enqueuer)
68+
end
69+
70+
it 'succeeds' do
71+
installer.install(TestConfig.config_instance.get(:install_buildpacks))
72+
73+
expect(job_factory).to have_received(:plan).with('cnb_buildpack', [buildpack_fields])
74+
end
75+
end
76+
77+
context 'when a cnb buildpack is specified with .tgz extension' do
78+
let(:file) { 'buildpack.tgz' }
79+
let(:buildpack_fields) do
80+
{ name: 'cnb_buildpack', file: file, stack: nil, options: { lifecycle: Lifecycles::CNB } }
81+
end
82+
83+
let(:install_buildpack_config) do
84+
{
85+
install_buildpacks: [
86+
{
87+
'name' => 'cnb_buildpack',
88+
'package' => 'cnb-buildpack-package',
89+
'lifecycle' => 'cnb'
90+
}
91+
]
92+
}
93+
end
94+
95+
before do
96+
expect(Dir).to receive(:[]).with('/var/vcap/packages/cnb-buildpack-package/*[.zip|.cnb|.tgz|.tar.gz]').
97+
and_return([file])
98+
expect(File).to receive(:file?).with(file).
99+
and_return(true)
100+
allow(job_factory).to receive(:plan).with('cnb_buildpack', [buildpack_fields]).and_return([enqueued_job1])
101+
allow(Jobs::Enqueuer).to receive(:new).and_return(enqueuer)
102+
end
103+
104+
it 'succeeds' do
105+
installer.install(TestConfig.config_instance.get(:install_buildpacks))
106+
107+
expect(job_factory).to have_received(:plan).with('cnb_buildpack', [buildpack_fields])
108+
end
109+
end
110+
43111
context 'when there are multiple buildpacks' do
44112
let(:buildpack1a_file) { 'abuildpacka.zip' }
45113
let(:buildpack1b_file) { 'abuildpackb.zip' }
@@ -56,15 +124,15 @@ module VCAP::CloudController
56124
end
57125

58126
before do
59-
expect(Dir).to receive(:[]).with('/var/vcap/packages/mybuildpackpkg/*.zip').
127+
expect(Dir).to receive(:[]).with('/var/vcap/packages/mybuildpackpkg/*[.zip|.cnb|.tgz|.tar.gz]').
60128
and_return([buildpack1a_file])
61129
expect(File).to receive(:file?).with(buildpack1a_file).
62130
and_return(true)
63-
expect(Dir).to receive(:[]).with('/var/vcap/packages/myotherpkg/*.zip').
131+
expect(Dir).to receive(:[]).with('/var/vcap/packages/myotherpkg/*[.zip|.cnb|.tgz|.tar.gz]').
64132
and_return([buildpack1b_file])
65133
expect(File).to receive(:file?).with(buildpack1b_file).
66134
and_return(true)
67-
expect(Dir).to receive(:[]).with('/var/vcap/packages/myotherpkg2/*.zip').
135+
expect(Dir).to receive(:[]).with('/var/vcap/packages/myotherpkg2/*[.zip|.cnb|.tgz|.tar.gz]').
68136
and_return([buildpack2_file])
69137
expect(File).to receive(:file?).with(buildpack2_file).
70138
and_return(true)
@@ -124,7 +192,7 @@ module VCAP::CloudController
124192
end
125193

126194
it 'logs an error when no buildpack zip file is found' do
127-
expect(Dir).to receive(:[]).with('/var/vcap/packages/mybuildpackpkg/*.zip').and_return([])
195+
expect(Dir).to receive(:[]).with('/var/vcap/packages/mybuildpackpkg/*[.zip|.cnb|.tgz|.tar.gz]').and_return([])
128196
expect(installer.logger).to receive(:error).with(/No file found for the buildpack/)
129197

130198
installer.install(TestConfig.config_instance.get(:install_buildpacks))
@@ -212,7 +280,7 @@ module VCAP::CloudController
212280

213281
it 'passes optional attributes to the job factory' do
214282
expect(Dir).to receive(:[]).
215-
with('/var/vcap/packages/mybuildpackpkg/*.zip').
283+
with('/var/vcap/packages/mybuildpackpkg/*[.zip|.cnb|.tgz|.tar.gz]').
216284
and_return(['abuildpack.zip'])
217285
expect(File).to receive(:file?).
218286
with('abuildpack.zip').

0 commit comments

Comments
 (0)