Skip to content

Commit

Permalink
Enable packaging of curl|bash and other wild stuff.
Browse files Browse the repository at this point in the history
For #1853
  • Loading branch information
jordansissel committed Nov 7, 2022
1 parent 63d4ac8 commit e8fb7dd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/fpm/package/curlbash.rb
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
7 changes: 7 additions & 0 deletions templates/curlbash.erb
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 %>

0 comments on commit e8fb7dd

Please sign in to comment.