Class: FPM::Dockery::CLI::PackageCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/fpm/dockery/cli.rb

Overview

The package command implementation.

Instance Method Summary collapse

Methods inherited from BaseCommand

#create_builder, #create_builder_if_required, #valid_builders, #validate_builder!

Methods included from Logging

#fatal, #info, #warn

Instance Method Details

#executeObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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