Skip to content

Commit

Permalink
Add proper image delegation to nix-exec
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgijssel committed Aug 30, 2024
1 parent 1872c42 commit dcb9cba
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
43 changes: 43 additions & 0 deletions 3rdparty/python/default.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// "CPython==3.10.*"
// ],
// "generated_with_requirements": [
// "deepdiff==8.0.1",
// "parsedatetime==2.6",
// "psutil==6.0.0"
// ],
Expand All @@ -28,6 +29,47 @@
"locked_resolves": [
{
"locked_requirements": [
{
"artifacts": [
{
"algorithm": "sha256",
"hash": "42e99004ce603f9a53934c634a57b04ad5900e0d8ed0abb15e635767489cbc05",
"url": "https://files.pythonhosted.org/packages/06/46/01673060e83277a863baf0909b387cd809865cba2d5e7213db76516bedd9/deepdiff-8.0.1-py3-none-any.whl"
},
{
"algorithm": "sha256",
"hash": "245599a4586ab59bb599ca3517a9c42f3318ff600ded5e80a3432693c8ec3c4b",
"url": "https://files.pythonhosted.org/packages/62/ba/aced1d6a7d988ca1b6f9b274faed7dafc7356a733e45a457819bddcf2dbc/deepdiff-8.0.1.tar.gz"
}
],
"project_name": "deepdiff",
"requires_dists": [
"click==8.1.7; extra == \"cli\"",
"orderly-set==5.2.2",
"orjson; extra == \"optimize\"",
"pyyaml==6.0.1; extra == \"cli\""
],
"requires_python": ">=3.8",
"version": "8.0.1"
},
{
"artifacts": [
{
"algorithm": "sha256",
"hash": "f7a37c95a38c01cdfe41c3ffb62925a318a2286ea0a41790c057fc802aec54da",
"url": "https://files.pythonhosted.org/packages/69/71/6f9554919da608cb5bcf709822a9644ba4785cc7856e01ea375f6d808774/orderly_set-5.2.2-py3-none-any.whl"
},
{
"algorithm": "sha256",
"hash": "52a18b86aaf3f5d5a498bbdb27bf3253a4e5c57ab38e5b7a56fa00115cd28448",
"url": "https://files.pythonhosted.org/packages/c8/71/5408fee86ce5408132a3ece6eff61afa2c25d5b37cd76bc100a9a4a4d8dd/orderly_set-5.2.2.tar.gz"
}
],
"project_name": "orderly-set",
"requires_dists": [],
"requires_python": ">=3.8",
"version": "5.2.2"
},
{
"artifacts": [
{
Expand Down Expand Up @@ -101,6 +143,7 @@
"pip_version": "24.0",
"prefer_older_binary": false,
"requirements": [
"deepdiff==8.0.1",
"parsedatetime==2.6",
"psutil==6.0.0"
],
Expand Down
3 changes: 2 additions & 1 deletion 3rdparty/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
psutil==6.0.0
parsedatetime==2.6
parsedatetime==2.6
deepdiff==8.0.1
34 changes: 1 addition & 33 deletions bastion/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,13 @@ files(
],
)

# shell_command(
# name = "image",
# timeout = 600,
# command = "./build.sh $(cat ./image-builder.docker-info.json | jq -r '.image_id')",
# execution_dependencies = [
# ":image-builder",
# ":bastion-files",
# ],
# output_files = [
# "bastion.qcow2",
# ],
# runnable_dependencies = [":jq"],
# tools = [
# "bash",
# "cat",
# "docker",
# "ls",
# ],
# )

# Interesting! We're able to pass environment variables directly
# into the shell command using `env` target.
# To prevent cache invalidation etc, probably best to use a stable
# location for the temporary directory for pants.
# That way we can hardcode it as well.
# run_shell_command(
# name = "kerk",
# command = f"""
# echo {env("KERK")}
# """,
# )

shell_command(
name = "image",
timeout = 600,
# command = "./build.sh $(cat ./image-builder.docker-info.json | jq -r '.image_id')",
command = """
export NIX_EXEC_WORKDIR=$(pwd)
# export NIX_EXEC_IMAGE=$(cat ./image-builder.docker-info.json | jq -r '.image_id')
export NIX_EXEC_IMAGE=$(cat ./image-builder.docker-info.json | jq -r '.image_id')
nix build .#qcow
""",
Expand Down
4 changes: 2 additions & 2 deletions bin/nix-exec
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fi

NIX_EXEC_IMAGE="${NIX_EXEC_IMAGE:-image-builder:dev}"

# Mounting the full disk "/" to allow the binary to work both from the host
# and from within the pants sandbox.
exec delegator \
--name nix-exec \
# Mounting the full disk to allow the binary to work both from the host
# and from within the pants sandbox.
--volume "/" \
--image "$NIX_EXEC_IMAGE" \
--timeout "12 hours" \
Expand Down
11 changes: 10 additions & 1 deletion delegator/delegator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from dataclasses import asdict, dataclass, field
from pathlib import Path

from deepdiff import DeepDiff

from .utils import setup_logging, validate_timeout

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -132,10 +134,16 @@ def is_container_running(settings: Settings) -> bool:
# Cannot compare Settings class to Settings class, because maybe the settings have changed.
# Therefore comparing the dicts to see if there is any difference
container_settings_data = json.loads(container_state["settings"])
LOGGER.debug("Current settings:\n%s", container_settings_data)

settings_data = asdict(settings)
LOGGER.debug("New settings:\n%s", settings_data)

diff = DeepDiff(container_settings_data, settings_data)

if container_settings_data != settings_data:
if len(diff) > 0:
LOGGER.info("Container settings have changed. Removing.")
LOGGER.debug("Diff\n" + diff.pretty())
remove_container(settings)
return False

Expand Down Expand Up @@ -221,6 +229,7 @@ def main():
"--volume",
required=False,
help="Map a local directory into the delegator container.",
default=[],
action="append",
)
parser.add_argument(
Expand Down

0 comments on commit dcb9cba

Please sign in to comment.