Skip to content

Commit

Permalink
CHE-4689: improve dockerfile parser (#4881)
Browse files Browse the repository at this point in the history
* CHE-4689: improve dockerfile parser

Signed-off-by: Oleksii Kurinnyi <okurinnyi@codenvy.com>

* fixup! CHE-4689: improve dockerfile parser
  • Loading branch information
Oleksii Kurinnyi committed Apr 24, 2017
1 parent 2b259a3 commit 8f83a91
Show file tree
Hide file tree
Showing 7 changed files with 717 additions and 150 deletions.
18 changes: 15 additions & 3 deletions dashboard/src/app/stacks/stack-details/stack-validation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Codenvy, S.A. - initial API and implementation
*/
'use strict';
import {DockerfileParser} from '../../../components/api/environment/docker-file-parser';


const COMPOSE = 'compose';
const DOCKERFILE = 'dockerfile';
Expand All @@ -21,6 +23,12 @@ const DOCKERIMAGE = 'dockerimage';
*/
export class StackValidationService {

dockerfileParser: DockerfileParser;

constructor() {
this.dockerfileParser = new DockerfileParser();
}

/**
* Return result of recipe validation.
* @param stack {che.IStack}
Expand Down Expand Up @@ -247,9 +255,13 @@ export class StackValidationService {
if (!recipe.content) {
isValid = false;
errors.push('Unknown recipe content.');
} else if (!/^FROM\s+\w+/m.test(recipe.content)) {
isValid = false;
errors.push('The dockerfile is invalid.');
} else {
try {
this.dockerfileParser.parse(recipe.content);
} catch (e) {
isValid = false;
errors.push(e.message);
}
}
}
if (!recipe.contentType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Codenvy, S.A. - initial API and implementation
*/
'use strict';
import {DockerfileParser} from '../../../../../components/api/environment/docker-file-parser';

/**
* @ngdoc controller
Expand All @@ -20,6 +21,9 @@
export class WorkspaceRecipeAuthoringController {
$timeout: ng.ITimeoutService;

dockerfileParser: DockerfileParser;
recipeValidationError: string;

editingTimeoutPromise: ng.IPromise<any>;

recipeFormat: string;
Expand All @@ -43,6 +47,8 @@ export class WorkspaceRecipeAuthoringController {
constructor($scope: ng.IScope, $timeout: ng.ITimeoutService) {
this.$timeout = $timeout;

this.dockerfileParser = new DockerfileParser();

this.editorOptions = {
lineWrapping: true,
lineNumbers: true,
Expand Down Expand Up @@ -81,6 +87,7 @@ export class WorkspaceRecipeAuthoringController {

this.editingTimeoutPromise = this.$timeout(() => {
this.detectFormat(content);
this.validateRecipe(content);
}, 100);
}

Expand All @@ -98,7 +105,16 @@ export class WorkspaceRecipeAuthoringController {
}
}

onRecipeChange() {
validateRecipe(content: string): void {
this.recipeValidationError = '';
try {
this.dockerfileParser.parse(content);
} catch (e) {
this.recipeValidationError = e.message;
}
}

onRecipeChange(): void {
this.$timeout(() => {
this.detectFormat(this.recipeScriptCopy);
this.recipeChange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<div ng-message="required">The recipe is required.</div>
</che-error-messages>
</che-input>
<div class="errors-container"
ng-if="workspaceRecipeAuthoringController.recipeValidationError">
{{workspaceRecipeAuthoringController.recipeValidationError}}
</div>
<div class="recipe-docs-link">
<a href="https://www.eclipse.org/che/docs/workspace/stacks/index.html#stack-administration" target="_blank">Custom stack documentation</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@

.che-label-container-row
align-items center

.errors-container
color $error-color
min-height 20px
margin-right 2px

span
margin-right 2px
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('If recipe has content', () => {
},
'recipe': {
'type': 'dockerfile',
'content': 'FROM codenvy/ubuntu_jdk8\nENV myName=\"John Doe\" myDog=Rex\\ The\\ Dog \\\n myCat=fluffy',
'content': 'FROM codenvy/ubuntu_jdk8\nENV myName="John Doe" myDog=Rex\\ The\\ Dog \\\n myCat=fluffy',
'contentType': 'text/x-dockerfile'
}
};
Expand Down
Loading

0 comments on commit 8f83a91

Please sign in to comment.