Skip to content

Commit 30d13b5

Browse files
committed
Wrote some tests...
and also fixed bugs found by the tests. :)
1 parent e2775d9 commit 30d13b5

File tree

4 files changed

+98
-5
lines changed

4 files changed

+98
-5
lines changed

lib/fpm/package/curlbash.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require "fpm/package"
2+
require "json"
3+
14
class FPM::Package::CurlBash < FPM::Package
25

36
option "--container-image", "IMAGE", "The container image to use when running the command", :default => "ubuntu:latest"
@@ -10,15 +13,15 @@ def input(entry)
1013
build_flags = []
1114

1215
if File.exists?(entry)
13-
if attributes[:curlbash_setup_list].any?
16+
if attributes[:curlbash_setup_list]
1417
logger.warn("When the argument given is a file or directory, the --curlbash-setup flags are ignored. This is because fpm assumes any setup you want to do is done inside of your Dockerfile or Containerfile, and also because fpm does not know how to edit a Dockerfile to append these setup steps.")
1518
end
1619

1720
entryinfo = File.stat(entry)
1821
if entryinfo.file?
1922
build_flags += ["-f", entry, build_path]
2023
elsif entryinfo.directory?
21-
build_flags += [entryinfo]
24+
build_flags += [entry]
2225
else
2326
logger.fatal("The path must be a file or a directory. It is not.", :path => entry)
2427
raise FPM::InvalidPackageConfiguration, "The path must be a file or directory, but it is neither. Path: #{entry.inspect}"
@@ -68,10 +71,14 @@ def input(entry)
6871

6972
(attributes[:excludes] ||= []).append(
7073
"tmp",
71-
"run",
7274
"var/tmp",
7375
"root/.bashrc",
74-
"root/.profile"
76+
"root/.profile",
77+
78+
# Ignore podman's secrets files
79+
"run/secret/**",
80+
"run/secret",
81+
"run",
7582
)
7683
end
7784
end

spec/fixtures/curlbash/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:latest
2+
3+
RUN touch /hello-world

spec/fpm/package/curlbash_spec.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
require "spec_setup"
2+
require "fpm/package/curlbash"
3+
require "stud/temporary"
4+
5+
require "fpm/package/dir"
6+
7+
describe FPM::Package::CurlBash do
8+
context "with commands" do
9+
after { subject.cleanup }
10+
11+
it "should work maybe" do
12+
subject.input("touch /usr/bin/example")
13+
14+
insist { File.stat(subject.staging_path("usr")) }.directory?
15+
insist { File.stat(subject.staging_path("usr/bin")) }.directory?
16+
insist { File.stat(subject.staging_path("usr/bin/example")) }.file?
17+
end
18+
19+
context "with setup steps" do
20+
before do
21+
subject.attributes[:curlbash_setup_list] = [
22+
"touch /usr/bin/example",
23+
"mkdir -p /hello/world",
24+
]
25+
26+
# Run a command which makes no file changes.
27+
subject.input("true")
28+
end
29+
30+
let(:output) { subject.convert(FPM::Package::Dir) }
31+
32+
after do
33+
output.cleanup
34+
end
35+
36+
it "should not capture setup step file activity" do
37+
# Expect an empty staging path in the output package.
38+
output.staging_path
39+
insist { Dir.entries(output.staging_path) } == [".", ".."]
40+
end
41+
end
42+
end
43+
44+
context "with Dockerfile or Containerfile" do
45+
before do
46+
subject.attributes[:excludes] = [ "etc/**", "etc" ]
47+
end
48+
49+
let(:output) { subject.convert(FPM::Package::Dir) }
50+
51+
after do
52+
subject.cleanup
53+
output.cleanup
54+
end
55+
56+
context "and specifying the file directly" do
57+
let(:dockerfile) { File.expand_path("../../fixtures/curlbash/Dockerfile", File.dirname(__FILE__)) }
58+
59+
before do
60+
subject.input(dockerfile)
61+
end
62+
63+
it "should use the dockerfile" do
64+
insist { Dir.entries(output.staging_path) } == [".", "..", "hello-world"]
65+
end
66+
end
67+
68+
context "and giving a directory containing a Dockerfile or Containerfile" do
69+
let(:path) { File.expand_path("../../fixtures/curlbash", File.dirname(__FILE__)) }
70+
71+
before do
72+
p path
73+
subject.input(path)
74+
end
75+
76+
it "should work" do
77+
insist { Dir.entries(output.staging_path) } == [".", "..", "hello-world"]
78+
end
79+
end
80+
81+
end
82+
83+
end

templates/curlbash.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM <%= attributes[:curlbash_container_image] %>
22

3-
<% attributes[:curlbash_setup_list].each do |step| %>
3+
<% attributes.fetch(:curlbash_setup_list, []).each do |step| %>
44
RUN <%= step %>
55
<% end %>
66

0 commit comments

Comments
 (0)