diff --git a/xonsh/docker.xsh b/xonsh/docker.xsh new file mode 100644 index 0000000..2e0d0c6 --- /dev/null +++ b/xonsh/docker.xsh @@ -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 diff --git a/xonsh/rc.xsh b/xonsh/rc.xsh index 2796100..e6b0ea8 100644 --- a/xonsh/rc.xsh +++ b/xonsh/rc.xsh @@ -27,7 +27,7 @@ $ALTERNATE_EDITOR = "vim" $TERMINAL = "kitty" config_dir = p"~/.dotfiles/xonsh" -xsh_modules = ["prompt", "nix", "path", "alias", "java", "linux", "python", "local"] +xsh_modules = ["prompt", "nix", "path", "alias", "java", "linux", "python", "local", "docker"] for module in xsh_modules: _p = config_dir / f"{module}.xsh"