1212 commands runtime : 'podman'
1313
1414 def exists?
15- desired_checksum = get_image_content_checksum
16-
17- unless File . directory? ( resource [ :destination ] )
18- Puppet . debug ( "Destination #{ resource [ :destination ] } not found. Resource does not exist." )
19- return false
20- end
21-
22- current_checksum = get_deployed_checksum
23-
24- in_sync = current_checksum == desired_checksum
25- Puppet . debug ( "Current checksum: #{ current_checksum } , Desired checksum: #{ desired_checksum } . In sync: #{ in_sync } " )
15+ File . exist? ( metadata_file )
16+ end
2617
27- cleanup ( nil , @staged_content_path ) if in_sync
18+ def image
19+ get_deployed_checksum . to_s
20+ end
2821
29- in_sync
22+ def image = ( value )
23+ create
3024 end
3125
3226 def create
3327 Puppet . info ( "Deploying new frontend content to '#{ resource [ :destination ] } '" )
3428
3529 destroy if File . directory? ( resource [ :destination ] )
3630
37- Puppet . debug ( "Copying staged content from '#{ @staged_content_path } ' to '#{ resource [ :destination ] } '" )
31+ staged_content_path , new_content_checksum = stage_content
32+ Puppet . debug ( "Copying staged content from '#{ staged_content_path } ' to '#{ resource [ :destination ] } '" )
3833 Dir . mkdir ( resource [ :destination ] , 0755 )
39- FileUtils . cp_r ( Dir . glob ( File . join ( @ staged_content_path, '*' ) ) , resource [ :destination ] )
34+ FileUtils . cp_r ( Dir . glob ( File . join ( staged_content_path , '*' ) ) , resource [ :destination ] )
4035
4136 restore_selinux_context ( resource [ :destination ] )
4237
43- metadata_file = File . join ( resource [ :destination ] , '.iop_frontend_checksum' )
44- Puppet . debug ( "Writing new checksum #{ @new_content_checksum } to #{ metadata_file } " )
45- File . write ( metadata_file , @new_content_checksum )
46-
47- @staged_content_path = nil
48- @new_content_checksum = nil
38+ Puppet . debug ( "Writing new checksum #{ new_content_checksum } to #{ metadata_file } " )
39+ File . write ( metadata_file , new_content_checksum )
4940 end
5041
5142 def destroy
5243 Puppet . info ( "Removing frontend at '#{ resource [ :destination ] } '" )
5344 FileUtils . rm_rf ( resource [ :destination ] )
5445 end
5546
47+ def content_checksum
48+ path , checksum = stage_content
49+ checksum
50+ end
51+
5652 private
5753
54+ def metadata_file
55+ File . join ( resource [ :destination ] , '.iop_frontend_checksum' )
56+ end
57+
5858 def get_deployed_checksum
59- metadata_file = File . join ( resource [ :destination ] , '.iop_frontend_checksum' )
6059 return nil unless File . exist? ( metadata_file )
6160
6261 File . read ( metadata_file ) . strip
6362 end
6463
65- def get_image_content_checksum
66- return @new_content_checksum if @new_content_checksum
67-
64+ def stage_content
6865 temp_container_name = "iop-frontend-checker-#{ resource . title . gsub ( /[^0-9a-zA-Z]/ , '-' ) } "
6966 staging_dir = Dir . mktmpdir ( 'iop_frontend_check' )
7067
@@ -73,10 +70,10 @@ def get_image_content_checksum
7370 source_in_container = "#{ temp_container_name } :#{ resource [ :source_path ] } /."
7471 execute ( [ 'podman' , 'cp' , source_in_container , staging_dir ] )
7572
76- @ new_content_checksum = calculate_checksum_for_path ( staging_dir )
77- @ staged_content_path = staging_dir
73+ new_content_checksum = calculate_checksum_for_path ( staging_dir )
74+ staged_content_path = staging_dir
7875
79- return @ new_content_checksum
76+ return staged_content_path , new_content_checksum
8077 rescue Puppet ::ExecutionFailure => e
8178 Puppet . err ( "Failed to get content checksum from image '#{ resource [ :image ] } ': #{ e . message } " )
8279 cleanup ( temp_container_name , staging_dir )
0 commit comments