Skip to content

Commit

Permalink
feat(templates): the user can configure a url and ref to get the temp…
Browse files Browse the repository at this point in the history
…lates from
  • Loading branch information
vfried committed Aug 14, 2019
1 parent 5af6e71 commit 67b648d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 25 deletions.
6 changes: 5 additions & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ 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
{
"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

Expand Down
4 changes: 4 additions & 0 deletions helm-chart/renku-ui/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: /
Expand Down
4 changes: 4 additions & 0 deletions helm-chart/renku-ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion run-telepresence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ class App extends Component {
}/>
<Route exact path="/project_new"
render={(p) =>
<Project.New key="project_new" client={this.props.client}
user={this.props.userState.getState().user} {...p}/> }/>
<Project.New key="project_new"
client={this.props.client}
user={this.props.userState.getState().user}
renkuTemplatesUrl={this.props.params['RENKU_TEMPLATES_URL']}
renkuTemplatesRef={this.props.params['RENKU_TEMPLATES_REF']}
{...p}/> }/>
<Route exact path="/notebooks"
render={p => <Notebooks key="notebooks" standalone={true}
user={this.props.userState.getState().user}
Expand Down
37 changes: 18 additions & 19 deletions src/api-client/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const FileCategories = {
workflows: (path) => 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 : {};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;});
}
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/project/new/ProjectNew.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 67b648d

Please sign in to comment.