class FPM::Dockery::CLI::PackageCommand

The package command implementation.

Public Instance Methods

execute() click to toggle source
# File lib/fpm/dockery/cli.rb, line 74
        def execute
          recipe_path = File.expand_path(recipe)
          dir_to_mount = File.dirname(recipe_path)
          name_of_recipe = File.basename(recipe_path)

          validate_builder!
          create_builder_if_required

          extra_docker_commands = []
          extra_fpm_cook_commands = []

          pkg_dir = "/recipe/pkg"

          if package_dir
            extra_docker_commands << "-v #{File.expand_path(package_dir)}:/output"
            pkg_dir = "/output"
          end

          extra_docker_commands << docker_params if docker_params

          if private_key
            begin
              key = IO.read(File.expand_path(private_key))
              if key.include?('ENCRYPTED')
                fatal 'Provided private key has a passphrase ' + private_key
                exit 1
              end
              extra_docker_commands << "-v #{File.expand_path(private_key)}:/root/.ssh/id_rsa"
            rescue Errno::ENOENT
              fatal 'Provided private key does not exist ' + private_key
              exit 1
            end
          end

          if local_cache_dir
            extra_docker_commands << "-v #{File.expand_path(local_cache_dir)}:/tmp/cache"
          end

          if skip_package?
            extra_fpm_cook_commands << "--skip-package"
          end

          command = <<eos
docker run \
-v #{dir_to_mount}:/recipe \
#{extra_docker_commands.join(' ')} \
fpm-dockery/#{builder} \
--tmp-root /tmp/tmproot \
--pkg-dir #{pkg_dir} \
--cache-dir /tmp/cache \
package \
#{extra_fpm_cook_commands.join(' ')} \
/recipe/#{name_of_recipe}
eos
          exit_status = Subprocess.run(command)
          if exit_status.exitstatus == 0
            info "Packaging complete"
          else
            info "Packaging process exited with a non-zero exit code"
            exit exit_status.exitstatus
          end
        end