Add helpful CLI utilities
This commit is contained in:
61
bin/,di
Executable file
61
bin/,di
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
|
||||
DOCKERFILE_TEXT = """
|
||||
FROM busybox
|
||||
COPY . /build-context
|
||||
WORKDIR /build-context
|
||||
CMD find .
|
||||
"""
|
||||
|
||||
def dockerignore_check(args):
|
||||
ignore_file = Path(args.file)
|
||||
|
||||
if not ignore_file.exists():
|
||||
print(f"Dockerignore file {ignore_file} doesn't exist.")
|
||||
|
||||
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)
|
||||
|
||||
env = os.environ.copy()
|
||||
env["DOCKER_BUILDKIT"] = "1"
|
||||
subprocess.run(
|
||||
f"docker image build --no-cache -t dockerignore-build-context -f {docker_path} .".split(),
|
||||
env=env,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
"docker run -it --rm dockerignore-build-context".split(),
|
||||
env=env,
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
"docker image rm dockerignore-build-context".split(),
|
||||
env=env,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(
|
||||
",di",
|
||||
description="Shows all files in a project seen by Docker after applying an ignore file.",
|
||||
)
|
||||
parser.add_argument("file")
|
||||
args = parser.parse_args()
|
||||
dockerignore_check(args)
|
||||
6
bin/,nixup
Executable file
6
bin/,nixup
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
pushd $SCRIPT_DIR/../nix &> /dev/null
|
||||
home-manager switch --flake ".#std"
|
||||
Reference in New Issue
Block a user