Skip to content

Commit f491914

Browse files
committed
Merge branch 'master' into gulp-build
2 parents 46b30f5 + 5fb046b commit f491914

File tree

7 files changed

+288
-1
lines changed

7 files changed

+288
-1
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ Kubernetes Console is a general purpose, web-based UI for Kubernetes clusters. I
33

44
The console is currently under active development and is not ready for production use (yet!).
55

6+
# Contribute:
7+
8+
Wish to contribute !! Great start [here](https://github.com/kubernetes/console/blob/master/CONTRIBUTING.md).
9+
10+
# License:
11+
12+
The work done has been licensed under Apache License 2.0.The license file can be found [here](https://github.com/kubernetes/console/blob/master/LICENSE). You can find out more about license,at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0

build/backend.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2015 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* Gulp tasks for compiling backend application.
17+
*/
18+
import child from 'child_process';
19+
import del from 'del';
20+
import gulp from 'gulp';
21+
import lodash from 'lodash';
22+
import path from 'path';
23+
24+
import conf from './conf';
25+
26+
27+
/**
28+
* External dependencies of the Go backend application.
29+
*
30+
* @type {!Array<string>}
31+
*/
32+
const goBackendDependencies = [
33+
'github.com/golang/glog',
34+
'github.com/spf13/pflag'
35+
];
36+
37+
38+
/**
39+
* Spawns Go process with GOPATH placed in the backend tmp folder.
40+
*
41+
* @param {!Array<string>} args
42+
* @param {function(?Error=)} doneFn
43+
* @param {!Object<string, string>=} opt_env Optional environment variables to be concatenated with
44+
* default ones.
45+
*/
46+
function spawnGoProcess(args, doneFn, opt_env) {
47+
var goTask = child.spawn('go', args, {
48+
env: lodash.merge(process.env, {GOPATH: conf.paths.backendTmp}, opt_env || {})
49+
});
50+
51+
// Call Gulp callback on task exit. This has to be done to make Gulp dependency management
52+
// work.
53+
goTask.on('exit', function(code) {
54+
if (code === 0) {
55+
doneFn();
56+
} else {
57+
doneFn(new Error('Go command error, code:' + code));
58+
}
59+
});
60+
61+
goTask.stdout.on('data', function (data) {
62+
console.log('' + data);
63+
});
64+
65+
goTask.stderr.on('data', function (data) {
66+
console.error('' + data);
67+
});
68+
}
69+
70+
71+
/**
72+
* Compiles backend application in development mode and places 'console' binary in the serve
73+
* directory.
74+
*/
75+
gulp.task('backend', ['backend-dependencies'], function(doneFn) {
76+
spawnGoProcess([
77+
'build',
78+
'-o', path.join(conf.paths.serve, 'console'),
79+
path.join(conf.paths.backendSrc, 'console.go')
80+
], doneFn);
81+
});
82+
83+
84+
/**
85+
* Compiles backend application in production mode and places 'console' binary in the dist
86+
* directory.
87+
*
88+
* The production binary difference from development binary is only that it contains all
89+
* dependencies inside it and is targeted for Linux.
90+
*/
91+
gulp.task('backend:prod', ['backend-dependencies'], function(doneFn) {
92+
let outputBinaryPath = path.join(conf.paths.dist, 'console');
93+
// Delete output binary first. This is required because prod build does not override it.
94+
del(outputBinaryPath)
95+
.then(function() {
96+
spawnGoProcess([
97+
'build',
98+
'-a',
99+
'-installsuffix', 'cgo',
100+
'-o', outputBinaryPath,
101+
path.join(conf.paths.backendSrc, 'console.go')
102+
], doneFn, {
103+
// Disable cgo package. Required to run on scratch docker image.
104+
CGO_ENABLED: '0',
105+
// Scratch docker image is linux.
106+
GOOS: 'linux'
107+
});
108+
}, function(error) {
109+
doneFn(error);
110+
});
111+
});
112+
113+
114+
/**
115+
* Gets backend dependencies and places them in the backend tmp directory.
116+
*
117+
* TODO(bryk): Investigate switching to Godep: https://github.com/tools/godep
118+
*/
119+
gulp.task('backend-dependencies', [], function(doneFn) {
120+
let args = ['get'].concat(goBackendDependencies);
121+
spawnGoProcess(args, doneFn);
122+
});

build/conf.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,32 @@ export default {
3535
app: path.join(basePath, 'src/app'),
3636
assets: path.join(basePath, 'src/app/assets'),
3737
base: basePath,
38+
backendSrc: path.join(basePath, 'src/app/backend'),
39+
backendTmp: path.join(basePath, '.tmp/backend'),
3840
bowerComponents: path.join(basePath, 'bower_components'),
3941
build: path.join(basePath, 'build'),
4042
dist: path.join(basePath, 'dist'),
43+
externs: path.join(basePath, 'src/app/externs'),
4144
frontendSrc: path.join(basePath, 'src/app/frontend'),
4245
frontendTest: path.join(basePath, 'src/test/frontend'),
4346
integrationTest: path.join(basePath, 'src/test/integration'),
4447
karmaConf: path.join(basePath, 'build/karma.conf.js'),
48+
nodeModules: path.join(basePath, 'node_modules'),
4549
partials: path.join(basePath, '.tmp/partials'),
50+
prodTmp: path.join(basePath, '.tmp/prod'),
4651
protractorConf: path.join(basePath, 'build/protractor.conf.js'),
4752
serve: path.join(basePath, '.tmp/serve'),
4853
src: path.join(basePath, 'src'),
4954
tmp: path.join(basePath, '.tmp')
55+
},
56+
57+
/**
58+
* Frontend application constants.
59+
*/
60+
frontend: {
61+
/**
62+
* The name of the root Angular module, i.e., the module that bootstraps the application.
63+
*/
64+
rootModuleName: 'kubernetesConsole'
5065
}
5166
};

build/protractor.conf.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2015 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @fileoverview Configuration file for Protractor test runner.
17+
*
18+
* TODO(bryk): Start using ES6 in this file when supported.
19+
*/
20+
require('babel-core/register');
21+
var conf = require('./conf');
22+
var path = require('path');
23+
24+
25+
/**
26+
* Exported protractor config required by the framework.
27+
*
28+
* Schema can be found here: https://github.com/angular/protractor/blob/master/docs/referenceConf.js
29+
*/
30+
exports.config = {
31+
capabilities: {
32+
'browserName': 'chrome'
33+
},
34+
35+
baseUrl: 'http://localhost:3000',
36+
37+
specs: [path.join(conf.paths.integrationTest, '**/*.js')]
38+
};

build/style.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2015 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @fileoverview Gulp tasks for processing stylesheets.
17+
*/
18+
import browserSync from 'browser-sync';
19+
import gulp from 'gulp';
20+
import gulpAutoprefixer from 'gulp-autoprefixer';
21+
import gulpFilter from 'gulp-filter';
22+
import gulpMinifyCss from 'gulp-minify-css';
23+
import gulpSourcemaps from 'gulp-sourcemaps';
24+
import gulpSass from 'gulp-sass';
25+
import path from 'path';
26+
import gulpConcat from 'gulp-concat';
27+
28+
import conf from './conf';
29+
30+
31+
/**
32+
* Compiles stylesheets and places them into the serve folder. Each stylesheet file is compiled
33+
* separately.
34+
*/
35+
gulp.task('styles', function () {
36+
let sassOptions = {
37+
style: 'expanded'
38+
};
39+
40+
let cssFilter = gulpFilter('**/*.css', { restore: true });
41+
42+
return gulp.src(path.join(conf.paths.frontendSrc, '**/*.scss'))
43+
.pipe(gulpSass(sassOptions))
44+
.pipe(cssFilter)
45+
.pipe(gulpSourcemaps.init({ loadMaps: true }))
46+
.pipe(gulpAutoprefixer())
47+
.pipe(gulpSourcemaps.write())
48+
.pipe(cssFilter.restore)
49+
.pipe(gulp.dest(conf.paths.serve))
50+
// If BrowserSync is running, inform it that styles have changed.
51+
.pipe(browserSync.stream());
52+
});
53+
54+
55+
/**
56+
* Compiles stylesheets and places them into the prod tmp folder. Styles are compiled and minified
57+
* into a single file.
58+
*/
59+
gulp.task('styles:prod', function () {
60+
let sassOptions = {
61+
style: 'compressed'
62+
};
63+
64+
return gulp.src(path.join(conf.paths.frontendSrc, '**/*.scss'))
65+
.pipe(gulpSass(sassOptions))
66+
.pipe(gulpAutoprefixer())
67+
.pipe(gulpConcat('app.css'))
68+
.pipe(gulpMinifyCss())
69+
.pipe(gulp.dest(conf.paths.prodTmp))
70+
});

gulpfile.babel.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @fileoverview Root configuration file of the Gulp build system. It loads child modules which
17+
* define specific Gulp tasks.
18+
*
19+
* Learn more at: http://gulpjs.com
20+
*/
21+
import './build/backend';
22+
import './build/build';
23+
import './build/index';
24+
import './build/script';
25+
import './build/serve';
26+
import './build/style';
27+
import './build/test';
28+
29+
30+
// No business logic in this file.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"gulp-autoprefixer": "~3.0.1",
2121
"gulp-browserify": "~0.5.1",
2222
"gulp-closure-compiler": "~0.3.1",
23+
"gulp-concat": "~2.6.0",
2324
"gulp-eslint": "~1.0.0",
2425
"gulp-filter": "~3.0.1",
2526
"gulp-flatten": "~0.2.0",
@@ -35,17 +36,19 @@
3536
"gulp-sass": "~0.7.1",
3637
"gulp-size": "~2.0.0",
3738
"gulp-sourcemaps": "~1.5.2",
39+
"gulp-uglify": "~1.3.0",
3840
"gulp-useref": "~1.3.0",
3941
"gulp-util": "~3.0.6",
4042
"gulp-watch": "~4.3.5",
4143
"karma": "~0.13.9",
42-
"karma-babel-preprocessor": "~5.2.2",
4344
"karma-browserify": "~4.4.0",
4445
"karma-chrome-launcher": "~0.2.0",
4546
"karma-coverage": "~0.5.2",
4647
"karma-jasmine": "~0.3.6",
4748
"karma-ng-html2js-preprocessor": "~0.1.2",
4849
"karma-sourcemap-loader": "~0.3.6",
50+
"lodash": "~3.10.1",
51+
"uglify-save-license": "~0.4.1",
4952
"wiredep": "~2.2.2",
5053
"wrench": "~1.5.8"
5154
},

0 commit comments

Comments
 (0)