Skip to content

Commit b14e56b

Browse files
redesign repos
1 parent f06a628 commit b14e56b

33 files changed

Lines changed: 639 additions & 678 deletions

.github/workflows/ci.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,3 @@ jobs:
7171
pip install -r requirements.txt
7272
- name: Test
7373
run: make test
74-
75-
release:
76-
needs: [test, test-end-to-end]
77-
if: startsWith(github.ref, 'refs/tags/v')
78-
runs-on: ubuntu-latest
79-
steps:
80-
- uses: actions/checkout@v2
81-
with:
82-
fetch-depth: 0
83-
- uses: actions/setup-go@v2
84-
with:
85-
go-version: 1.16
86-
- uses: goreleaser/goreleaser-action@v2
87-
with:
88-
version: latest
89-
args: release --rm-dist
90-
env:
91-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ model: "model.py:JazzSoloComposerModel"
4040
3. Build and push the model:
4141
4242
```
43-
$ cog remote set http://10.1.2.3:8000
43+
$ cog repo set http://10.1.2.3:8000
4444
$ cog build
4545
...
4646
--> Built and pushed b6a2f8a2d2ff
@@ -82,13 +82,9 @@ When that has finished, you can run inferences on the built model from any machi
8282

8383
cog infer b31f9f72d8f14f0eacc5452e85b05c957b9a8ed9 -i @hotdog.jpg
8484

85-
You can list packages to see the built package:
86-
87-
cog list
88-
8985
You can see more details about the package:
9086

91-
cog show b31f9f72d8f14f0eacc5452e85b05c957b9a8ed9
87+
cog show b31f9f72d8f14f0eacc5452e85b05c957b9a8ed9
9288

9389
In this output is the Docker image. You can run this anywhere a Docker image runs to deploy your model.
9490

@@ -100,14 +96,14 @@ No docs yet -- sorry! It should be pretty self-explanatory from the examples.
10096

10197
## Server API
10298

103-
### POST `/v1/packages/upload`
99+
### PUT `/v1/packages/<user>/<name>/`
104100

105101
Upload a new package.
106102

107103
Example:
108104

109105
```
110-
$ curl -X POST localhost:8080/v1/packages/upload -F "[email protected]"
106+
$ curl -X PUT localhost:8080/v1/packages/andreas/my-model/ -F "[email protected]"
111107
```
112108

113109
where `package.zip` is a zip folder of a directory with `cog.yaml` in it.
@@ -120,25 +116,23 @@ This does the following:
120116
* Tests that the model works by running the Docker image locally and performing an inference
121117
* Inserts model metadata into database (local files)
122118

123-
### GET `/v1/packages/<id>`
119+
### GET `/v1/packages/<user>/<name>`
124120

125121
Fetch package metadata.
126122

127123
Example:
128124

129125
```
130-
$ curl localhost:8080/v1/packages/c43b98b37776656e6b3dac3ea3270660ffc21ca7 | jq .
126+
$ curl localhost:8080/v1/packages/andreas/my-model/c43b98b37776656e6b3dac3ea3270660ffc21ca7 | jq .
131127
{
132128
"ID": "c43b98b37776656e6b3dac3ea3270660ffc21ca7",
133-
"Name": "andreas/scratch",
134129
"Artifacts": [
135130
{
136131
"Target": "docker-cpu",
137132
"URI": "us-central1-docker.pkg.dev/replicate/andreas-scratch/andreas/scratch:2c7492b7d3d6"
138133
}
139134
],
140135
"Config": {
141-
"Name": "andreas/scratch",
142136
"Environment": {
143137
"PythonVersion": "3.8",
144138
"PythonRequirements": "",
@@ -155,36 +149,16 @@ $ curl localhost:8080/v1/packages/c43b98b37776656e6b3dac3ea3270660ffc21ca7 | jq
155149
}
156150
```
157151

158-
### GET `/v1/packages/<id>.zip`
152+
### GET `/v1/packages/<user>/<name>/<id>.zip`
159153

160154
Download the package.
161155

162156
Example:
163157

164158
```
165-
$ curl localhost:8080/v1/packages/c43b98b37776656e6b3dac3ea3270660ffc21ca7.zip > my-package.zip
159+
$ curl localhost:8080/v1/packages/andreas/my-model/c43b98b37776656e6b3dac3ea3270660ffc21ca7.zip > my-package.zip
166160
$ unzip my-package.zip
167161
Archive: my-package.zip
168162
inflating: cog.yaml
169163
inflating: infer.py
170164
```
171-
172-
### GET `/v1/packages/`
173-
174-
List all packages.
175-
176-
Example:
177-
178-
```
179-
$ curl localhost:8080/v1/packages/ | jq .
180-
[
181-
{
182-
"ID": "af3ff5288247833f5f9d8d9f6ecd5fe2b586f6aa",
183-
"Name": "andreas/fastgan",
184-
"Artifacts": [
185-
{
186-
"Target": "docker-cpu",
187-
"URI": "us-central1-docker.pkg.dev/replicate/andreas-scratch/andreas/fastgan:a034b8a9bf46"
188-
},
189-
[...]
190-
```

end-to-end-test/end_to_end_test/test_server.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import random
2+
import string
13
from glob import glob
24
import os
3-
from os.path import basename
45
import tempfile
56
import socket
67
from contextlib import closing
@@ -25,31 +26,19 @@ def cog_server_port_dir():
2526
)
2627
assert resp.text == "pong"
2728

28-
out, err = subprocess.Popen(
29-
["cog", "remote"],
30-
stdout=subprocess.PIPE,
31-
stderr=subprocess.PIPE,
32-
).communicate()
33-
old_remote = out.decode().strip()
34-
35-
out, err = subprocess.Popen(
36-
["cog", "remote", "set", "http://localhost:" + port],
37-
stdout=subprocess.PIPE,
38-
stderr=subprocess.PIPE,
39-
).communicate()
40-
assert out.decode() == f"Updated remote: http://localhost:{port}\n"
41-
assert err == b""
42-
4329
yield port, cog_dir
4430

4531
os.chdir(old_cwd)
4632
server_proc.kill()
4733

48-
subprocess.Popen(["cog", "remote", "set", old_remote]).communicate()
49-
5034

5135
def test_build_show_list_download_infer(cog_server_port_dir, tmpdir_factory):
5236
cog_port, cog_dir = cog_server_port_dir
37+
38+
user = "".join(random.choice(string.ascii_lowercase) for i in range(10))
39+
repo_name = "".join(random.choice(string.ascii_lowercase) for i in range(10))
40+
repo = f"localhost:{cog_port}/{user}/{repo_name}"
41+
5342
project_dir = tmpdir_factory.mktemp("project")
5443
with open(project_dir / "infer.py", "w") as f:
5544
f.write(
@@ -88,6 +77,13 @@ def run(self, text, path):
8877
"""
8978
)
9079

80+
out, _ = subprocess.Popen(
81+
["cog", "repo", "set", f"localhost:{cog_port}/{user}/{repo_name}"],
82+
stdout=subprocess.PIPE,
83+
cwd=project_dir,
84+
).communicate()
85+
assert out.decode() == f"Updated repo: localhost:{cog_port}/{user}/{repo_name}\n"
86+
9187
with open(project_dir / "myfile.txt", "w") as f:
9288
f.write("baz")
9389

@@ -103,19 +99,25 @@ def run(self, text, path):
10399
package_id = out.decode().strip().split("Successfully built ")[1]
104100

105101
out, _ = subprocess.Popen(
106-
["cog", "show", package_id], stdout=subprocess.PIPE
102+
["cog", "-r", repo, "show", package_id], stdout=subprocess.PIPE
107103
).communicate()
108104
lines = out.decode().splitlines()
109105
assert lines[0] == f"ID: {package_id}"
110-
assert lines[1] == "Name: andreas/hello-world"
106+
assert lines[1] == f"Repo: {user}/{repo_name}"
111107

112-
out, _ = subprocess.Popen(["cog", "ls"], stdout=subprocess.PIPE).communicate()
108+
# show without -r
109+
out, _ = subprocess.Popen(
110+
["cog", "show", package_id],
111+
stdout=subprocess.PIPE,
112+
cwd=project_dir,
113+
).communicate()
113114
lines = out.decode().splitlines()
114-
assert lines[1].startswith(f"{package_id} andreas/hello-world")
115+
assert lines[0] == f"ID: {package_id}"
116+
assert lines[1] == f"Repo: {user}/{repo_name}"
115117

116118
download_dir = tmpdir_factory.mktemp("download") / "my-dir"
117119
subprocess.Popen(
118-
["cog", "download", "--output-dir", download_dir, package_id],
120+
["cog", "-r", repo, "download", "--output-dir", download_dir, package_id],
119121
stdout=subprocess.PIPE,
120122
).communicate()
121123
paths = sorted(glob(str(download_dir / "*.*")))
@@ -129,7 +131,19 @@ def run(self, text, path):
129131

130132
out_path = output_dir / "out.txt"
131133
subprocess.Popen(
132-
["cog", "infer", "-o", out_path, "-i", "text=baz", "-i", f"path=@{input_path}", package_id],
134+
[
135+
"cog",
136+
"-r",
137+
repo,
138+
"infer",
139+
"-o",
140+
out_path,
141+
"-i",
142+
"text=baz",
143+
"-i",
144+
f"path=@{input_path}",
145+
package_id,
146+
],
133147
stdout=subprocess.PIPE,
134148
).communicate()
135149
with out_path.open() as f:

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/docker/go-units v0.4.0 // indirect
1313
github.com/golang/protobuf v1.4.3 // indirect
1414
github.com/google/go-cmp v0.5.4 // indirect
15+
github.com/gopherdata/gophernotes v0.7.2 // indirect
1516
github.com/gorilla/mux v1.8.0
1617
github.com/kr/text v0.2.0 // indirect
1718
github.com/mholt/archiver/v3 v3.5.0
@@ -23,6 +24,8 @@ require (
2324
github.com/onsi/gomega v1.4.3 // indirect
2425
github.com/opencontainers/go-digest v1.0.0 // indirect
2526
github.com/opencontainers/image-spec v1.0.1 // indirect
27+
github.com/pebbe/zmq4 v0.0.0-20170917105202-90d69e412a09 // indirect
28+
github.com/satori/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5 // indirect
2629
github.com/schollz/progressbar/v3 v3.7.6
2730
github.com/sirupsen/logrus v1.7.0
2831
github.com/spf13/cobra v1.1.3

0 commit comments

Comments
 (0)