Class: FPM::Dockery::CLI::BaseCommand
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- FPM::Dockery::CLI::BaseCommand
- Defined in:
- lib/fpm/dockery/cli.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#create_builder(no_cache) ⇒ Object
Create a builder image.
-
#create_builder_if_required ⇒ Object
Create a builder image if it doesn’t exist.
-
#valid_builders ⇒ Object
List all valid builders by listing the Dockerfile.* files in the docker directory.
-
#validate_builder! ⇒ Object
Check the builder is one we have a Dockerfile for.
Methods included from Logging
Instance Method Details
#create_builder(no_cache) ⇒ Object
Create a builder image.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fpm/dockery/cli.rb', line 35 def create_builder(no_cache) validate_builder! cache_option = no_cache ? '--no-cache=true' : '' exit_status = Subprocess.run("docker build #{cache_option} -f #{FPM::Dockery.root}/docker/Dockerfile.#{builder} -t fpm-dockery/#{builder} #{FPM::Dockery.root}") if exit_status.exitstatus == 0 info "Build complete" else info "Build process exited with a non-zero exit code" exit exit_status.exitstatus end end |
#create_builder_if_required ⇒ Object
Create a builder image if it doesn’t exist.
26 27 28 29 30 31 32 |
# File 'lib/fpm/dockery/cli.rb', line 26 def create_builder_if_required image_check = Subprocess.run("docker images | awk '{print $1}' | grep fpm-dockery/#{builder}") unless image_check.exitstatus == 0 warn "The builder image '#{builder}' does not exist; running the image creation for you" create_builder(false) end end |
#valid_builders ⇒ Object
List all valid builders by listing the Dockerfile.* files in the docker directory.
13 14 15 |
# File 'lib/fpm/dockery/cli.rb', line 13 def valid_builders Dir.glob("#{FPM::Dockery.root}/docker/Dockerfile.*").map {|f| File.basename(f.gsub('Dockerfile.', ''))} end |
#validate_builder! ⇒ Object
Check the builder is one we have a Dockerfile for.
18 19 20 21 22 23 |
# File 'lib/fpm/dockery/cli.rb', line 18 def validate_builder! unless valid_builders.include?(builder) fatal "Image type must be one of: #{valid_builders.join(', ')}" exit 1 end end |