Skip to content

Commit a34141d

Browse files
committed
Update Docker build to use streamlined dist build.
1 parent 61fface commit a34141d

10 files changed

+115
-119
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ tmp
3434

3535
options.sh
3636

37-
public/
37+
dist/

Dockerfile

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
FROM node:8.12
1+
FROM node:8.16
22

33
WORKDIR /app
44

5-
ENV NODE_ENV=production
5+
COPY dist .
66

7-
ADD ./package.json .
8-
9-
ADD ./yarn.lock .
10-
11-
ADD ./docker-entry.sh .
12-
13-
RUN yarn install
14-
15-
ADD ./public/*.* ./public/
16-
17-
ADD ./server/*.js ./server/
7+
RUN yarn --production install
188

199
RUN groupadd -g 1097 mousebrainmicro
2010
RUN adduser -u 7700649 --disabled-password --gecos '' mluser

docker-entry.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ chown mluser:mousebrainmicro ${logPath}
1818

1919
export DEBUG=pipeline*
2020

21-
node server/pipelineClientServer.js >> ${logPath} 2>&1
21+
node pipelineClientServer.js >> ${logPath} 2>&1

gulpfile.ts

+65-44
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,21 @@ import * as fs from "fs";
22
import * as gulp from "gulp";
33
import * as shell from "gulp-shell";
44

5-
const contents = fs.readFileSync("./package.json").toString();
6-
7-
const npmPackage = JSON.parse(contents);
8-
9-
const version = npmPackage.version;
10-
const [versionMajor, versionMajMin] = versionMajorMinor(version);
11-
const repo = npmPackage.dockerRepository;
12-
const imageName = npmPackage.dockerImageName || npmPackage.name;
13-
14-
const dockerRepoImage = `${repo}/${imageName}`;
15-
165
///
17-
// The objective here is to build and tag the actual version, mark it as latest, and also tag it with just the major
18-
// version and major.minor as the "latest" within those scopes. Iterations of deploy-services should generally use
19-
// major.minor in the Compose file rather that just latest. This facilitates side-by-side deployments of current and
20-
// next version systems where pulling "latest" doesn't affect the older system on subsequent up commands.
6+
// Build and tag the actual version, mark as latest, and also tag it with just the major and minor versions.
217
///
8+
const [buildTask, tagTask, pushTask] = createShellTasks("./package.json");
229

23-
const imageWithVersion = `${dockerRepoImage}:${version}`;
24-
const imageWithVersionMajor = versionMajor ? `${dockerRepoImage}:${versionMajor}` : null;
25-
const imageWithVersionMajMin = versionMajMin ? `${dockerRepoImage}:${versionMajMin}` : null;
26-
const imageAsLatest = `${dockerRepoImage}:latest`;
10+
gulp.task("default", ["docker-build"]);
2711

28-
const buildCommand = `docker build --tag ${imageWithVersion} .`;
29-
const tagMajorCommand = imageWithVersionMajor ? `docker tag ${imageWithVersion} ${imageWithVersionMajor}` : `echo "could not tag with major version"`;
30-
const tagMajMinCommand = imageWithVersionMajMin ? `docker tag ${imageWithVersion} ${imageWithVersionMajMin}` : `echo "could not tag with major.minor version"`;
31-
const tagLatestCommand = `docker tag ${imageWithVersion} ${imageAsLatest}`;
12+
gulp.task("build", buildTask);
3213

33-
const pushCommand = `docker push ${imageWithVersion}`;
34-
const pushMajorCommand = imageWithVersionMajor ? `docker push ${imageWithVersionMajor}` : `echo "could not push major version"`;
35-
const pushMajMinCommand = imageWithVersionMajMin ? `docker push ${imageWithVersionMajMin}` : `echo "could not push major.minor version"`;
36-
const pushLatestCommand = `docker push ${imageAsLatest}`;
14+
gulp.task("docker-build", ["build"], tagTask);
3715

38-
gulp.task("default", ["docker-build"]);
16+
gulp.task("docker-push", ["docker-build"], pushTask);
3917

4018
gulp.task("release", ["docker-push"]);
4119

42-
gulp.task("docker-build", shell.task([
43-
buildCommand,
44-
tagMajorCommand,
45-
tagMajMinCommand,
46-
tagLatestCommand
47-
])
48-
);
49-
50-
gulp.task("docker-push", ["docker-build"], shell.task([
51-
pushCommand,
52-
pushMajorCommand,
53-
pushMajMinCommand,
54-
pushLatestCommand
55-
])
56-
);
57-
5820
function versionMajorMinor(version: string) {
5921
const parts = version.split(".");
6022

@@ -64,3 +26,62 @@ function versionMajorMinor(version: string) {
6426

6527
return [null, null];
6628
}
29+
30+
function createShellTasks(sourceFile: string) {
31+
// Clean and build
32+
const cleanCommand = `rm -rf dist`;
33+
34+
const compileTypescript = `tsc -p tsconfig.prod.json`;
35+
36+
const moveFiles = `cp ./{package.json,yarn.lock,LICENSE,docker-entry.sh} dist`;
37+
const webpack = `webpack`;
38+
39+
const contents = fs.readFileSync(sourceFile).toString();
40+
41+
const npmPackage = JSON.parse(contents);
42+
43+
const version = npmPackage.version;
44+
const [versionMajor, versionMajMin] = versionMajorMinor(version);
45+
const repo = npmPackage.dockerRepository;
46+
const imageName = npmPackage.dockerImageName || npmPackage.name;
47+
48+
const dockerRepoImage = `${repo}/${imageName}`;
49+
50+
const imageWithVersion = `${dockerRepoImage}:${version}`;
51+
const imageWithVersionMajor = versionMajor ? `${dockerRepoImage}:${versionMajor}` : null;
52+
const imageWithVersionMajMin = versionMajMin ? `${dockerRepoImage}:${versionMajMin}` : null;
53+
const imageAsLatest = `${dockerRepoImage}:latest`;
54+
55+
// Docker build/tag
56+
const buildCommand = `docker build --tag ${imageWithVersion} .`;
57+
const tagMajorCommand = imageWithVersionMajor ? `docker tag ${imageWithVersion} ${imageWithVersionMajor}` : `echo "could not tag with major version"`;
58+
const tagMajMinCommand = imageWithVersionMajMin ? `docker tag ${imageWithVersion} ${imageWithVersionMajMin}` : `echo "could not tag with major.minor version"`;
59+
const tagLatestCommand = `docker tag ${imageWithVersion} ${imageAsLatest}`;
60+
61+
// Docker push
62+
const pushCommand = `docker push ${imageWithVersion}`;
63+
const pushMajorCommand = imageWithVersionMajor ? `docker push ${imageWithVersionMajor}` : `echo "could not push major version"`;
64+
const pushMajMinCommand = imageWithVersionMajMin ? `docker push ${imageWithVersionMajMin}` : `echo "could not push major.minor version"`;
65+
const pushLatestCommand = `docker push ${imageAsLatest}`;
66+
67+
return [
68+
shell.task([
69+
cleanCommand,
70+
compileTypescript,
71+
moveFiles,
72+
webpack
73+
]),
74+
shell.task([
75+
buildCommand,
76+
tagMajorCommand,
77+
tagMajMinCommand,
78+
tagLatestCommand
79+
]),
80+
shell.task([
81+
pushCommand,
82+
pushMajorCommand,
83+
pushMajMinCommand,
84+
pushLatestCommand
85+
])
86+
];
87+
}

package.json

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pipeline-ui",
3-
"version": "1.4.4",
3+
"version": "1.5.0",
44
"description": "",
55
"keywords": [],
66
"author": "Patrick Edson <[email protected]> (http://github.com/pedson)",
@@ -9,9 +9,8 @@
99
"dockerImageName": "pipeline-client",
1010
"scripts": {
1111
"devel": "DEBUG=pipeline* node $NODE_DEBUG_OPTION server/pipelineClientServer.js",
12-
"lint": "eslint src",
13-
"docker-build": "webpack && gulp docker-build",
14-
"docker-release": "webpack && gulp release"
12+
"docker-build": "gulp docker-build",
13+
"docker-release": "gulp release"
1514
},
1615
"devDependencies": {
1716
"@types/highcharts": "^4.2.6",
@@ -30,27 +29,15 @@
3029
"@types/socket.io-client": "^1.4.32",
3130
"@types/webpack": "^2.2.6",
3231
"@types/webpack-dev-server": "^2.4.0",
33-
"css-loader": "^0.28.11",
34-
"file-loader": "^1.1.11",
35-
"gulp": "^3.9.1",
36-
"gulp-shell": "^0.6.5",
37-
"semantic-ui": "^2.3.1",
38-
"style-loader": "^0.21.0",
39-
"ts-loader": "^3.5.0",
40-
"typescript": "2.9.2",
41-
"uglifyjs-webpack-plugin": "^1.2.5",
42-
"url-loader": "^1.0.1",
43-
"webpack": "^2.6.1",
44-
"webpack-dev-server": "^2.5.0"
45-
},
46-
"dependencies": {
4732
"apollo-boost": "^0.1.6",
33+
"css-loader": "^0.28.11",
4834
"cytoscape": "^2.7.13",
4935
"cytoscape-cxtmenu": "^2.10.3",
50-
"express": "^4.16.3",
51-
"express-http-proxy": "^1.2.0",
36+
"file-loader": "^1.1.11",
5237
"graphql": "^0.13.2",
5338
"graphql-tag": "^2.9.2",
39+
"gulp": "^3.9.1",
40+
"gulp-shell": "^0.6.5",
5441
"highcharts": "^5.0.7",
5542
"highcharts-heatmap": "^0.1.7",
5643
"highcharts-more": "^0.1.7",
@@ -73,8 +60,21 @@
7360
"react-toastify": "^4.0.1",
7461
"react-virtualized": "^9.12.0",
7562
"react-virtualized-select": "^3.1.0",
63+
"semantic-ui": "^2.3.1",
7664
"semantic-ui-react": "^0.81.1",
77-
"socket.io": "^2.1.1",
78-
"socket.io-client": "^2.1.1"
65+
"socket.io-client": "^2.1.1",
66+
"style-loader": "^0.23.1",
67+
"three-obj-loader": "^1.1.2",
68+
"ts-loader": "^5.3.0",
69+
"typescript": "^3.1.6",
70+
"url-loader": "^1.0.1",
71+
"webpack": "^4.25.1",
72+
"webpack-cli": "^3.1.2",
73+
"webpack-dev-server": "^3.1.10"
74+
},
75+
"dependencies": {
76+
"express": "^4.16.3",
77+
"express-http-proxy": "^1.2.0",
78+
"socket.io": "^2.1.1"
7979
}
8080
}

run.sh

-11
This file was deleted.

server/pipelineClientServer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as path from "path";
2+
import * as os from "os";
3+
const express = require("express");
4+
import * as http from "http";
25
import * as proxy from "express-http-proxy";
36

4-
const express = require("express");
57

68
const debug = require("debug")("pipeline-api:server");
79

@@ -18,8 +20,6 @@ if (process.env.NODE_ENV !== "production") {
1820
}
1921

2022
import {Configuration} from "./configuration";
21-
import * as http from "http";
22-
import * as os from "os";
2323

2424
const apiUri = `http://${Configuration.graphQLHostname}:${Configuration.graphQLPort}`;
2525

tsconfig.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"compileOnSave": true,
33
"compilerOptions": {
4+
"sourceMap": true,
45
"module": "commonjs",
56
"target": "es6",
67
"jsx": "react",
7-
"sourceMap": true,
8-
"experimentalDecorators": true,
9-
"skipLibCheck": true
8+
"skipLibCheck": true,
9+
"experimentalDecorators": true
1010
},
1111
"exclude": [
12+
"dist",
1213
"node_modules"
1314
]
1415
}

tsconfig.prod.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compileOnSave": false,
4+
"compilerOptions": {
5+
"sourceMap": false,
6+
"outDir": "dist"
7+
},
8+
"include": [
9+
"server"
10+
]
11+
}

webpack.config.ts

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import * as path from "path";
22

3-
import webpack = require("webpack");
4-
import * as UglifyJSPlugin from "uglifyjs-webpack-plugin";
5-
63
const src = path.join(__dirname, "client");
7-
const dist = path.join(__dirname, "public");
4+
const dist = path.join(__dirname, "dist", "public");
85

96
module.exports = {
107
context: src,
@@ -18,39 +15,26 @@ module.exports = {
1815
path: dist
1916
},
2017

18+
mode: "production",
19+
2120
module: {
2221
rules: [
2322
{
2423
test: /\.tsx?$/,
2524
loader: "ts-loader",
26-
exclude: /node_modules/,
25+
exclude: /node_modules/
2726
},
2827
{test: /\.css$/, use: "style-loader"},
2928
{test: /\.css$/, use: "css-loader"},
30-
{test: /\.(graphql|gql)$/, exclude: /node_modules/, loader: "graphql-tag/loader"},
3129
{
3230
test: /\.jpe?g$|\.gif$|\.png$|\.ttf$|\.eot$|\.svg$/,
3331
use: "file-loader?name=[name].[ext]?[hash]",
3432
},
35-
{
36-
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
37-
loader: "url-loader?limit=10000&mimetype=application/fontwoff"
38-
},
3933
]
4034
},
4135

4236
resolve: {
4337
extensions: [".tsx", ".ts", ".js"]
4438
},
45-
devtool: "source-map",
46-
plugins: [
47-
new UglifyJSPlugin({
48-
sourceMap: true
49-
}),
50-
new webpack.DefinePlugin({
51-
'process.env': {
52-
'NODE_ENV': JSON.stringify('production')
53-
}
54-
})
55-
]
39+
devtool: "source-map"
5640
};

0 commit comments

Comments
 (0)