-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add workspace:create command instead of workspace:start #592
Changes from all commits
006e4df
38108b8
ad89388
e84bb9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2019-2020 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import { Command, flags } from '@oclif/command' | ||
import { boolean, string } from '@oclif/parser/lib/flags' | ||
import { cli } from 'cli-ux' | ||
import * as fs from 'fs' | ||
import * as Listr from 'listr' | ||
import * as notifier from 'node-notifier' | ||
|
||
import { CheHelper } from '../../api/che' | ||
import { accessToken, cheNamespace } from '../../common-flags' | ||
export default class Create extends Command { | ||
static description = 'Creates a workspace from a devfile' | ||
|
||
static flags = { | ||
help: flags.help({ char: 'h' }), | ||
chenamespace: cheNamespace, | ||
devfile: string({ | ||
char: 'f', | ||
description: 'path or URL to a valid devfile', | ||
env: 'DEVFILE_PATH', | ||
required: false, | ||
}), | ||
name: string({ | ||
description: 'workspace name: overrides the workspace name to use instead of the one defined in the devfile.', | ||
required: false, | ||
}), | ||
start: boolean({ | ||
char: 's', | ||
description: 'Starts the workspace after creation', | ||
default: false | ||
}), | ||
'access-token': accessToken | ||
} | ||
|
||
async run() { | ||
const { flags } = this.parse(Create) | ||
|
||
const tasks = this.getWorkspaceCreateTasks(flags) | ||
try { | ||
let ctx = await tasks.run() | ||
this.log('\nWorkspace IDE URL:') | ||
cli.url(ctx.workspaceIdeURL, ctx.workspaceIdeURL) | ||
} catch (err) { | ||
this.error(err) | ||
} | ||
|
||
notifier.notify({ | ||
title: 'chectl', | ||
message: 'Command workspace:create has completed successfully.' | ||
}) | ||
|
||
this.exit(0) | ||
} | ||
|
||
getWorkspaceCreateTasks(flags: any): Listr<any> { | ||
const che = new CheHelper(flags) | ||
return new Listr([ | ||
{ | ||
title: 'Retrieving Eclipse Che server URL', | ||
task: async (ctx: any, task: any) => { | ||
ctx.cheURL = await che.cheURL(flags.chenamespace) | ||
task.title = await `${task.title}... ${ctx.cheURL}` | ||
} | ||
}, | ||
{ | ||
title: 'Verify if Eclipse Che server is running', | ||
task: async (ctx: any, task: any) => { | ||
if (!await che.isCheServerReady(ctx.cheURL)) { | ||
this.error(`E_SRV_NOT_RUNNING - Eclipse Che server is not available by ${ctx.cheURL}`, { code: 'E_SRV_NOT_RUNNNG' }) | ||
} | ||
const status = await che.getCheServerStatus(ctx.cheURL) | ||
ctx.isAuthEnabled = await che.isAuthenticationEnabled(ctx.cheURL) | ||
const auth = ctx.isAuthEnabled ? '(auth enabled)' : '(auth disabled)' | ||
task.title = await `${task.title}...${status} ${auth}` | ||
} | ||
}, | ||
{ | ||
title: `Create workspace from Devfile ${flags.devfile}`, | ||
task: async (ctx: any) => { | ||
if (ctx.isAuthEnabled && !flags['access-token']) { | ||
this.error('E_AUTH_REQUIRED - Eclipse Che authentication is enabled and an access token needs to be provided (flag --access-token).') | ||
} | ||
|
||
let devfilePath: string | ||
if (flags.devfile) { | ||
devfilePath = flags.devfile | ||
} else if (fs.existsSync('devfile.yaml')) { | ||
devfilePath = 'devfile.yaml' | ||
} else if (fs.existsSync('devfile.yml')) { | ||
mmorhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
devfilePath = 'devfile.yml' | ||
} else { | ||
throw new Error("E_DEVFILE_MISSING - Devfile wasn't specified via '-f' option and \'devfile.yaml' is not present in current directory.") | ||
} | ||
|
||
const workspaceConfig = await che.createWorkspaceFromDevfile(flags.chenamespace, devfilePath, flags.name, flags['access-token']) | ||
ctx.workspaceId = workspaceConfig.id | ||
if (workspaceConfig.links && workspaceConfig.links.ide) { | ||
ctx.workspaceIdeURL = await che.buildDashboardURL(workspaceConfig.links.ide) | ||
} | ||
} | ||
}, { | ||
title: 'Start workspace', | ||
enabled: () => flags.start, | ||
task: async (ctx: any, task: any) => { | ||
await che.startWorkspace(flags.chenamespace, ctx.workspaceId, flags['access-token']) | ||
task.title = `${task.title}... Done` | ||
} | ||
} | ||
], { renderer: 'silent' }) | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,10 @@ | |
exec-sh "^0.3.2" | ||
minimist "^1.2.0" | ||
|
||
"@eclipse-che/api@latest": | ||
version "7.5.0-SNAPSHOT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks strange There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. It is really latest version... https://www.npmjs.com/package/@eclipse-che/api There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing strange. I just used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @mmorhun wants to use dts types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry @AndrienkoAleksandr but I have no idea who is responsible now for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should a part of release process. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use outdated version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there were some major changes. But we need to raise this question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've create issue for this problem: eclipse-che/che#16436 |
||
resolved "https://registry.yarnpkg.com/@eclipse-che/api/-/api-7.5.0-SNAPSHOT.tgz#bf0c5be60354e34c73bc52b2e18be8680ce8d900" | ||
|
||
"@fimbul/bifrost@^0.21.0": | ||
version "0.21.0" | ||
resolved "https://registry.yarnpkg.com/@fimbul/bifrost/-/bifrost-0.21.0.tgz#d0fafa25938fda475657a6a1e407a21bbe02c74e" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCheApiError
function actually catches 404 error (rebase on master pls)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to handle 404 error in another way for this specific request.