Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Improve production mode #186

Merged
merged 5 commits into from
May 25, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ RUN apt-get update && \

EXPOSE 8888

CMD ["gluestick", "start", "-T"]
CMD ["gluestick", "start", "-P"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gluestick",
"version": "0.7.0",
"version": "0.7.1",
"description": "GlueStick is a command line interface for quickly developing universal web applications using React",
"main": "src/cli-harmony.js",
"bin": "src/cli-harmony.js",
Expand Down
11 changes: 10 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const karmaTestOption = ["-k, --karma", "run tests in Karma"];
const mochaReporterOption = ["-r, --reporter [type]", "run tests in Node.js"];
const firefoxOption = ["-F, --firefox", "Use Firefox with test runner"];
const singleRunOption = ["-S, --single", "Run test suite only once"];
const skipBuildOption = ["-P, --skip-build", "skip build when running in production mode"];

commander
.version(currentGluestickVersion);
Expand Down Expand Up @@ -82,6 +83,7 @@ commander
.option(...debugTestOption)
.option(...mochaReporterOption)
.option(...karmaTestOption)
.option(...skipBuildOption)
.action(checkGluestickProject)
.action(() => notifyUpdates())
.action(startAll)
Expand Down Expand Up @@ -210,7 +212,14 @@ async function startAll(options) {
process.exit();
}

spawnProcess("client");
// in production spawning the client really just creates a build. Our docker
// images pre-build and therefor they start with the skip build option as
// true. We only want to start the client in development mode or if
// skipBuild is not specified
if (!(isProduction && options.skipBuild)) {
spawnProcess("client");
}

spawnProcess("server", (options.debugServer ? ["--debug-server"] : []));

// Start tests unless they asked us not to or we are in production mode
Expand Down
68 changes: 38 additions & 30 deletions src/commands/start-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,47 @@ module.exports = function startServer (debug=false) {
process.exit(2);
}

pm2.start({
script: scriptPath,
name: name,
cwd: CWD,
exec_mode: "cluster",
instances: MAX_INSTANCES, // 0 = auto detect based on CPUs
max_memory_restart: process.env.MAX_MEMORY_RESTART || "200M",
environment_name: process.env.NODE_ENV,
no_autorestart: false,
merge_logs: true,
watch: process.env.NODE_ENV !== "production" ? ["assets", "src", "Index.js"] : false
}, (error) => {
if (error) {
logger.error(error);
pm2.disconnect();
}

// start showing the logs
spawn(path.join(__dirname, "..", "..", "node_modules", ".bin", "pm2"), ["logs", name, "--raw", "--lines", 0], {stdio: "inherit"});
// Stop any previous processes with the same name before starting new
// instances
pm2.stop(name, () => {
startPM2(scriptPath, name);
});
});
};

/**
* When the app is quit, we go through all of the processes that were
* started up because of PM2 and we terminate them.
*/
process.on("SIGINT", () => {
logger.info(`Stopping pm2 instance: ${highlight(name)}…`);
pm2.delete(name, () => {
pm2.disconnect(() => {
process.exit();
});
function startPM2 (scriptPath, name) {
pm2.start({
script: scriptPath,
name: name,
cwd: CWD,
exec_mode: "cluster",
instances: MAX_INSTANCES, // 0 = auto detect based on CPUs
max_memory_restart: process.env.MAX_MEMORY_RESTART || "200M",
environment_name: process.env.NODE_ENV,
no_autorestart: false,
merge_logs: true,
watch: process.env.NODE_ENV !== "production" ? ["assets", "src", "Index.js"] : false
}, (error) => {
if (error) {
logger.error(error);
pm2.disconnect();
}

// start showing the logs
spawn(path.join(__dirname, "..", "..", "node_modules", ".bin", "pm2"), ["logs", name, "--raw", "--lines", 0], {stdio: "inherit"});
});

/**
* When the app is quit, we go through all of the processes that were
* started up because of PM2 and we terminate them.
*/
process.on("SIGINT", () => {
logger.info(`Stopping pm2 instance: ${highlight(name)}…`);
pm2.delete(name, () => {
pm2.disconnect(() => {
process.exit();
});
});
});
};
}

4 changes: 1 addition & 3 deletions src/config/webpack-isomorphic-tools-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ module.exports = {
styles: {
extensions: ["css", "scss", "sass"],
filter: function(module, regex, options, log) {
if (options.development) {
return WebpackIsomorphicToolsPlugin.style_loader_filter(module, regex, options, log);
}
return WebpackIsomorphicToolsPlugin.style_loader_filter(module, regex, options, log);
},
path: WebpackIsomorphicToolsPlugin.style_loader_path_extractor,
parser: WebpackIsomorphicToolsPlugin.css_loader_parser
Expand Down
1 change: 1 addition & 0 deletions templates/new/src/config/.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ FROM truecar/gluestick:0.7.0
ADD . /app

RUN npm install
RUN gluestick build