Skip to content
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

San 5253 no dockerfile error #1849

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion client/directives/components/buildLogs/buildLogsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ function BuildLogsController(
$rootScope,
$timeout,
errs,
keypather,
launchDebugContainer,
loading,
updateInstanceWithNewBuild,
primus,
promisify,
fetchRepoDockerfile,
streamingLog
) {
var BLC = this;
Expand All @@ -27,10 +29,19 @@ function BuildLogsController(
BLC.failReason = buildError.message || 'failed';
BLC.showDebug = true;
BLC.buildLogsRunning = false;
BLC.showNoDockerfileError = (BLC.instance.hasDockerfileMirroring() && BLC.instance.mirroredDockerfile === null);
if (status === 'neverStarted') {
BLC.showErrorPanel = true;
}
var repoAndBranchName = BLC.instance.getRepoAndBranchName().split('/');
var repoName = repoAndBranchName[0];
var branchName = repoAndBranchName[1];
var dockerfilePath = keypather.get(BLC, 'instance.mirroredDockerfile.attrs.path') + keypather.get(BLC, 'instance.mirroredDockerfile.attrs.name');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're 100% the path has a / a the end, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make a difference? I'm assuming there is nothing at the end, usually it is just repo/branch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... this code only works as expected because of this kirk: !!(null + null), right? Seems like we should be checking for these properties individually?

var dockerfilePath = keypather.get(BLC, 'instance.mirroredDockerfile.attrs.path');
var dockerfileName = keypather.get(BLC, 'instance.mirroredDockerfile.attrs.name');
if (dockerfilePath && dockerfileName) {
  fetchRepoDockerfile(repoName, branchName, dockerfilePath + dockerfileName) // ???
} 

if (!!dockerfilePath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the !!. We don't use this convention anywhere for if statements, since the result is exactly the same.

fetchRepoDockerfile(repoName, branchName, dockerfilePath)
.then(function (dockerfile) {
BLC.showNoDockerfileError = (BLC.instance.hasDockerfileMirroring() && dockerfile.message === 'Not Found');
});
}
} else if (status === 'building') {
BLC.buildStatus = 'running';
BLC.buildLogsRunning = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ describe('BuildLogsController'.bold.underline.blue, function () {
var BLC;
var mockCreateDebugContainer;
var mockDebugContainer;
var mockDockerfile;
var mockErrs;
var isRunnabotPartOfOrgStub;
var fetchRepoDockerfileStub;

function setup(useInstance, dontIncludeBuildDockerContainer) {
mockInstance = {
Expand All @@ -36,6 +38,13 @@ describe('BuildLogsController'.bold.underline.blue, function () {
dockerContainer: dontIncludeBuildDockerContainer ? undefined : 'asdsdfsd'
}
}
},
getRepoAndBranchName: sinon.stub().returns('test/master'),
mirroredDockerfile: {
attrs: {
path: '/',
name: 'Dockerfile'
}
}
};
mockDebugContainer = {
Expand All @@ -51,7 +60,7 @@ describe('BuildLogsController'.bold.underline.blue, function () {
logs: []
};
mockStreamingLog = sinon.stub().returns(mockStreamingLogContents);

mockDockerfile = {message: 'Not Found'};
mockPrimus = {
createBuildStream: sinon.spy(function () {
mockStream = new EventEmitter();
Expand All @@ -77,7 +86,10 @@ describe('BuildLogsController'.bold.underline.blue, function () {
mockCreateDebugContainer = sinon.stub().returns($q.when(mockDebugContainer));
return mockCreateDebugContainer;
});

$provide.factory('fetchRepoDockerfile', function ($q) {
fetchRepoDockerfileStub = sinon.stub().returns($q.when(mockDockerfile));
return fetchRepoDockerfileStub;
});
$provide.factory('isRunnabotPartOfOrg', function ($q) {
isRunnabotPartOfOrgStub = sinon.stub().returns($q.when());
return isRunnabotPartOfOrgStub;
Expand Down Expand Up @@ -188,6 +200,12 @@ describe('BuildLogsController'.bold.underline.blue, function () {
mockInstance.on.lastCall.args[1]();
expect(BLC.showDebug).to.be.ok;
});
it('should display a dockerfile error if absent', function () {
mockInstance.status.returns('buildFailed');
mockInstance.on.lastCall.args[1]();
$scope.$digest();
expect(BLC.showNoDockerfileError).to.equal(true);
})
});
describe('actions', function () {
describe('launchDebugContainer', function () {
Expand Down