Skip to content

Commit

Permalink
update docs and CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickvP committed Apr 10, 2024
1 parent 4f49673 commit a6356d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Build cog images deterministically using Nix.

## Example (./examples/torch-demo/default.nix):
```
# build the image and stream it to docker
$ nix build github:yorickvp/cognix#torch-demo && ./result | docker load
# build the image and load it into docker
$ nix build github:yorickvp/cognix#torch-demo && ./result load
$ cog predict torch-demo:......
Expand All @@ -29,7 +29,7 @@ $ nix path-info ./result -rSsh | sort -hk3
## Example (./examples/ebsynth-cpu/default.nix):
```
$ git clone ...
$ nix build .#ebsynth-cpu && ./result | docker load
$ nix build .#ebsynth-cpu && ./result load
$ cog predict ebsynth-cpu:...... -i style=@...
```

Expand Down
17 changes: 9 additions & 8 deletions pkgs/cognix-cli/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ def lock(cli):
# todo: add lockfile to git (git add --intend-to-add?)

@cli.command()
# @click.option("-t", "--tag", default="")
@click.pass_context
def build(cli):
call_nix(cli, "build", "", ["--no-link"])
# hash = cli.invoke(load)
# if tag:
# subprocess.run(["docker", "tag", hash, tag], check=True)


def get_tag(cmd: str) -> str:
Expand All @@ -77,6 +73,7 @@ def get_tag(cmd: str) -> str:
return json_content["repo_tag"]

@cli.command()
# @click.option("-t", "--tag", default="")
@click.pass_context
def load(cli):
cli.invoke(build)
Expand All @@ -87,7 +84,9 @@ def load(cli):
if subprocess.run(["docker", "image", "inspect", tag], check=False, capture_output=True).returncode == 0:
print("Already loaded into docker:", tag)
return tag
subprocess.run(f"{cmd} | docker load", check=True, shell=True)
subprocess.run(f"{cmd} load", check=True, shell=True)
# if tag:
# subprocess.run(["docker", "tag", hash, tag], check=True)
return tag

@cli.command()
Expand All @@ -101,9 +100,11 @@ def run(cli, args):
@click.argument("name", nargs=1)
@click.pass_context
def push(cli, name):
tag = cli.invoke(load)
subprocess.run(["docker", "tag", tag, name], check=True)
subprocess.run(["docker", "push", name], check=True)
cli.invoke(build)
f = call_nix(cli, "build", "", ["--json", "--no-link"], capture_output=True)
result = json.loads(f.stdout)
cmd = result[0]["outputs"]["out"]
subprocess.run([cmd, "push", name], check=True)

@cli.command(name="push-weights")
@click.pass_context
Expand Down

0 comments on commit a6356d1

Please sign in to comment.