Skip to content

Commit 6c0d1e9

Browse files
author
Nisha K
committed
Fix application for multiple cached layers
This is work towards tern-tools#1082 When using the default method of overlaying the container image's layers, in the event of a cache hit the current implementation does not copy over the filesystem into the merge directory. As a result, the overlaying fails. To fix this issue, we check to see if there was a cache hit and if the driver is the default one. If this is the case, we prep the merge directory anyway. In some situations, the operations to build container images create whiteout files owned by the root user. In order to delete these files and directories, tern needs to be able to run these operations as the root user. Hence we use the root_command utility to remove whiteout files and directories. Signed-off-by: Nisha K <[email protected]>
1 parent ab13f1c commit 6c0d1e9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tern/analyze/default/container/multi_layer.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import glob
1111
import logging
1212
import os
13-
import shutil
1413

1514
from tern.report import errors
1615
from tern.utils import constants
@@ -53,9 +52,9 @@ def apply_layers(image_obj, top_layer):
5352
delpath = os.path.join(target, os.path.dirname(fd.path), deleted)
5453
if os.path.exists(delpath):
5554
if os.path.isfile(delpath):
56-
os.remove(delpath)
55+
rootfs.root_command(['rm'], delpath)
5756
else:
58-
shutil.rmtree(delpath)
57+
rootfs.root_command(rootfs.remove, delpath)
5958
os.remove(os.path.join(layer_dir, fd.path))
6059
# Finally, bulk copy the layer contents into the target directory
6160
# if there are any files to move
@@ -128,6 +127,10 @@ def analyze_subsequent_layers(image_obj, prereqs, master_list, options):
128127
fresh analysis
129128
package information and bundle it into the image object
130129
3. Update the master list"""
130+
# if the driver is 'default' then the first layer needs to be extracted
131+
mergepath = os.path.join(rootfs.get_working_dir(), constants.mergedir)
132+
if not os.listdir(mergepath):
133+
prep_layers(image_obj, 0, 'default')
131134
curr_layer = 1
132135
# get list of environment variables
133136
prereqs.envs = lock.get_env_vars(image_obj)
@@ -151,6 +154,9 @@ def analyze_subsequent_layers(image_obj, prereqs, master_list, options):
151154
if not common.load_from_cache(image_obj.layers[curr_layer],
152155
options.redo):
153156
fresh_analysis(image_obj, curr_layer, prereqs, options)
157+
# If the driver is 'default' apply the current layer anyway
158+
if options.driver == 'default':
159+
apply_layers(image_obj, curr_layer)
154160
# update the master list
155161
dcom.update_master_list(master_list, image_obj.layers[curr_layer])
156162
curr_layer = curr_layer + 1

0 commit comments

Comments
 (0)