From 4ae280528e94927bc776bfba575bd14efffbedfa Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 9 Jan 2019 07:42:16 -0500 Subject: [PATCH] fix: ensure we can deploy code when there is no pre or post-deploy script defined Closes #3385 --- plugins/app-json/internal-functions | 6 +-- tests/apps/nodejs-express-noappjson/CHECKS | 5 ++ tests/apps/nodejs-express-noappjson/Procfile | 54 +++++++++++++++++++ .../nodejs-express-noappjson/check_deploy | 5 ++ .../nodejs-express-noappjson/package.json | 10 ++++ tests/apps/nodejs-express-noappjson/web.js | 12 +++++ tests/apps/nodejs-express-noappjson/worker.js | 6 +++ tests/unit/40_app-json.bats | 10 +++- 8 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 tests/apps/nodejs-express-noappjson/CHECKS create mode 100644 tests/apps/nodejs-express-noappjson/Procfile create mode 100755 tests/apps/nodejs-express-noappjson/check_deploy create mode 100644 tests/apps/nodejs-express-noappjson/package.json create mode 100644 tests/apps/nodejs-express-noappjson/web.js create mode 100644 tests/apps/nodejs-express-noappjson/worker.js diff --git a/plugins/app-json/internal-functions b/plugins/app-json/internal-functions index 4a2d5debc..28a632691 100755 --- a/plugins/app-json/internal-functions +++ b/plugins/app-json/internal-functions @@ -28,7 +28,7 @@ get_release_cmd() { extract_procfile "$APP" "$IMAGE_TAG" >/dev/null trap 'remove_procfile $APP' RETURN INT TERM EXIT - get_cmd_from_procfile "$APP" "release" "5000" || true + get_cmd_from_procfile "$APP" "release" "5000" } execute_script() { @@ -38,9 +38,9 @@ execute_script() { IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") if [[ "$PHASE_SCRIPT_KEY" == "release" ]]; then - SCRIPT_CMD=$(get_release_cmd "$APP" "$IMAGE" 2>/dev/null) + SCRIPT_CMD=$(get_release_cmd "$APP" "$IMAGE" 2>/dev/null || true) else - SCRIPT_CMD=$(get_phase_script "$IMAGE" "$PHASE_SCRIPT_KEY" 2>/dev/null) + SCRIPT_CMD=$(get_phase_script "$IMAGE" "$PHASE_SCRIPT_KEY" 2>/dev/null || true) fi if [[ -z "$SCRIPT_CMD" ]]; then diff --git a/tests/apps/nodejs-express-noappjson/CHECKS b/tests/apps/nodejs-express-noappjson/CHECKS new file mode 100644 index 000000000..67d14794a --- /dev/null +++ b/tests/apps/nodejs-express-noappjson/CHECKS @@ -0,0 +1,5 @@ +WAIT=2 # wait 2 seconds +TIMEOUT=5 # set timeout to 5 seconds +ATTEMPTS=2 # try 2 times + +/ nodejs/express \ No newline at end of file diff --git a/tests/apps/nodejs-express-noappjson/Procfile b/tests/apps/nodejs-express-noappjson/Procfile new file mode 100644 index 000000000..f38a198e3 --- /dev/null +++ b/tests/apps/nodejs-express-noappjson/Procfile @@ -0,0 +1,54 @@ +############################### +# DEVELOPMENT # +############################### + +# Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job) +cron: node worker.js +web: node web.js # testing inline comment +worker: node worker.js +custom: echo -n +release: touch /app/release.test + + +# Old version with separate processes (use this if you have issues with the threaded version) +# web: bundle exec rails server +# schedule: bundle exec rails runner bin/schedule.rb +# twitter: bundle exec rails runner bin/twitter_stream.rb +# dj: bundle exec script/delayed_job run + +############################### +# PRODUCTION # +############################### + +# You need to copy or link config/unicorn.rb.example to config/unicorn.rb for both production versions. +# Have a look at the deployment guides, if you want to set up huginn on your server: +# https://github.com/cantino/huginn/doc + +# Using the threaded worker (consumes less RAM but can run slower) +# web: bundle exec unicorn -c config/unicorn.rb +# jobs: bundle exec rails runner bin/threaded.rb + +# Old version with separate processes (use this if you have issues with the threaded version) +# web: bundle exec unicorn -c config/unicorn.rb +# schedule: bundle exec rails runner bin/schedule.rb +# twitter: bundle exec rails runner bin/twitter_stream.rb +# dj: bundle exec script/delayed_job run + +############################### +# Multiple DelayedJob workers # +############################### +# Per default Huginn can just run one agent at a time. Using a lot of agents or calling slow +# external services frequently might require more DelayedJob workers (an indicator for this is +# a backlog in your 'Job Management' page). +# Every uncommented line starts an additional DelayedJob worker. This works for development, production +# and for the threaded and separate worker processes. Keep in mind one worker needs about 300MB of RAM. +# +#dj2: bundle exec script/delayed_job -i 2 run +#dj3: bundle exec script/delayed_job -i 3 run +#dj4: bundle exec script/delayed_job -i 4 run +#dj5: bundle exec script/delayed_job -i 5 run +#dj6: bundle exec script/delayed_job -i 6 run +#dj7: bundle exec script/delayed_job -i 7 run +#dj8: bundle exec script/delayed_job -i 8 run +#dj9: bundle exec script/delayed_job -i 9 run +#dj10: bundle exec script/delayed_job -i 10 run diff --git a/tests/apps/nodejs-express-noappjson/check_deploy b/tests/apps/nodejs-express-noappjson/check_deploy new file mode 100755 index 000000000..e4519b442 --- /dev/null +++ b/tests/apps/nodejs-express-noappjson/check_deploy @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "nodejs/express" diff --git a/tests/apps/nodejs-express-noappjson/package.json b/tests/apps/nodejs-express-noappjson/package.json new file mode 100644 index 000000000..ce01f3afa --- /dev/null +++ b/tests/apps/nodejs-express-noappjson/package.json @@ -0,0 +1,10 @@ +{ + "name": "node-example", + "version": "0.0.1", + "dependencies": { + "express": "2.5.x" + }, + "engines": { + "node": "4.2.x" + } +} diff --git a/tests/apps/nodejs-express-noappjson/web.js b/tests/apps/nodejs-express-noappjson/web.js new file mode 100644 index 000000000..6b8f4d819 --- /dev/null +++ b/tests/apps/nodejs-express-noappjson/web.js @@ -0,0 +1,12 @@ +var express = require('express'); + +var app = express.createServer(express.logger()); + +app.get('/', function(request, response) { + response.send('nodejs/express'); +}); + +var port = process.env.PORT || 5000; +app.listen(port, function() { + console.log("Listening on " + port); +}); diff --git a/tests/apps/nodejs-express-noappjson/worker.js b/tests/apps/nodejs-express-noappjson/worker.js new file mode 100644 index 000000000..12133530d --- /dev/null +++ b/tests/apps/nodejs-express-noappjson/worker.js @@ -0,0 +1,6 @@ +function worker() { + console.log('sleeping for 60 seconds'); + setTimeout(worker, 60 * 1000); +} + +worker(); diff --git a/tests/unit/40_app-json.bats b/tests/unit/40_app-json.bats index b540daabb..7c43f6513 100644 --- a/tests/unit/40_app-json.bats +++ b/tests/unit/40_app-json.bats @@ -17,7 +17,7 @@ teardown() { } @test "(app-json) app.json scripts" { - deploy_app + deploy_app nodejs-express run /bin/bash -c "dokku run $TEST_APP ls /app/prebuild.test" echo "output: $output" @@ -36,3 +36,11 @@ teardown() { echo "status: $status" assert_success } + + +@test "(app-json) app.json scripts missing" { + deploy_app nodejs-express-noappjson + echo "output: $output" + echo "status: $status" + assert_success +}