Module: Kubes::Docker::Strategy::ImageName
- Extended by:
- Memoist
- Included in:
- Kubes::Docker, Utils
- Defined in:
- lib/kubes/docker/strategy/image_name.rb
Constant Summary collapse
- @@image_name =
nil
- @@timestamp =
Time.now.strftime('%Y-%m-%dT%H-%M-%S')
Instance Method Summary collapse
- #args ⇒ Object
- #custom ⇒ Object
- #default ⇒ Object
- #generate_name ⇒ Object
- #git_sha ⇒ Object
-
#image_name ⇒ Object
full_image - Includes the tag.
-
#image_state_path ⇒ Object
output can get entirely wiped so dont use that folder.
- #read_image_name ⇒ Object
- #repo ⇒ Object
- #reserve_image_name ⇒ Object
-
#store_image_name ⇒ Object
Store this in a file because this name gets reference in other tasks later and we want the image name to stay the same when the commands are run separate in different processes.
Instance Method Details
#args ⇒ Object
69 70 71 72 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 69 def args # base at end in case of redirection. IE: command > /path custom.args + default.args end |
#custom ⇒ Object
74 75 76 77 78 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 74 def custom custom = Kubes::Args::Custom.new(@name, "#{Kubes.root}/.kubes/config/args/docker.rb") custom.build custom end |
#default ⇒ Object
81 82 83 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 81 def default Kubes::Docker::Args::Default.new(@name, image_name, @options) end |
#generate_name ⇒ Object
50 51 52 53 54 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 50 def generate_name # IE: tongueroo/demo:kubes- tag = ENV['KUBES_IMAGE_TAG'] || Kubes.config.image_tag || ["kubes-#{@@timestamp}", git_sha].compact.join('-') "#{repo}:#{tag}" end |
#git_sha ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 60 def git_sha return @git_sha if @git_sha # always call this and dont use the execute method because of the noop option git_installed = system("type git > /dev/null 2>&1") return unless git_installed && File.exist?("#{Kubes.root}/.git") @git_sha = `cd #{Kubes.root} && git rev-parse --short HEAD` @git_sha.strip! end |
#image_name ⇒ Object
full_image - Includes the tag. Examples:
123456789.dkr.ecr.us-west-2.amazonaws.com/myapp:kubes-2018-04-20T09-29-08-b7d51df
tongueroo/demo-kubes:kubes-2018-04-20T09-29-08-b7d51df
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 36 def image_name return generate_name if @options[:generate] return @@image_name if @@image_name return "tongueroo/demo-kubes:kubes-12345678" if ENV['TEST'] unless File.exist?(image_state_path) logger.error "ERROR: Unable to find #{image_state_path} which contains the last docker image name built with kubes build. Please run `kubes docker build` first." exit 1 end data = JSON.load(IO.read(image_state_path)) data['image'] end |
#image_state_path ⇒ Object
output can get entirely wiped so dont use that folder
29 30 31 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 29 def image_state_path Kubes.config.state.path end |
#read_image_name ⇒ Object
22 23 24 25 26 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 22 def read_image_name return unless File.exist?(image_state_path) data = IO.read(image_state_path).strip JSON.load(data)['image'] end |
#repo ⇒ Object
56 57 58 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 56 def repo Kubes.config.repo end |
#reserve_image_name ⇒ Object
8 9 10 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 8 def reserve_image_name @@image_name = generate_name end |
#store_image_name ⇒ Object
Store this in a file because this name gets reference in other tasks later and we want the image name to stay the same when the commands are run separate in different processes. So we store the state in a file. Only when a new docker build command gets run will the image name state be updated.
16 17 18 19 20 |
# File 'lib/kubes/docker/strategy/image_name.rb', line 16 def store_image_name FileUtils.mkdir_p(File.dirname(image_state_path)) text = JSON.pretty_generate(image: @@image_name) IO.write(image_state_path, text) end |