7373property :sysctls , Hash , default : { }
7474property :timeout , Integer , desired_state : false
7575property :tmpfs , [ Hash , Array ] , default : { } , coerce : proc { |v | coerce_tmpfs ( v ) } ,
76- description : 'A hash or array of tmpfs mounts to add to the container. Hash format: { "/path" => "size=100M,uid=1000" }. Array format: ["/path", "/path2"]. See https://docs.docker.com/storage/tmpfs/'
76+ description : 'A hash or array of tmpfs mounts to add to the container. Hash format: { "/path" => "size=100M,uid=1000" }. Array format: ["/path", "/path2"]. See https://docs.docker.com/storage/tmpfs/'
7777property :tty , [ true , false ] , default : false
7878property :ulimits , [ Array , nil ] , coerce : proc { |v | coerce_ulimits ( v ) }
7979property :user , String
8787property :gpu_driver , String , default : 'nvidia' , description : 'GPU driver to use for container (e.g., nvidia)'
8888
8989# Used to store the bind property since binds is an alias to volumes
90- property :volumes_binds , Array , coerce : proc { | v | v . sort }
90+ property :volumes_binds , Array , coerce : proc ( & : sort)
9191
9292# Used to store the state of the Docker container
9393property :container , Docker ::Container , desired_state : false
@@ -206,7 +206,7 @@ def coerce_volumes(v)
206206 PartialHash [ v ]
207207 else
208208 b = [ ]
209- v = Array ( v ) . to_a # in case v.is_A?(Chef::Node::ImmutableArray)
209+ v = Array ( v ) # in case v.is_A?(Chef::Node::ImmutableArray)
210210 v . delete_if do |x |
211211 parts = x . split ( ':' )
212212 b << x if parts . length > 1
@@ -260,27 +260,27 @@ def parse_port(v)
260260 parts = v . split ( ':' )
261261 case parts . length
262262 when 3
263- host_ip = parts [ 0 ]
263+ host_ip = parts . first
264264 host_port = parts [ 1 ] . split ( '-' )
265265 container_port = parts [ 2 ] . split ( '-' )
266266 when 2
267267 host_ip = '0.0.0.0'
268- host_port = parts [ 0 ] . split ( '-' )
268+ host_port = parts . first . split ( '-' )
269269 container_port = parts [ 1 ] . split ( '-' )
270270 when 1
271271 host_ip = ''
272272 host_port = [ '' ]
273- container_port = parts [ 0 ] . split ( '-' )
273+ container_port = parts . first . split ( '-' )
274274 end
275275 host_port . map! ( &:to_i ) unless host_port == [ '' ]
276276 container_port . map! ( &:to_i )
277277 if host_port . count > 1
278- Chef ::Log . fatal ( "FATAL: Invalid port range! #{ host_port } " ) if host_port [ 0 ] > host_port [ 1 ]
279- host_port = ( host_port [ 0 ] ..host_port [ 1 ] ) . to_a
278+ Chef ::Log . fatal ( "FATAL: Invalid port range! #{ host_port } " ) if host_port . first > host_port [ 1 ]
279+ host_port = ( host_port . first ..host_port [ 1 ] ) . to_a
280280 end
281281 if container_port . count > 1
282- Chef ::Log . fatal ( "FATAL: Invalid port range! #{ container_port } " ) if container_port [ 0 ] > container_port [ 1 ]
283- container_port = ( container_port [ 0 ] ..container_port [ 1 ] ) . to_a
282+ Chef ::Log . fatal ( "FATAL: Invalid port range! #{ container_port } " ) if container_port . first > container_port [ 1 ]
283+ container_port = ( container_port . first ..container_port [ 1 ] ) . to_a
284284 end
285285 Chef ::Log . fatal ( 'FATAL: Port range size does not match!' ) if host_port . count > 1 && host_port . count != container_port . count
286286 # qualify the port-binding protocol even when it is implicitly tcp #427.
@@ -408,7 +408,7 @@ def to_snake_case(name)
408408
409409 # reload_signal is not persisted elsewhere, and will cause container
410410 # to restart if different from the default value
411- public_send ( ' reload_signal' , new_resource . reload_signal )
411+ reload_signal ( new_resource . reload_signal )
412412
413413 # Go through everything in the container and set corresponding properties:
414414 # c.info['Config']['ExposedPorts'] -> exposed_ports
@@ -461,7 +461,7 @@ def load_container_labels
461461 engine_labels . any? { |k , v | k == key && v == val }
462462 end
463463
464- public_send ( : labels, labels )
464+ labels ( labels )
465465end
466466
467467action :run do
@@ -479,71 +479,71 @@ def load_container_labels
479479
480480 with_retries do
481481 config = {
482- 'name' => new_resource . container_name ,
483- 'Image' => new_resource . tag . to_s . start_with? ( 'sha256:' ) ? "#{ new_resource . repo } @#{ new_resource . tag } " : "#{ new_resource . repo } :#{ new_resource . tag } " ,
484- 'Labels' => new_resource . labels ,
485- 'Cmd' => to_shellwords ( new_resource . command ) ,
486- 'AttachStderr' => new_resource . attach_stderr ,
487- 'AttachStdin' => new_resource . attach_stdin ,
488- 'AttachStdout' => new_resource . attach_stdout ,
489- 'Domainname' => new_resource . domain_name ,
490- 'Entrypoint' => to_shellwords ( new_resource . entrypoint ) ,
491- 'Env' => new_resource . env + read_env_file ,
492- 'ExposedPorts' => new_resource . exposed_ports ,
493- 'Healthcheck' => new_resource . health_check ,
494- 'Hostname' => parsed_hostname ,
495- 'MacAddress' => new_resource . mac_address ,
482+ 'name' => new_resource . container_name ,
483+ 'Image' => new_resource . tag . to_s . start_with? ( 'sha256:' ) ? "#{ new_resource . repo } @#{ new_resource . tag } " : "#{ new_resource . repo } :#{ new_resource . tag } " ,
484+ 'Labels' => new_resource . labels ,
485+ 'Cmd' => to_shellwords ( new_resource . command ) ,
486+ 'AttachStderr' => new_resource . attach_stderr ,
487+ 'AttachStdin' => new_resource . attach_stdin ,
488+ 'AttachStdout' => new_resource . attach_stdout ,
489+ 'Domainname' => new_resource . domain_name ,
490+ 'Entrypoint' => to_shellwords ( new_resource . entrypoint ) ,
491+ 'Env' => new_resource . env + read_env_file ,
492+ 'ExposedPorts' => new_resource . exposed_ports ,
493+ 'Healthcheck' => new_resource . health_check ,
494+ 'Hostname' => parsed_hostname ,
495+ 'MacAddress' => new_resource . mac_address ,
496496 'NetworkDisabled' => new_resource . network_disabled ,
497- 'OpenStdin' => new_resource . open_stdin ,
498- 'StdinOnce' => new_resource . stdin_once ,
499- 'Tty' => new_resource . tty ,
500- 'User' => new_resource . user ,
501- 'Volumes' => new_resource . volumes ,
502- 'WorkingDir' => new_resource . working_dir ,
503- 'HostConfig' => {
504- 'Binds' => new_resource . volumes_binds ,
505- 'CapAdd' => new_resource . cap_add ,
506- 'CapDrop' => new_resource . cap_drop ,
507- 'CgroupParent' => new_resource . cgroup_parent ,
508- 'CgroupnsMode' => new_resource . cgroup_ns ,
509- 'CpuShares' => new_resource . cpu_shares ,
510- 'CpusetCpus' => new_resource . cpuset_cpus ,
511- 'Devices' => new_resource . devices ,
512- 'Dns' => new_resource . dns ,
513- 'DnsSearch' => new_resource . dns_search ,
514- 'ExtraHosts' => new_resource . extra_hosts ,
515- 'IpcMode' => new_resource . ipc_mode ,
516- 'Init' => new_resource . init ,
517- 'KernelMemory' => new_resource . kernel_memory ,
518- 'Links' => new_resource . links ,
519- 'LogConfig' => log_config ,
520- 'Memory' => new_resource . memory ,
521- 'MemorySwap' => new_resource . memory_swap ,
497+ 'OpenStdin' => new_resource . open_stdin ,
498+ 'StdinOnce' => new_resource . stdin_once ,
499+ 'Tty' => new_resource . tty ,
500+ 'User' => new_resource . user ,
501+ 'Volumes' => new_resource . volumes ,
502+ 'WorkingDir' => new_resource . working_dir ,
503+ 'HostConfig' => {
504+ 'Binds' => new_resource . volumes_binds ,
505+ 'CapAdd' => new_resource . cap_add ,
506+ 'CapDrop' => new_resource . cap_drop ,
507+ 'CgroupParent' => new_resource . cgroup_parent ,
508+ 'CgroupnsMode' => new_resource . cgroup_ns ,
509+ 'CpuShares' => new_resource . cpu_shares ,
510+ 'CpusetCpus' => new_resource . cpuset_cpus ,
511+ 'Devices' => new_resource . devices ,
512+ 'Dns' => new_resource . dns ,
513+ 'DnsSearch' => new_resource . dns_search ,
514+ 'ExtraHosts' => new_resource . extra_hosts ,
515+ 'IpcMode' => new_resource . ipc_mode ,
516+ 'Init' => new_resource . init ,
517+ 'KernelMemory' => new_resource . kernel_memory ,
518+ 'Links' => new_resource . links ,
519+ 'LogConfig' => log_config ,
520+ 'Memory' => new_resource . memory ,
521+ 'MemorySwap' => new_resource . memory_swap ,
522522 'MemorySwappiness' => new_resource . memory_swappiness ,
523523 'MemoryReservation' => new_resource . memory_reservation ,
524- 'NanoCpus' => new_resource . cpus ,
525- 'NetworkMode' => normalize_container_network_mode ( new_resource . network_mode ) ,
526- 'OomKillDisable' => new_resource . oom_kill_disable ,
527- 'OomScoreAdj' => new_resource . oom_score_adj ,
528- 'Privileged' => new_resource . privileged ,
529- 'PidMode' => new_resource . pid_mode ,
530- 'PortBindings' => new_resource . port_bindings ,
524+ 'NanoCpus' => new_resource . cpus ,
525+ 'NetworkMode' => normalize_container_network_mode ( new_resource . network_mode ) ,
526+ 'OomKillDisable' => new_resource . oom_kill_disable ,
527+ 'OomScoreAdj' => new_resource . oom_score_adj ,
528+ 'Privileged' => new_resource . privileged ,
529+ 'PidMode' => new_resource . pid_mode ,
530+ 'PortBindings' => new_resource . port_bindings ,
531531 'PublishAllPorts' => new_resource . publish_all_ports ,
532- 'RestartPolicy' => {
533- 'Name' => new_resource . restart_policy ,
532+ 'RestartPolicy' => {
533+ 'Name' => new_resource . restart_policy ,
534534 'MaximumRetryCount' => new_resource . restart_maximum_retry_count ,
535535 } ,
536- 'ReadonlyRootfs' => new_resource . ro_rootfs ,
537- 'Runtime' => new_resource . runtime ,
538- 'SecurityOpt' => new_resource . security_opt ,
539- 'ShmSize' => new_resource . shm_size ,
540- 'Sysctls' => new_resource . sysctls ,
541- 'Tmpfs' => new_resource . tmpfs ,
542- 'Ulimits' => ulimits_to_hash ,
543- 'UsernsMode' => new_resource . userns_mode ,
544- 'UTSMode' => new_resource . uts_mode ,
545- 'VolumesFrom' => new_resource . volumes_from ,
546- 'VolumeDriver' => new_resource . volume_driver ,
536+ 'ReadonlyRootfs' => new_resource . ro_rootfs ,
537+ 'Runtime' => new_resource . runtime ,
538+ 'SecurityOpt' => new_resource . security_opt ,
539+ 'ShmSize' => new_resource . shm_size ,
540+ 'Sysctls' => new_resource . sysctls ,
541+ 'Tmpfs' => new_resource . tmpfs ,
542+ 'Ulimits' => ulimits_to_hash ,
543+ 'UsernsMode' => new_resource . userns_mode ,
544+ 'UTSMode' => new_resource . uts_mode ,
545+ 'VolumesFrom' => new_resource . volumes_from ,
546+ 'VolumeDriver' => new_resource . volume_driver ,
547547 } ,
548548 }
549549 net_config = {
@@ -699,7 +699,7 @@ def validate_container_create
699699 raise Chef ::Exceptions ::ValidationFailed , 'restart_policy must be either no, always, unless-stopped, or on-failure.'
700700 end
701701
702- if new_resource . autoremove == true && ( new_resource . property_is_set? ( :restart_policy ) && new_resource . restart_policy != 'no' )
702+ if new_resource . autoremove == true && new_resource . property_is_set? ( :restart_policy ) && new_resource . restart_policy != 'no'
703703 raise Chef ::Exceptions ::ValidationFailed , 'Conflicting options restart_policy and autoremove.'
704704 end
705705
@@ -754,8 +754,8 @@ def state
754754 def ulimits_to_hash
755755 return if new_resource . ulimits . nil?
756756 new_resource . ulimits . map do |u |
757- name = u . split ( '=' ) [ 0 ]
758- soft = u . split ( '=' ) [ 1 ] . split ( ':' ) [ 0 ]
757+ name = u . split ( '=' ) . first
758+ soft = u . split ( '=' ) [ 1 ] . split ( ':' ) . first
759759 hard = u . split ( '=' ) [ 1 ] . split ( ':' ) [ 1 ]
760760 { 'Name' => name , 'Soft' => soft . to_i , 'Hard' => hard . to_i }
761761 end
0 commit comments