Skip to content

Commit

Permalink
Removing specifications from api provided via build route
Browse files Browse the repository at this point in the history
  • Loading branch information
costrouc committed Jul 31, 2021
1 parent 6ae466e commit e3b3dc2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 125 deletions.
1 change: 0 additions & 1 deletion conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ def register_environment(
orm.Environment(
name=specification.name,
namespace_id=namespace.id,
specification_id=specification.id,
build_id=build.id,
)
)
Expand Down
3 changes: 0 additions & 3 deletions conda-store-server/conda_store_server/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ class Environment(Base):

name = Column(String, nullable=False)

specification_id = Column(Integer, ForeignKey("specification.id"))
specification = relationship(Specification)

build_id = Column(Integer, ForeignKey("build.id"))
build = relationship(Build)

Expand Down
28 changes: 13 additions & 15 deletions conda-store-server/conda_store_server/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ class Config:
orm_mode = True


class Specification(BaseModel):
id: int
name: str
spec: dict
sha256: str
created_on: datetime.datetime

class Config:
orm_mode = True


class Build(BaseModel):
id: int
namespace: Namespace
specification_id: int
specification: Specification
packages: List[CondaPackage]
status: enum.Enum
size: int
Expand All @@ -75,25 +86,12 @@ class Config:
use_enum_values = True


class Specification(BaseModel):
id: int
name: str
spec: dict
sha256: str
created_on: datetime.datetime
builds: List[Build]

class Config:
orm_mode = True


class Environment(BaseModel):
id: int
namespace: Namespace
name: str
build_id: Optional[int]
specification_id: Optional[int]
specification: Optional[Specification]
build: Optional[Build]

class Config:
orm_mode = True
Expand Down
16 changes: 13 additions & 3 deletions conda-store-server/conda_store_server/server/templates/build.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ <h3 class="card-title">Build {{ build.id }}

<dt class="col-sm-3">status</dt>
<dd class="col-sm-9">{{ build.status.value }}</dd>

<dt class="col-sm-3">specification</dt>
<dd class="col-sm-9"><a href="/specification/{{ build.specification.sha256 }}/">{{ build.specification.sha256[:8] }}</a></dd>
</dl>

<div class="card-body">
<div id="editor" style="height: 300px;">{{ spec }}</div>
</div>
</p>
</div>

Expand Down Expand Up @@ -79,4 +80,13 @@ <h3 class="card-title">Conda Environment Artifacts</h3>
</div>
</div>
{% endif %}

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js" integrity="sha512-GZ1RIgZaSc8rnco/8CXfRdCpDxRCphenIiZ2ztLy3XQfCbQUSCuk8IudvNHxkRA3oUg6q0qejgN/qqyG1duv5Q==" crossorigin="anonymous"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/github");
editor.getSession().setMode("ace/mode/yaml");
editor.setFontSize("20px");
editor.setReadOnly(true);
</script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ <h5 class="card-title">{{ environment.namespace.name }}/{{ environment.name }}
</h5>
</div>
<ul class="list-group list-group-flush">
{% if environment.specification_id is not none %}
<li class="list-group-item"><a href="/specification/{{ environment.specification.sha256 }}/">Current Specification</a></li>
{% endif %}
{% if environment.build_id is not none %}
<li class="list-group-item"><a href="/build/{{ environment.build_id }}/">Current Build</a></li>
{% endif %}
<li class="list-group-item">
<div class="card-body">
<div id="editor" style="height: 300px;">{{ spec }}</div>
</div>
</li>
</ul>
<div class="card-body">
<a href="/environment/{{ environment.namespace.name }}/{{ environment.name }}/edit/" class="btn btn-primary btn-block">Edit</a>
Expand Down Expand Up @@ -46,16 +45,23 @@ <h3>Builds</h3>
{% endfor %}
</ul>

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js" integrity="sha512-GZ1RIgZaSc8rnco/8CXfRdCpDxRCphenIiZ2ztLy3XQfCbQUSCuk8IudvNHxkRA3oUg6q0qejgN/qqyG1duv5Q==" crossorigin="anonymous"></script>
<script>
function updateEnvironmentBuild(buildId) {
var editor = ace.edit("editor");
editor.setTheme("ace/theme/github");
editor.getSession().setMode("ace/mode/yaml");
editor.setFontSize("20px");
editor.setReadOnly(true);

function updateEnvironmentBuild(buildId) {
fetch(`/api/v1/environment/{{ environment.namespace.name }}/{{ environment.name }}/`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({"buildId": buildId})
})
}
}

function buildAction(method, buildId) {
fetch(`/api/v1/build/${buildId}/`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h5 class="card-title">
<a class="card-link" href="/build/{{ environment.build_id }}/yaml/"><ion-icon name="code-download"></ion-icon> YAML</a>
<a class="card-link" href="/build/{{ environment.build_id }}/lockfile/"><ion-icon name="lock-closed-outline"></ion-icon> Lockfile</a>
<a class="card-link" href="/build/{{ environment.build_id }}/archive/"><ion-icon name="archive-outline"></ion-icon> Archive</a>
<a class="card-link" onclick="setClipboard('localhost:5000/{{ environment.namespace }}/{{ environment.name }}:{{ environment.specification.sha256 }}')"><ion-icon name="logo-docker"></ion-icon> Docker</a>
<a class="card-link" onclick="setClipboard('localhost:5000/{{ environment.namespace }}/{{ environment.name }}:{{ environment.build.specification.sha256 }}')"><ion-icon name="logo-docker"></ion-icon> Docker</a>
{% endif %}
</div>
</div>
Expand Down

This file was deleted.

33 changes: 7 additions & 26 deletions conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def api_list_environments():
orm_environments = auth.filter_environments(
api.list_environments(conda_store.db))
environments = [
schema.Environment.from_orm(_).dict(exclude={"specification": {"builds"}})
schema.Environment.from_orm(_).dict(exclude={"build"})
for _ in orm_environments.all()
]
return jsonify(environments)
Expand All @@ -52,10 +52,11 @@ def api_get_environment(namespace, name):
{Permissions.ENVIRONMENT_READ},
require=True)

environment = schema.Environment.from_orm(
api.get_environment(conda_store.db, namespace=namespace, name=name)
).dict()
return jsonify(environment)
environment = api.get_environment(conda_store.db, namespace=namespace, name=name)
if environment is None:
return jsonify({"status": "error", "error": "environment does not exist"}), 404

return jsonify(schema.Environment.from_orm(environment).dict())


@app_api.route("/api/v1/environment/<namespace>/<name>/", methods=["PUT"])
Expand All @@ -73,17 +74,6 @@ def api_update_environment_build(namespace, name):
return jsonify({"status": "ok"})


@app_api.route("/api/v1/specification/", methods=["GET"])
def api_list_specification():
conda_store = get_conda_store()
orm_specifications = api.list_specifications(conda_store.db)
specifications = [
schema.Specification.from_orm(_).dict(exclude={"builds"})
for _ in orm_specifications
]
return jsonify(specifications)


@app_api.route("/api/v1/specification/", methods=["POST"])
def api_post_specification():
conda_store = get_conda_store()
Expand All @@ -95,15 +85,6 @@ def api_post_specification():
return jsonify({"status": "error", "error": e.errors()}), 400


@app_api.route("/api/v1/specification/<sha256>/", methods=["GET"])
def api_get_specification(sha256):
conda_store = get_conda_store()
specification = schema.Specification.from_orm(
api.get_specification(conda_store.db, sha256)
)
return jsonify(specification.dict(exclude={"builds"}))


@app_api.route("/api/v1/build/", methods=["GET"])
def api_list_builds():
conda_store = get_conda_store()
Expand All @@ -112,7 +93,7 @@ def api_list_builds():
orm_builds = auth.filter_builds(
api.list_builds(conda_store.db))
builds = [
schema.Build.from_orm(build).dict(exclude={"packages"}) for build in orm_builds.all()
schema.Build.from_orm(build).dict(exclude={"specification", "packages"}) for build in orm_builds.all()
]
return jsonify(builds)

Expand Down
46 changes: 24 additions & 22 deletions conda-store-server/conda_store_server/server/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ def ui_get_environment(namespace, name):
{Permissions.ENVIRONMENT_READ},
require=True)

environment = api.get_environment(conda_store.db, namespace=namespace, name=name)
if environment is None:
return render_template("404.html", message=f"environment namespace={namespace} name={name} not found"), 404

return render_template(
"environment.html",
environment=api.get_environment(conda_store.db, namespace=namespace, name=name),
environment=environment,
environment_builds=api.get_environment_builds(conda_store.db, namespace, name),
spec=yaml.dump(environment.build.specification.spec),
)


Expand All @@ -86,29 +91,21 @@ def ui_edit_environment(namespace, name):

auth = get_auth()
auth.authorize_request(
f'{namespace}/{name}', {Permissions.ENVIRONMENT_CREATE}, require=True)
f'{namespace}/{name}',
{Permissions.ENVIRONMENT_CREATE},
require=True)

environment = api.get_environment(conda_store.db, namespace=namespace, name=name)
specification = api.get_specification(
environment = api.get_environment(
conda_store.db,
environment.specification.sha256,
)
namespace = api.get_namespace(conda_store.db, namespace)
return render_template(
"create.html",
specification=yaml.dump(specification.spec),
namespaces=[namespace],
)
namespace=namespace,
name=name)
if environment is None:
return render_template("404.html", message=f"environment namespace={namespace} name={nme} not found"), 404


@app_ui.route("/specification/<sha256>/", methods=["GET"])
def ui_get_specification(sha256):
conda_store = get_conda_store()
specification = api.get_specification(conda_store.db, sha256)
return render_template(
"specification.html",
specification=specification,
spec=yaml.dump(specification.spec),
"create.html",
specification=yaml.dump(environment.build.specification.spec),
namespaces=[environment.namespace],
)


Expand All @@ -119,14 +116,19 @@ def ui_get_build(build_id):

build = api.get_build(conda_store.db, build_id)
if build is None:
return render_template("404.html", message=f"build {build_id} not found"), 404
return render_template("404.html", message=f"build id={build_id} not found"), 404

auth.authorize_request(
f'{build.namespace.name}/{build.specification.name}',
{Permissions.ENVIRONMENT_READ},
require=True)

return render_template("build.html", build=build, platform=conda_platform())
return render_template(
"build.html",
build=build,
platform=conda_platform(),
spec=yaml.dump(build.specification.spec),
)


@app_ui.route("/build/<build_id>/logs/", methods=["GET"])
Expand Down

0 comments on commit e3b3dc2

Please sign in to comment.