From 67b648d6642c844bfd27e290359b51f3b7f2691f Mon Sep 17 00:00:00 2001 From: vfried Date: Wed, 14 Aug 2019 11:55:40 +0200 Subject: [PATCH] feat(templates): the user can configure a url and ref to get the templates from --- docker-entrypoint.sh | 6 ++- helm-chart/renku-ui/templates/deployment.yaml | 4 ++ helm-chart/renku-ui/values.yaml | 4 ++ run-telepresence.sh | 7 +++- src/App.js | 8 +++- src/api-client/project.js | 37 +++++++++---------- src/project/new/ProjectNew.container.js | 4 +- 7 files changed, 45 insertions(+), 25 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 21a24f2237..38c74b3141 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -21,6 +21,8 @@ echo " Configuration:" echo " GATEWAY_URL=${GATEWAY_URL:-http://gateway.renku.build}" echo " BASE_URL=${BASE_URL:-http://renku.build}" echo " RENKU_VERSION=${RENKU_VERSION}" +echo " RENKU_TEMPLATES_URL=${RENKU_TEMPLATES_URL}" +echo " RENKU_TEMPLATES_REF=${RENKU_TEMPLATES_REF}" echo "===================================================" tee > /usr/share/nginx/html/config.json << EOF @@ -28,7 +30,9 @@ tee > /usr/share/nginx/html/config.json << EOF "BASE_URL": "${BASE_URL:-http://renku.build}", "GATEWAY_URL": "${GATEWAY_URL:-http://gateway.renku.build}", "WELCOME_PAGE": "${WELCOME_PAGE}", - "RENKU_VERSION": "${RENKU_VERSION}" + "RENKU_VERSION": "${RENKU_VERSION}", + "RENKU_TEMPLATES_URL": "${RENKU_TEMPLATES_URL}", + "RENKU_TEMPLATES_REF": "${RENKU_TEMPLATES_REF}", } EOF diff --git a/helm-chart/renku-ui/templates/deployment.yaml b/helm-chart/renku-ui/templates/deployment.yaml index 6c39c7b141..35b060ad69 100644 --- a/helm-chart/renku-ui/templates/deployment.yaml +++ b/helm-chart/renku-ui/templates/deployment.yaml @@ -36,6 +36,10 @@ spec: value: {{ .Values.gatewayUrl | default (printf "%s://gateway.%s" (include "ui.protocol" .) .Values.global.renku.domain) | quote }} - name: WELCOME_PAGE value: {{ .Values.welcomePage.text | b64enc | quote }} + - name: RENKU_TEMPLATES_URL + value: {{ .Values.templatesRepository.url | b64enc | quote }} + - name: RENKU_TEMPLATES_REF + value: {{ .Values.templatesRepository.ref | b64enc | quote }} livenessProbe: httpGet: path: / diff --git a/helm-chart/renku-ui/values.yaml b/helm-chart/renku-ui/values.yaml index f8b4d462cd..d880fa0254 100644 --- a/helm-chart/renku-ui/values.yaml +++ b/helm-chart/renku-ui/values.yaml @@ -57,3 +57,7 @@ welcomePage: ## Welcome to Renku! Renku is software for collaborative data science. With Renku you can share code and data, discuss problems and solutions, and coordinate data-science projects. + +templatesRepository: + url: https://github.com/SwissDataScienceCenter/renku-project-template + ref: test-branch-manifests \ No newline at end of file diff --git a/run-telepresence.sh b/run-telepresence.sh index 544ff3230a..e36bd7eec8 100755 --- a/run-telepresence.sh +++ b/run-telepresence.sh @@ -57,12 +57,17 @@ else SERVICE_NAME=${DEV_NAMESPACE}-renku-ui fi +RENKU_TEMPLATES_URL=${RENKU_TEMPLATES_URL} +RENKU_TEMPLATES_REF=${RENKU_TEMPLATES_REF} + tee > ./public/config.json << EOF { "BASE_URL": "${BASE_URL}", "GATEWAY_URL": "${BASE_URL}/api", "WELCOME_PAGE": "${WELCOME_PAGE}", - "RENKU_VERSION": "latest" + "RENKU_VERSION": "latest", + "RENKU_TEMPLATES_URL": "${RENKU_TEMPLATES_URL}" + "RENKU_TEMPLATES_REF": "${RENKU_TEMPLATES_REF}" } EOF diff --git a/src/App.js b/src/App.js index cd8a168db4..77d276c7c6 100644 --- a/src/App.js +++ b/src/App.js @@ -94,8 +94,12 @@ class App extends Component { }/> - }/> + }/> path.startsWith('.renku/workflow/'), }; -const TemplatesReposUrl = { - TREES: 'https://api.github.com/repos/SwissDataScienceCenter/renku-project-template/git/trees/', - TREES_MASTER: 'https://api.github.com/repos/SwissDataScienceCenter/renku-project-template/git/trees/master', - BLOBS: 'https://api.github.com/repos/SwissDataScienceCenter/renku-project-template/git/blobs/' -} function groupedFiles(files, projectFiles) { projectFiles = (projectFiles != null) ? projectFiles : {}; @@ -120,7 +115,7 @@ function addProjectMethods(client) { client.getEmptyProjectObject = () => { return {folder:'empty-project-template', name:"Empty Project"} } - client.postProject = (renkuProject) => { + client.postProject = (renkuProject, renkuTemplatesUrl, renkuTemplatesRef) => { const gitlabProject = { name: renkuProject.display.title, description: renkuProject.display.description, @@ -170,13 +165,17 @@ function addProjectMethods(client) { // When the provided version does not exist, we log an error and uses latest. // Maybe this should raise a more prominent alarm? - const payloadPromise = getPayload(gitlabProject.name, client.renkuVersion, renkuProject.meta.template) - .catch(error => { - console.error(`Problem when retrieving project template ${client.renkuVersion}`); - console.error(error); - console.error('Trying again with \'latest\''); - return getPayload(gitlabProject.name, 'latest', renkuProject.meta.template) - }); + const payloadPromise = getPayload( + gitlabProject.name, + renkuTemplatesUrl, + renkuTemplatesRef, + renkuProject.meta.template + ).catch(error => { + console.error(`Problem when retrieving project template with url ${renkuTemplatesUrl} and ref ${renkuTemplatesRef}`); + console.error(error); + console.error('Trying again with '+renkuTemplatesRef); + return getPayload(gitlabProject.name, renkuTemplatesUrl, renkuTemplatesRef, renkuProject.meta.template) + }); let promises = [newProjectPromise, payloadPromise]; if (createGraphWebhookPromise) { @@ -387,10 +386,10 @@ function addProjectMethods(client) { }, 'json', false) } - client.getProjectTemplates = () => { - return fetchJson(TemplatesReposUrl.TREES_MASTER) + client.getProjectTemplates = (renkuTemplatesUrl, renkuTemplatesRef) => { + return fetchJson(`${renkuTemplatesUrl}/git/trees/${renkuTemplatesRef}`) .then(data => data.tree.filter(obj => obj.path === 'manifest.yaml')[0]['sha']) - .then(manifestSha => fetchJson(`${TemplatesReposUrl.BLOBS}${manifestSha}`)) + .then(manifestSha => fetchJson(`${renkuTemplatesUrl}/git/blobs/${manifestSha}`)) .then(data => {return yaml.load(atob(data.content))}) .then(data => {data.push(client.getEmptyProjectObject()); return data;}); } @@ -447,12 +446,12 @@ function carveProject(projectJson) { // make sense at some point to serve the project template from the GitLab // instance we're working with. -function getPayload(projectName, renkuVersion, projectTemplate) { +function getPayload(projectName, renkuTemplatesUrl, renkuTemplatesRef, projectTemplate) { // Promise which will resolve into the repository sub-tree // which matches the desired version of the renku project template. - const subTreePromise = fetchJson(TemplatesReposUrl.TREES_MASTER) + const subTreePromise = fetchJson(`${renkuTemplatesUrl}/git/trees/${renkuTemplatesRef}`) .then(data => data.tree.filter(obj => obj.path === projectTemplate)[0]['sha']) - .then(treeSha => fetchJson(`${TemplatesReposUrl.TREES}${treeSha}?recursive=1`)); + .then(treeSha => fetchJson(`${renkuTemplatesUrl}/git/trees/${treeSha}?recursive=1`)); // Promise which will resolve into a list of file creation actions // ready to be passed to the GitLab API. diff --git a/src/project/new/ProjectNew.container.js b/src/project/new/ProjectNew.container.js index a85c221f80..28f490a7bd 100644 --- a/src/project/new/ProjectNew.container.js +++ b/src/project/new/ProjectNew.container.js @@ -75,7 +75,7 @@ class New extends Component { } async fetchProjectTemplates(){ - return this.props.client.getProjectTemplates(); + return this.props.client.getProjectTemplates(this.props.renkuTemplatesUrl, this.props.renkuTemplatesRef); } async componentDidMount() { @@ -107,7 +107,7 @@ class New extends Component { const validation = this.validate(); if (validation.result) { this.newProject.set('display.loading', true); - this.props.client.postProject(this.newProject.get()) + this.props.client.postProject(this.newProject.get(), this.props.renkuTemplatesUrl, this.props.renkuTemplatesRef) .then((project) => { this.newProject.set('display.loading', false); this.props.history.push(`/projects/${project.id}`);