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
|
||||||
@@ -27,7 +27,7 @@ $ALTERNATE_EDITOR = "vim"
|
|||||||
$TERMINAL = "kitty"
|
$TERMINAL = "kitty"
|
||||||
|
|
||||||
config_dir = p"~/.dotfiles/xonsh"
|
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:
|
for module in xsh_modules:
|
||||||
_p = config_dir / f"{module}.xsh"
|
_p = config_dir / f"{module}.xsh"
|
||||||
|
|||||||
Reference in New Issue
Block a user