Skip to content

Commit f9805cd

Browse files
committed
feat!: expand environments specification (#338)
This is a breaking change in the API. It requires changes in the UI for it to be fully useful.
1 parent 024c770 commit f9805cd

File tree

15 files changed

+1130
-380
lines changed

15 files changed

+1130
-380
lines changed

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,19 @@ components/renku_data_services/data_connectors/apispec.py: components/renku_data
4545

4646
##@ Apispec
4747

48-
schemas: components/renku_data_services/crc/apispec.py components/renku_data_services/storage/apispec.py components/renku_data_services/users/apispec.py components/renku_data_services/project/apispec.py components/renku_data_services/namespace/apispec.py components/renku_data_services/secrets/apispec.py components/renku_data_services/connected_services/apispec.py components/renku_data_services/repositories/apispec.py components/renku_data_services/notebooks/apispec.py components/renku_data_services/platform/apispec.py components/renku_data_services/message_queue/apispec.py components/renku_data_services/data_connectors/apispec.py ## Generate pydantic classes from apispec yaml files
48+
schemas: components/renku_data_services/crc/apispec.py \
49+
components/renku_data_services/storage/apispec.py \
50+
components/renku_data_services/users/apispec.py \
51+
components/renku_data_services/project/apispec.py \
52+
components/renku_data_services/session/apispec.py \
53+
components/renku_data_services/namespace/apispec.py \
54+
components/renku_data_services/secrets/apispec.py \
55+
components/renku_data_services/connected_services/apispec.py \
56+
components/renku_data_services/repositories/apispec.py \
57+
components/renku_data_services/notebooks/apispec.py \
58+
components/renku_data_services/platform/apispec.py \
59+
components/renku_data_services/message_queue/apispec.py \
60+
components/renku_data_services/data_connectors/apispec.py ## Generate pydantic classes from apispec yaml files
4961
@echo "generated classes based on ApiSpec"
5062

5163
##@ Avro schemas
@@ -90,6 +102,8 @@ style_checks: ## Run linting and style checks
90102
@$(call test_apispec_up_to_date,"platform")
91103
@echo "checking message_queue apispec is up to date"
92104
@$(call test_apispec_up_to_date,"message_queue")
105+
@echo "checking session apispec is up to date"
106+
@$(call test_apispec_up_to_date,"session")
93107
poetry run mypy
94108
poetry run ruff format --check
95109
poetry run ruff check .
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Add command and args to environment
2+
3+
Revision ID: 1ef98b967767
4+
Revises: 584598f3b769
5+
Create Date: 2024-08-25 21:05:02.158021
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from sqlalchemy.dialects import postgresql
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "1ef98b967767"
15+
down_revision = "584598f3b769"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade() -> None:
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.add_column(
23+
"environments",
24+
sa.Column("args", sa.JSON().with_variant(postgresql.JSONB(astext_type=sa.Text()), "postgresql"), nullable=True),
25+
schema="sessions",
26+
)
27+
op.add_column(
28+
"environments",
29+
sa.Column(
30+
"command", sa.JSON().with_variant(postgresql.JSONB(astext_type=sa.Text()), "postgresql"), nullable=True
31+
),
32+
schema="sessions",
33+
)
34+
# ### end Alembic commands ###
35+
36+
37+
def downgrade() -> None:
38+
# ### commands auto generated by Alembic - please adjust! ###
39+
op.drop_column("environments", "command", schema="sessions")
40+
op.drop_column("environments", "args", schema="sessions")
41+
# ### end Alembic commands ###
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"""expand and separate environments from session launchers
2+
3+
Revision ID: 584598f3b769
4+
Revises: 9058bf0a1a12
5+
Create Date: 2024-08-12 14:25:24.292285
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from sqlalchemy.dialects import postgresql
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "584598f3b769"
15+
down_revision = "9058bf0a1a12"
16+
branch_labels = None
17+
depends_on = None
18+
19+
default_url: str = "/lab"
20+
working_dir: str = "/home/jovyan/work"
21+
mount_dir: str = "/home/jovyan/work"
22+
uid: int = 1000
23+
gid: int = 1000
24+
port: int = 8888
25+
26+
27+
def upgrade() -> None:
28+
# ### commands auto generated by Alembic - please adjust! ###
29+
op.execute("DELETE FROM sessions.launchers")
30+
op.drop_column("launchers", "default_url", schema="sessions")
31+
op.drop_column("launchers", "environment_kind", schema="sessions")
32+
op.drop_column("launchers", "container_image", schema="sessions")
33+
op.execute("DROP TYPE environmentkind CASCADE")
34+
op.execute("CREATE TYPE environmentkind AS ENUM ('GLOBAL', 'CUSTOM')")
35+
op.add_column("environments", sa.Column("port", sa.Integer(), nullable=True), schema="sessions")
36+
op.add_column("environments", sa.Column("working_directory", sa.String(), nullable=True), schema="sessions")
37+
op.add_column("environments", sa.Column("mount_directory", sa.String(), nullable=True), schema="sessions")
38+
op.add_column("environments", sa.Column("uid", sa.Integer(), nullable=True), schema="sessions")
39+
op.add_column("environments", sa.Column("gid", sa.Integer(), nullable=True), schema="sessions")
40+
op.add_column(
41+
"environments",
42+
sa.Column("environment_kind", sa.Enum("GLOBAL", "CUSTOM", name="environmentkind"), nullable=True),
43+
schema="sessions",
44+
)
45+
op.execute(sa.text("UPDATE sessions.environments SET port = :port WHERE port is NULL").bindparams(port=port))
46+
op.execute(
47+
sa.text(
48+
"UPDATE sessions.environments SET working_directory = :working_dir WHERE working_directory is NULL"
49+
).bindparams(working_dir=working_dir)
50+
)
51+
op.execute(
52+
sa.text(
53+
"UPDATE sessions.environments SET mount_directory = :mount_dir WHERE mount_directory is NULL"
54+
).bindparams(mount_dir=mount_dir)
55+
)
56+
op.execute(sa.text("UPDATE sessions.environments SET uid = :uid WHERE uid is NULL").bindparams(uid=uid))
57+
op.execute(sa.text("UPDATE sessions.environments SET gid = :gid WHERE gid is NULL").bindparams(gid=gid))
58+
op.execute("UPDATE sessions.environments SET environment_kind = 'GLOBAL' WHERE environment_kind is NULL")
59+
op.execute(
60+
sa.text("UPDATE sessions.environments SET default_url = :default_url WHERE default_url is NULL").bindparams(
61+
default_url=default_url
62+
)
63+
)
64+
op.alter_column("environments", "port", nullable=False, schema="sessions")
65+
op.alter_column("environments", "working_directory", nullable=False, schema="sessions")
66+
op.alter_column("environments", "mount_directory", nullable=False, schema="sessions")
67+
op.alter_column("environments", "uid", nullable=False, schema="sessions")
68+
op.alter_column("environments", "gid", nullable=False, schema="sessions")
69+
op.alter_column("environments", "environment_kind", nullable=False, schema="sessions")
70+
op.alter_column(
71+
"environments", "default_url", existing_type=sa.VARCHAR(length=200), nullable=False, schema="sessions"
72+
)
73+
# ### end Alembic commands ###
74+
75+
76+
def downgrade() -> None:
77+
# ### commands auto generated by Alembic - please adjust! ###
78+
op.drop_column("environments", "environment_kind", schema="sessions")
79+
op.drop_column("environments", "gid", schema="sessions")
80+
op.drop_column("environments", "uid", schema="sessions")
81+
op.drop_column("environments", "mount_directory", schema="sessions")
82+
op.drop_column("environments", "working_directory", schema="sessions")
83+
op.drop_column("environments", "port", schema="sessions")
84+
op.execute("DROP TYPE environmentkind")
85+
op.execute("CREATE TYPE environmentkind AS ENUM ('global_environment', 'container_image')")
86+
op.add_column(
87+
"launchers",
88+
sa.Column("container_image", sa.VARCHAR(length=500), autoincrement=False, nullable=True),
89+
schema="sessions",
90+
)
91+
op.add_column(
92+
"launchers",
93+
sa.Column(
94+
"environment_kind",
95+
postgresql.ENUM("global_environment", "container_image", name="environmentkind"),
96+
autoincrement=False,
97+
nullable=False,
98+
),
99+
schema="sessions",
100+
)
101+
op.add_column(
102+
"launchers",
103+
sa.Column("default_url", sa.VARCHAR(length=200), autoincrement=False, nullable=True),
104+
schema="sessions",
105+
)
106+
op.alter_column(
107+
"environments", "default_url", existing_type=sa.VARCHAR(length=200), nullable=True, schema="sessions"
108+
)
109+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)