diff --git a/bin/release b/bin/release index ac7ff7c82..2e7d1a5aa 100755 --- a/bin/release +++ b/bin/release @@ -1,8 +1,12 @@ #!/usr/bin/env bash # bin/release -cat << EOF -addons: [] -default_process_types: - web: npm start --max-old-space-size=$(( $(jq -r '.limits.mem' <<<"$VCAP_APPLICATION") * 75 / 100 )) $NPM_CLI_OPTIONS -EOF + +echo 'addons: []' +echo 'default_process_types:' + +if [[ "${OPTIMIZE_MEMORY:-}" = "true" ]]; then + echo ' web: npm start --optimize_for_size --always_compact --max_old_space_size=$(( $(jq -r '.limits.mem' <<<"$VCAP_APPLICATION") * 75 / 100 ))' +else + echo ' web: npm start' +fi diff --git a/cf_spec/fixtures/without_procfile/.gitignore b/cf_spec/fixtures/simple_app/.gitignore similarity index 100% rename from cf_spec/fixtures/without_procfile/.gitignore rename to cf_spec/fixtures/simple_app/.gitignore diff --git a/cf_spec/fixtures/without_procfile/README.md b/cf_spec/fixtures/simple_app/README.md similarity index 100% rename from cf_spec/fixtures/without_procfile/README.md rename to cf_spec/fixtures/simple_app/README.md diff --git a/cf_spec/fixtures/simple_app/manifest.yml b/cf_spec/fixtures/simple_app/manifest.yml new file mode 100644 index 000000000..52d60ad13 --- /dev/null +++ b/cf_spec/fixtures/simple_app/manifest.yml @@ -0,0 +1,2 @@ +--- + memory: 350MB diff --git a/cf_spec/fixtures/without_procfile/package.json b/cf_spec/fixtures/simple_app/package.json similarity index 72% rename from cf_spec/fixtures/without_procfile/package.json rename to cf_spec/fixtures/simple_app/package.json index 61d7a4631..0d77dc508 100644 --- a/cf_spec/fixtures/without_procfile/package.json +++ b/cf_spec/fixtures/simple_app/package.json @@ -1,5 +1,5 @@ { - "name": "node_web_app", + "name": "simple_app", "version": "0.0.0", "description": "hello, world", "main": "server.js", @@ -8,12 +8,6 @@ }, "author": "", "license": "BSD-2-Clause", - "dependencies": { - "logfmt": "~1.1.2", - "express": "~4.0.0" - }, - "engines" : { - }, "repository" : { "type" : "git", diff --git a/cf_spec/fixtures/simple_app/server.js b/cf_spec/fixtures/simple_app/server.js new file mode 100644 index 000000000..803d2e9a0 --- /dev/null +++ b/cf_spec/fixtures/simple_app/server.js @@ -0,0 +1,16 @@ +const http = require('http') +const port = process.env.PORT || 8080 + +const requestHandler = (request, response) => { + response.end(`MaxOldSpace: ${process.env.npm_config_max_old_space_size}`) +} + +const server = http.createServer(requestHandler) + +server.listen(port, (err) => { + if (err) { + return console.log('something bad happened', err) + } + + console.log(`server is listening on ${port}`) +}) diff --git a/cf_spec/fixtures/without_procfile/.npmrc b/cf_spec/fixtures/without_procfile/.npmrc deleted file mode 100644 index 1e8fc6419..000000000 --- a/cf_spec/fixtures/without_procfile/.npmrc +++ /dev/null @@ -1 +0,0 @@ -ca= diff --git a/cf_spec/fixtures/without_procfile/package.sh b/cf_spec/fixtures/without_procfile/package.sh deleted file mode 100755 index e76a70db5..000000000 --- a/cf_spec/fixtures/without_procfile/package.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -l - -rm -rf node_modules -npm install diff --git a/cf_spec/fixtures/without_procfile/resolve b/cf_spec/fixtures/without_procfile/resolve deleted file mode 100644 index 8e6eba22d..000000000 --- a/cf_spec/fixtures/without_procfile/resolve +++ /dev/null @@ -1 +0,0 @@ -0.10.26 \ No newline at end of file diff --git a/cf_spec/fixtures/without_procfile/server.js b/cf_spec/fixtures/without_procfile/server.js deleted file mode 100644 index 60a8e29ac..000000000 --- a/cf_spec/fixtures/without_procfile/server.js +++ /dev/null @@ -1,18 +0,0 @@ -// web.js - -console.log("***************************I'm running!********************************") - -var express = require("express"); -var logfmt = require("logfmt"); -var app = express(); - -app.use(logfmt.requestLogger()); - -app.get('/', function(req, res) { - res.send('Hello, World!'); -}); - -var port = Number(process.env.PORT || 5000); -app.listen(port, function() { - console.log("Listening on " + port); -}); diff --git a/cf_spec/integration/deploy_a_node_app_spec.rb b/cf_spec/integration/deploy_a_node_app_spec.rb index ad203c972..c0a3b9bc0 100644 --- a/cf_spec/integration/deploy_a_node_app_spec.rb +++ b/cf_spec/integration/deploy_a_node_app_spec.rb @@ -3,7 +3,8 @@ require 'open3' describe 'CF NodeJS Buildpack' do - subject(:app) { Machete.deploy_app(app_name) } + subject(:app) { Machete.deploy_app(app_name, env: app_env) } + let(:app_env) { {} } let(:browser) { Machete::Browser.new(app) } let(:buildpack_dir) { File.join(File.dirname(__FILE__), '..', '..') } let(:version_file) { File.join(buildpack_dir, 'VERSION') } @@ -82,7 +83,7 @@ context 'with an unsupported, but released, nodejs version' do let(:app_name) { 'unsupported_node_version' } - it 'displays a nice error messages and gracefully fails' do + it 'displhttps://github.com/cloudfoundry-samples/pong_matcher_rails/pull/3ays a nice error messages and gracefully fails' do expect(app).to_not be_running expect(app).to have_logged 'Downloading and installing node 4.1.1' expect(app).to_not have_logged 'Downloaded [' @@ -90,25 +91,24 @@ end end - context 'with no Procfile and no NPM_CLI_OPTIONS env var' do - let (:app_name) { 'without_procfile' } + context 'with no Procfile and OPTIMIZE_MEMORY=true' do + let (:app_name) { 'simple_app' } + let (:app_env) { { OPTIMIZE_MEMORY: true } } it 'is running with autosized max_old_space_size' do expect(app).to be_running - expect(app).to have_logged("--max_old_space_size=768") + browser.visit_path('/') + expect(browser).to have_body('MaxOldSpace: 262') # 350 * 75% end end - context 'with no Procfile and with NPM_CLI_OPTIONS env var' do - let (:app_name) { 'without_procfile' } + context 'with no Procfile and OPTIMIZE_MEMORY is unset' do + let (:app_name) { 'simple_app' } - subject(:app) do - Machete.deploy_app(app_name, env: {'NPM_CLI_OPTIONS' => '--trace-sync-io'}) - end - - it 'is running with autosized max_old_space_size and appended NPM_CLI_OPTIONS' do + it 'does not run with autosized max_old_space_size' do expect(app).to be_running - expect(app).to have_logged("--max_old_space_size=768 --trace-sync-io") + browser.visit_path('/') + expect(browser).to have_body('MaxOldSpace: undefined') end end