Skip to content

Commit 9850c13

Browse files
committed
Merge pull request #26 from kubernetes/gulp-deploy
Gulp tasks for creating Docker deployment images
2 parents c1f748f + 218f0f8 commit 9850c13

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

build/backend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const goBackendDependencies = [
4444
* default ones.
4545
*/
4646
function spawnGoProcess(args, doneFn, opt_env) {
47-
var goTask = child.spawn('go', args, {
47+
let goTask = child.spawn('go', args, {
4848
env: lodash.merge(process.env, {GOPATH: conf.paths.backendTmp}, opt_env || {}),
4949
});
5050

build/conf.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ const basePath = path.join(__dirname, '../');
2828
* Exported configuration object with common constants used in build pipeline.
2929
*/
3030
export default {
31+
/**
32+
* Deployment constants configuration.
33+
*/
34+
deploy: {
35+
/**
36+
* The name of the Docker image with the application.
37+
*/
38+
imageName: 'kubernetes/console',
39+
},
40+
3141
/**
3242
* Frontend application constants.
3343
*/

build/deploy.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 deploying and releasing the application.
17+
*/
18+
import child from 'child_process';
19+
import gulp from 'gulp';
20+
import path from 'path';
21+
22+
import conf from './conf';
23+
24+
25+
/**
26+
* @param {!Array<string>} args
27+
* @param {function(?Error=)} doneFn
28+
*/
29+
function spawnDockerProcess(args, doneFn) {
30+
let dockerTask = child.spawn('docker', args);
31+
32+
// Call Gulp callback on task exit. This has to be done to make Gulp dependency management
33+
// work.
34+
dockerTask.on('exit', function(code) {
35+
if (code === 0) {
36+
doneFn();
37+
} else {
38+
doneFn(new Error('Docker command error, code:' + code));
39+
}
40+
});
41+
42+
dockerTask.stdout.on('data', function (data) {
43+
console.log('' + data);
44+
});
45+
46+
dockerTask.stderr.on('data', function (data) {
47+
console.error('' + data);
48+
});
49+
}
50+
51+
52+
/**
53+
* Creates Docker image for the application. The image is tagged with the image name configuration
54+
* constant.
55+
*
56+
* In order to run the image on a Kubernates cluster, it has to be deployed to a registry.
57+
*/
58+
gulp.task('docker-image', ['docker-file'], function(doneFn) {
59+
spawnDockerProcess([
60+
'build',
61+
// Remove intermediate containers after a successful build.
62+
'--rm=true',
63+
'--tag', conf.deploy.imageName,
64+
conf.paths.dist,
65+
], doneFn);
66+
});
67+
68+
69+
/**
70+
* Processes the Docker file and places it in the dist folder for building.
71+
*/
72+
gulp.task('docker-file', function() {
73+
return gulp.src(path.join(conf.paths.deploySrc, 'Dockerfile'))
74+
.pipe(gulp.dest(conf.paths.dist));
75+
});

gulpfile.babel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
import './build/backend';
2222
import './build/build';
23+
import './build/deploy';
2324
import './build/index';
2425
import './build/script';
2526
import './build/serve';

0 commit comments

Comments
 (0)