Skip to content

Commit

Permalink
Add unsafe tar ignore option (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolsson authored Sep 19, 2024
1 parent eb23f97 commit 314c015
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pants-plugins/oci/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ python_distribution_with_secret(
],
provides=python_artifact(
name="pants_backend_oci",
version="0.6.1",
version="0.6.2",
long_description_content_type="markdown",
),
long_description_path="pants-plugins/oci/README.md",
Expand Down
5 changes: 5 additions & 0 deletions pants-plugins/oci/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.6.2 - 2024-09-19

- Adds `[oci].unsafe_tar_ignore_file_changed` flag that will set `--warning=no-file-changed`
when invoking tar

## 0.6.1 - 2024-03-28

- Fix a bug where the plugin would try to publish OCI images without a repository.
Expand Down
13 changes: 13 additions & 0 deletions pants-plugins/oci/pants_backend_oci/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pants.engine.platform import Platform
from pants.option.option_types import BoolOption, StrListOption, StrOption
from pants.option.subsystem import Subsystem
from pants.util.strutil import softwrap


class OciSubsystem(Subsystem):
Expand Down Expand Up @@ -43,6 +44,18 @@ class OciSubsystem(Subsystem):
help="The name of the synthetic target for an empty base image.",
)

unsafe_tar_ignore_file_changed = BoolOption(
default=False,
advanced=True,
help=softwrap("""
Adds `--warning=no-file-changed` to tar calls.
When working with large files, Pants will use symlinks instead of copying files into the
sandboxes. Unfortunately, creating a symlink *modifies the target file*, which means
that tar can detect that the file was linked into another sandbox and fail with a "file changed"
warning."""),
)


class UmociTool(ExternalTool):
options_scope = "umoci"
Expand Down
9 changes: 8 additions & 1 deletion pants-plugins/oci/pants_backend_oci/util_rules/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from pants.util.logging import LogLevel
from pants.version import PANTS_SEMVER, Version

from pants_backend_oci.subsystem import OciSubsystem

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -155,7 +157,9 @@ async def tar_directory_process(


@rule(desc="Creating an archive file", level=LogLevel.DEBUG)
async def create_archive(request: CreateDeterministicTar, env: TarEnvironment, platform: Platform) -> Digest:
async def create_archive(
request: CreateDeterministicTar, env: TarEnvironment, oci_subsystem: OciSubsystem, platform: Platform
) -> Digest:
if platform in (Platform.macos_arm64, Platform.macos_x86_64):
tar_binary = await Get(GTarBinary)

Expand Down Expand Up @@ -186,6 +190,9 @@ async def create_archive(request: CreateDeterministicTar, env: TarEnvironment, p
"--numeric-owner",
]

if oci_subsystem.unsafe_tar_ignore_file_changed:
argv[8:8] = ["--warning=no-file-changed"]

# `tar` expects to find a couple binaries like `gzip` and `xz` by looking on the PATH.
env = {**env.env}

Expand Down
2 changes: 1 addition & 1 deletion pants-plugins/oci/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "pants_backend_oci"
description = "An OCI plugin for the Pants build system"
version = "0.6.1"
version = "0.6.2"
authors = [
{ name = "Tom Solberg", email = "[email protected]" }
]
Expand Down

0 comments on commit 314c015

Please sign in to comment.