Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
oci: configurable tmpdir
Browse files Browse the repository at this point in the history
  • Loading branch information
elthariel committed Jun 4, 2021
1 parent 971df85 commit 5cf1233
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions oci/oci.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def container_image(
dockerfile = containerfile
transitive_base_images = [canonicalise(rule) for rule in transitive_base_images]
base_image_target = base_image

# OCI_TMPDIR: If your code and /tmp are in different file systems, the hard-link used by
# this rule will not work. In that case, you can use the OCI_TMPDIR buildconfig
oci_tmpdir=CONFIG.get('OCI_TMPDIR', '/tmp')

def assert_transitive_base_images_present():
"""
Expand Down Expand Up @@ -81,7 +85,7 @@ def container_image(
if srcs:
context = "$STORE/context"
srcs_dict['context'] = srcs
cmds += [f'mkdir "{context}"', f'mv $SRCS_CONTEXT "{context}"']
cmds += [f'mkdir "{context}"', f'mv "$SRCS_CONTEXT" "{context}"']
return context, cmds

def build_using_dockerfile(srcs_dict:dict, cmds:list, base_image:str, context:str):
Expand Down Expand Up @@ -120,7 +124,7 @@ def container_image(
# Buildah uses an image store, which can be ephemeral, except that please fails to delete it
# due to permissions. This uses a cache in /tmp, outside the build rule dir, where it
# doesnt have to be deleted by please. It is deleted on successful build or system restart.
'STORE=$(TMPDIR=/tmp mktemp -d)',
f'STORE=$(TMPDIR="{oci_tmpdir}" mktemp -d)',
'TOOL="$TOOL --root=$STORE/containers --runroot=$STORE/run"',
]
base_image, cmds, labels, pre_build = format_base_image(srcs_dict, cmds, labels)
Expand Down Expand Up @@ -186,7 +190,7 @@ def container_image(
if srcs_dict.get('base'):
base_images = transitive_base_images + srcs_dict['base']
data += base_images
cmds += ['tmp_dir=\\\$(mktemp -d)', f'cp -rl $(out_location {image_rule})/* \\\$tmp_dir']
cmds += [f'tmp_dir=\\\$(TMPDIR="{oci_tmpdir}" mktemp -d)', f'cp -rl $(out_location {image_rule})/* \\\$tmp_dir']
for base in base_images:
cmds += [f'cp -l $(out_location {base})/blobs/sha256/* "\\\$tmp_dir/blobs/sha256"']
img_loc = f'oci:\\\$tmp_dir'
Expand Down

0 comments on commit 5cf1233

Please sign in to comment.