feat(build runner): added in context, dockerfile_location

this is a new feature meant to allow people to use any file as
  a dockerfile and any folder as a context directory
This commit is contained in:
Charlton Austin 2017-03-21 17:24:11 -04:00
parent 90b130fe16
commit e6d201e0b0
29 changed files with 531 additions and 111 deletions

View file

@ -0,0 +1,33 @@
<div class="context-path-select-element">
<div class="dropdown-select" placeholder="'Enter a docker context'"
selected-item="$ctrl.selectedContext"
lookahead-items="$ctrl.contexts"
handle-input="$ctrl.setContext(input)"
handle-item-selected="$ctrl.setSelectedContext(datum.value)"
allow-custom-input="true"
hide-dropdown="$ctrl.contexts.length <= 0">
<!-- Icons -->
<i class="dropdown-select-icon none-icon fa fa-folder-o fa-lg"
ng-show="$ctrl.isUnknownContext"></i>
<i class="dropdown-select-icon none-icon fa fa-folder fa-lg" style="color: black;"
ng-show="!$ctrl.isUnknownContext"></i>
<i class="dropdown-select-icon fa fa-folder fa-lg"></i>
<!-- Dropdown menu -->
<ul class="dropdown-select-menu pull-right" role="menu">
<li ng-repeat="context in $ctrl.contexts">
<a ng-click="$ctrl.setSelectedContext(context)"
ng-if="context">
<i class="fa fa-folder fa-lg"></i> {{ context }}
</a>
</li>
</ul>
</div>
<div style="padding: 10px">
<div class="co-alert co-alert-danger"
ng-show="!$ctrl.isValidContext && $ctrl.currentContext">
Path is an invalid context.
</div>
</div>
</div>

View file

@ -0,0 +1,87 @@
import { ContextPathSelectComponent } from './context-path-select.component';
describe("ContextPathSelectComponent", () => {
var component: ContextPathSelectComponent;
var currentContext: string;
var isValidContext: boolean;
var contexts: string[];
beforeEach(() => {
component = new ContextPathSelectComponent();
currentContext = '/';
isValidContext = false;
contexts = ['/'];
component.currentContext = currentContext;
component.isValidContext = isValidContext;
component.contexts = contexts;
});
describe("$onChanges", () => {
it("sets valid context flag to true if current context is valid", () => {
component.$onChanges({});
expect(component.isValidContext).toBe(true);
});
it("sets valid context flag to false if current context is invalid", () => {
component.currentContext = "asdfdsf";
component.$onChanges({});
expect(component.isValidContext).toBe(false);
});
});
describe("setcontext", () => {
var newContext: string;
beforeEach(() => {
newContext = '/conf';
});
it("sets current context to given context", () => {
component.setContext(newContext);
expect(component.currentContext).toEqual(newContext);
});
it("sets valid context flag to true if given context is valid", () => {
component.setContext(newContext);
expect(component.isValidContext).toBe(true);
});
it("sets valid context flag to false if given context is invalid", () => {
component.setContext("asdfsadfs");
expect(component.isValidContext).toBe(false);
});
});
describe("setCurrentcontext", () => {
var context: string;
beforeEach(() => {
context = '/conf';
});
it("sets current context to given context", () => {
component.setSelectedContext(context);
expect(component.currentContext).toEqual(context);
});
it("sets valid context flag to true if given context is valid", () => {
component.setSelectedContext(context);
expect(component.isValidContext).toBe(true);
});
it("sets valid context flag to false if given context is invalid", () => {
component.setSelectedContext("a;lskjdf;ldsa");
expect(component.isValidContext).toBe(false);
});
});
});

View file

@ -0,0 +1,46 @@
import { Input, Component } from 'angular-ts-decorators';
/**
* A component that allows the user to select the location of the Context in their source code repository.
*/
@Component({
selector: 'contextPathSelect',
templateUrl: '/static/js/directives/ui/context-path-select/context-path-select.component.html'
})
export class ContextPathSelectComponent implements ng.IComponentController {
// FIXME: Use one-way data binding
@Input('=') public currentContext: string;
@Input('=') public isValidContext: boolean;
@Input('=') public contexts: string[];
private isUnknownContext: boolean = true;
private selectedContext: string | null = null;
public $onChanges(changes: ng.IOnChangesObject): void {
this.isValidContext = this.checkContext(this.currentContext, this.contexts);
}
public setContext(context: string): void {
this.currentContext = context;
this.selectedContext = null;
this.isValidContext = this.checkContext(context, this.contexts);
}
public setSelectedContext(context: string): void {
this.currentContext = context;
this.selectedContext = context;
this.isValidContext = this.checkContext(context, this.contexts);
}
private checkContext(context: string = '', contexts: string[] = []): boolean {
this.isUnknownContext = false;
var isValidContext: boolean = false;
if (context.length > 0 && context[0] === '/') {
isValidContext = true;
this.isUnknownContext = true;
}
return isValidContext;
}
}

View file

@ -257,9 +257,10 @@
<dockerfile-path-select
current-path="$ctrl.local.dockerfilePath"
paths="$ctrl.local.dockerfileLocations.subdir"
paths="$ctrl.local.dockerfileLocations.dockerfile_paths"
supports-full-listing="true"
is-valid-path="$ctrl.local.hasValidDockerfilePath"></dockerfile-path-select>
is-valid-path="$ctrl.local.hasValidDockerfilePath">
</dockerfile-path-select>
</div>
<div class="col-lg-8 col-md-8 col-sm-12 main-col"
@ -268,10 +269,44 @@
</div>
<div class="col-lg-4 col-md-4 hidden-sm hidden-xs help-col">
<p>Please select the location containing the Dockerfile to be built.</p>
<p>The build context will start at the location selected.</p>
</div>
</linear-workflow-section><!-- /Section: Dockerfile Location -->
<!-- Section: Context Location -->
<linear-workflow-section class="row"
section-id="contextlocation"
section-title="Select Docker Context"
section-valid="$ctrl.local.hasValidContextLocation">
<div class="col-lg-7 col-md-7 col-sm-12 main-col"
ng-if="$ctrl.local.dockerfileLocations.status == 'error'">
<div class="co-alert co-alert-warning">
{{ $ctrl.local.dockerfileLocations.message }}
</div>
</div>
<div class="col-lg-7 col-md-7 col-sm-12 main-col" ng-if="$ctrl.local.dockerfileLocations.status == 'success'">
<h3>Select Context</h3>
<strong>
Please select the context for the docker build
</strong>
<context-path-select
current-context="$ctrl.local.dockerContext"
current-path="$ctrl.local.dockerfilePath"
contexts="$ctrl.local.contexts"
is-valid-context="$ctrl.local.hasValidContextLocation">
</context-path-select>
</div>
<div class="col-lg-8 col-md-8 col-sm-12 main-col"
ng-if="!$ctrl.local.dockerfileLocations">
<span class="cor-loader-inline"></span> Retrieving Dockerfile locations
</div>
<div class="col-lg-4 col-md-4 hidden-sm hidden-xs help-col">
<p>Please select a docker context.</p>
</div>
</linear-workflow-section><!-- /Section: Context Location -->
<!-- Section: Robot Account -->
<linear-workflow-section class="row"
section-id="verification"

View file

@ -80,7 +80,14 @@ export class ManageTriggerGithostComponent implements ng.IComponentController {
this.$scope.$watch(() => this.local.dockerfilePath, (path) => {
if (path && this.local.selectedRepository) {
this.checkDockerfilePath(this.local.selectedRepository, path);
this.setPossibleContexts(path);
this.checkDockerfilePath(this.local.selectedRepository, path, this.local.dockerContext);
}
});
this.$scope.$watch(() => this.local.dockerContext, (context) => {
if (context && this.local.selectedRepository) {
this.checkDockerfilePath(this.local.selectedRepository, this.local.dockerfilePath, context);
}
});
@ -117,7 +124,8 @@ export class ManageTriggerGithostComponent implements ng.IComponentController {
public createTrigger(): void {
var config: any = {
build_source: this.local.selectedRepository.full_name,
subdir: this.local.dockerfilePath.substr(1) // Remove starting /
dockerfile_path: this.local.dockerfilePath,
context: this.local.dockerContext
};
if (this.local.triggerOptions.hasBranchTagFilter &&
@ -271,6 +279,7 @@ export class ManageTriggerGithostComponent implements ng.IComponentController {
private loadDockerfileLocations(repository: any): void {
this.local.dockerfilePath = null;
this.local.dockerContext = null;
var params = {
'repository': this.repository.namespace + '/' + this.repository.name,
@ -301,7 +310,7 @@ export class ManageTriggerGithostComponent implements ng.IComponentController {
[]);
}
private checkDockerfilePath(repository: any, path: string): void {
private checkDockerfilePath(repository: any, path: string, context: string): void {
this.local.triggerAnalysis = null;
this.local.robotAccount = null;
@ -312,7 +321,8 @@ export class ManageTriggerGithostComponent implements ng.IComponentController {
var config = {
'build_source': repository.full_name,
'subdir': path.substr(1)
'dockerfile_path': path.substr(1),
'context': context
};
var data = {
@ -325,6 +335,12 @@ export class ManageTriggerGithostComponent implements ng.IComponentController {
this.buildOrderedRobotAccounts();
}, this.ApiService.errorDisplay('Could not analyze trigger'));
}
private setPossibleContexts(path){
if(this.local.dockerfileLocations.contextMap){
this.local.contexts = this.local.dockerfileLocations.contextMap[path] || [];
}
}
}

View file

@ -7,6 +7,7 @@ import { RegexMatchViewComponent } from "./directives/ui/regex-match-view/regex-
import { NgModule } from "angular-ts-decorators";
import { QuayRoutes } from "./quay-routes.module";
import { DockerfilePathSelectComponent } from './directives/ui/dockerfile-path-select/dockerfile-path-select.component';
import { ContextPathSelectComponent } from './directives/ui/context-path-select/context-path-select.component';
import { ManageTriggerCustomGitComponent } from './directives/ui/manage-trigger-custom-git/manage-trigger-custom-git.component';
import { ManageTriggerGithostComponent } from './directives/ui/manage-trigger-githost/manage-trigger-githost.component';
import { LinearWorkflowComponent } from './directives/ui/linear-workflow/linear-workflow.component';
@ -31,6 +32,7 @@ import { DataFileServiceImpl } from './services/datafile/datafile.service.impl';
declarations: [
RegexMatchViewComponent,
DockerfilePathSelectComponent,
ContextPathSelectComponent,
ManageTriggerCustomGitComponent,
ManageTriggerGithostComponent,
LinearWorkflowComponent,