35 lines
968 B
Plaintext
35 lines
968 B
Plaintext
_DOCKERFILE_TEXT = """
|
|
FROM busybox
|
|
COPY . /build-context
|
|
WORKDIR /build-context
|
|
CMD find .
|
|
"""
|
|
|
|
def _dockerignore_check(args):
|
|
if len(args) != 1:
|
|
print("Must specify only one argument: The dockerignore file.")
|
|
return
|
|
|
|
ignore_file = Path(args[0])
|
|
|
|
if not ignore_file.exists():
|
|
print(f"Dockerignore file {ignore_file} doesn't exist.")
|
|
|
|
import tempfile
|
|
import shutil
|
|
|
|
with tempfile.TemporaryDirectory() as td:
|
|
dpath = Path(td)
|
|
|
|
docker_path = dpath / "Dockerfile"
|
|
ignore_path = dpath / "Dockerfile.dockerignore"
|
|
docker_path.write_text(_DOCKERFILE_TEXT)
|
|
shutil.copyfile(ignore_file, ignore_path)
|
|
|
|
$DOCKER_BUILDKIT=1
|
|
docker image build --no-cache -t dockerignore-build-context -f @(docker_path) . &>/dev/null
|
|
docker run -it --rm dockerignore-build-context
|
|
docker image rm dockerignore-build-context &> /dev/null
|
|
|
|
aliases["ditest"] = _dockerignore_check
|