Add dockerignore tester to xonsh config
This commit is contained in:
34
xonsh/docker.xsh
Normal file
34
xonsh/docker.xsh
Normal file
@@ -0,0 +1,34 @@
|
||||
_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
|
||||
Reference in New Issue
Block a user