Skip to content

Commit

Permalink
feat(service): allow setting default CLI version for project creation (
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Apr 27, 2023
1 parent 00a1963 commit 9f16b0a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions helm-chart/renku-core/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ spec:
value: {{ $.Values.gitLFSSkipSmudge | quote }}
- name: RENKU_DOMAIN
value: {{ $.Values.global.renku.domain }}
- name: RENKU_PROJECT_DEFAULT_CLI_VERSION
value: {{ $.Values.global.renku.cli_version | default "" | quote }}
{{- include "certificates.env.python" $ | nindent 12 }}
volumeMounts:
- name: shared-volume
Expand Down
2 changes: 1 addition & 1 deletion renku/command/command_builder/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _injection_pre_hook(self, builder: Command, context: dict, *args, **kwargs)

current_version = Version(__version__)

if current_version < minimum_renku_version:
if Version(current_version.base_version) < minimum_renku_version:
raise errors.MinimumVersionError(current_version, minimum_renku_version)

def _post_hook(self, builder: Command, context: dict, result: CommandResult, *args, **kwargs) -> None:
Expand Down
7 changes: 5 additions & 2 deletions renku/ui/service/controllers/templates_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Renku service template create project controller."""
import os
import shutil
from typing import Any, Dict, Optional, cast

Expand Down Expand Up @@ -72,8 +73,10 @@ def default_metadata(self):
"__project_slug__": self.ctx["project_slug"],
"__project_description__": self.ctx["project_description"],
}
if is_release():
metadata["__renku_version__"] = __version__

cli_version = os.environ.get("RENKU_PROJECT_DEFAULT_CLI_VERSION") or __version__
if is_release(cli_version):
metadata["__renku_version__"] = cli_version

return metadata

Expand Down
8 changes: 6 additions & 2 deletions renku/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""Version information for Renku."""

import re
from typing import Optional

try:
from importlib.metadata import distribution, version
Expand All @@ -27,9 +28,12 @@
__minimum_project_version__ = "2.4.0"


def is_release():
def is_release(version: Optional[str] = None):
"""Check if current version is a release semver."""
if re.match(r"\d+.\d+.\d+$", __version__):
if not version:
version = __version__

if re.match(r"\d+.\d+.\d+(rc\d+)?$", version):
return True
return False

Expand Down
28 changes: 28 additions & 0 deletions tests/service/controllers/test_templates_create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,31 @@ def test_except_project_name_handler(project_name, ctrl_init, svc_client_templat
TemplatesCreateProjectCtrl(cache, user_data, payload)

assert "Project name contains only unsupported characters" in str(exc_info.value)


def test_template_create_project_with_custom_cli_ctrl(
ctrl_init, svc_cache_dir, svc_client_templates_creation, mocker, monkeypatch
):
"""Test template create project controller."""
monkeypatch.setenv("RENKU_PROJECT_DEFAULT_CLI_VERSION", "9.9.9rc9")
from renku.ui.service.controllers.templates_create_project import TemplatesCreateProjectCtrl

cache, user_data = ctrl_init
_, _, payload, _ = svc_client_templates_creation

ctrl = TemplatesCreateProjectCtrl(cache, user_data, payload)
mocker.patch.object(ctrl, "new_project_push", return_value=None)
response = ctrl.to_response()

# Check response.
assert {"result"} == response.json.keys()
assert {"project_id", "url", "namespace", "name", "slug"} == response.json["result"].keys()

cache_dir, _ = svc_cache_dir

project_path = (
cache_dir / user_data["user_id"] / response.json["result"]["namespace"] / response.json["result"]["slug"]
)

with open(project_path / "Dockerfile") as f:
assert "ARG RENKU_VERSION=9.9.9rc9" in f.read()

0 comments on commit 9f16b0a

Please sign in to comment.