-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable packaging of curl|bash and other wild stuff.
For #1853
- Loading branch information
1 parent
63d4ac8
commit e8fb7dd
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
class FPM::Package::CurlBash < FPM::Package | ||
|
||
option "--container-image", "IMAGE", "The container image to use when running the command", :default => "ubuntu:latest" | ||
|
||
option "--setup", "SHELL COMMANDS", "Commands to run but not to include in the resulting package. For example, 'apt-get update' or other setup.", :multivalued => true | ||
|
||
def input(command) | ||
name = "whatever-#{$$}" | ||
|
||
content = template("curlbash.erb").result(binding) | ||
containerfile = build_path("Containerfile") | ||
File.write(containerfile, content) | ||
|
||
safesystem("podman", "image", "build", "-t", name, build_path) | ||
|
||
# Convert the container to a image layer tarball. | ||
changes_tar = build_path("changes.tar") | ||
safesystem("podman", "save", name, "-o", changes_tar) | ||
|
||
last_layer = nil | ||
execmd(["podman", "inspect", name], :stdin => false, :stdout =>true) do |stdout| | ||
inspection = JSON.parse(stdout.read) | ||
stdout.close | ||
last_layer = inspection[0]["RootFS"]["Layers"][-1] | ||
end | ||
|
||
layerdir = build_path("layers") | ||
safesystem("podman", "save", "--format", "docker-dir", "--output", layerdir, name) | ||
|
||
# Extract the last layer to the staging_path for packaging. | ||
safesystem("tar", "-C", staging_path, "-xf", build_path(File.join("layers", last_layer.gsub(/^sha256:/, "")))) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM <%= attributes[:curlbash_container_image] %> | ||
|
||
<% attributes[:curlbash_setup_list].each do |step| %> | ||
RUN <%= step %> | ||
<% end %> | ||
|
||
RUN <%= command %> |