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

Commit

Permalink
oci: oci_tmpdir in buildconfig and rule param
Browse files Browse the repository at this point in the history
  • Loading branch information
elthariel committed Jun 4, 2021
1 parent 876d4fd commit 6c18de3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions oci/oci.build_defs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
def container_image(
name:str, base_image='', transitive_base_images=[], srcs=[],image='', version='', dockerfile='',
containerfile='', entrypoint=[], cmd=[], repo=CONFIG.get('DEFAULT_DOCKER_REPO', ''),
labels=[], run_args:str='', push_args:str='', test_only=False, visibility:list=None
oci_tmpdir=CONFIG.get('OCI_TMPDIR', '/tmp'), labels=[], run_args:str='', push_args:str='',
test_only=False, visibility:list=None
):
"""Build an OCI-compliant image. Uses incremental layering to optimise for please. The OCI
Specification standardises the docker image format https://github.com/opencontainers/image-spec.
Expand Down Expand Up @@ -29,6 +30,9 @@ def container_image(
cmd: (when not using containerfile) The 'cmd' of the image, as a list of commands. For
single-source images, defaults to a command running that source.
repo: Optional repository to hold this image. Can also provide env var when calling '_push'.
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, use the config option or this parameter.
labels: Labels to tag this rule with.
run_args: Any additional arguments to provide to 'podman run'.
push_args: Any additional arguments to provide to 'skopeo copy'.
Expand Down Expand Up @@ -113,17 +117,14 @@ def container_image(
# commit the image and remove the working container
cmds += [f'$TOOL commit --omit-timestamp "$ctr" "{img_id}"']
return img_id, cmds

# image rule, builds the image and stores it as an oci-formatted dir.
srcs_dict = {}
cmds = [
# 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.
# If your code and /tmp are in different file systems, the hard-link will not work. In that
# case, you can override OCI_TMPDIR in your [buildenv]
'OCI_TMPDIR=${OCI_TMPDIR:-/tmp}',
'STORE=$(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 @@ -189,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=\\\$(TMPDIR=$OCI_TMPDIR 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 6c18de3

Please sign in to comment.