Skip to content

Commit 0815d47

Browse files
committed
Move the safety checks to the top.
Also ensure we clean up the temporary container image we created
1 parent 30d13b5 commit 0815d47

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lib/fpm/package/curlbash.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ class FPM::Package::CurlBash < FPM::Package
1010
#option "--volume", "VOLUME" , "Same syntax as `podman run --volume`. Mount a local directory into the container. Useful for `make install` types of projects that were built outside of fpm."
1111

1212
def input(entry)
13+
if program_exists?("podman")
14+
runtime = "podman"
15+
elsif program_exists?("docker")
16+
# Docker support isn't implemented yet. I don't expect it to be difficult, but
17+
# we need to check if the build, inspect, and save commands use the same syntax
18+
# At minimu, docker doesn't support the same flags as `podman image save`
19+
#runtime = "docker"
20+
logger.error("Docker executable found, but fpm doesn't support this yet. If you want this, file an issue? https://github.com/jordansissel/fpm/issues/new")
21+
raise FPM::Package::InvalidPackageConfiguration, "Missing 'podman' executable."
22+
else
23+
raise FPM::Package::InvalidPackageConfiguration, "Missing 'podman' executable."
24+
end
25+
1326
build_flags = []
27+
name = "whatever-#{$$}"
1428

1529
if File.exists?(entry)
1630
if attributes[:curlbash_setup_list]
@@ -37,20 +51,6 @@ def input(entry)
3751
build_flags += ["-f", build_path("Containerfile"), build_path]
3852
end
3953

40-
name = "whatever-#{$$}"
41-
if program_exists?("podman")
42-
runtime = "podman"
43-
elsif program_exists?("docker")
44-
# Docker support isn't implemented yet. I don't expect it to be difficult, but
45-
# we need to check if the build, inspect, and save commands use the same syntax
46-
# At minimu, docker doesn't support the same flags as `podman image save`
47-
#runtime = "docker"
48-
logger.error("Docker executable found, but fpm doesn't support this yet. If you want this, file an issue? https://github.com/jordansissel/fpm/issues/new")
49-
raise FPM::Package::InvalidPackageConfiguration, "Missing 'podman' executable."
50-
else
51-
raise FPM::Package::InvalidPackageConfiguration, "Missing 'podman' executable."
52-
end
53-
5454
safesystem(runtime, "image", "build", "-t", name, *build_flags)
5555

5656
# Find out the identifier for the most latest image layer
@@ -80,5 +80,10 @@ def input(entry)
8080
"run/secret",
8181
"run",
8282
)
83+
ensure
84+
if !name.nil? && !runtime.nil?
85+
logger.info("Removing #{runtime} image", :name => name)
86+
safesystem(runtime, "image", "rm", name)
87+
end
8388
end
8489
end

0 commit comments

Comments
 (0)