Fix #1564: Use Procfile for process types in Dockerfile apps
* Document new Procfile feature * Add and update tests * Fix a typo in generate_scale_file (ref #1923)
This commit is contained in:
committed by
Jose Diaz-Gonzalez
parent
8e297cd38e
commit
6a01abb905
1
tests/apps/dockerfile-procfile/CHECKS
Normal file
1
tests/apps/dockerfile-procfile/CHECKS
Normal file
@@ -0,0 +1 @@
|
||||
/ nodejs/express
|
||||
16
tests/apps/dockerfile-procfile/Dockerfile
Normal file
16
tests/apps/dockerfile-procfile/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
FROM ubuntu:trusty
|
||||
ENV LC_ALL C
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
ENV DEBCONF_NONINTERACTIVE_SEEN true
|
||||
EXPOSE 3001/udp
|
||||
EXPOSE 3000/tcp
|
||||
EXPOSE 3003
|
||||
|
||||
RUN apt-get install -y software-properties-common && add-apt-repository ppa:chris-lea/node.js && apt-get update
|
||||
RUN apt-get install -y build-essential curl postgresql-client-9.3 nodejs git
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN npm install
|
||||
|
||||
CMD npm start
|
||||
8
tests/apps/dockerfile-procfile/Procfile
Normal file
8
tests/apps/dockerfile-procfile/Procfile
Normal file
@@ -0,0 +1,8 @@
|
||||
###############################
|
||||
# DEVELOPMENT #
|
||||
###############################
|
||||
|
||||
# Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job)
|
||||
cron: node worker.js
|
||||
web: node web.js
|
||||
worker: node worker.js
|
||||
2
tests/apps/dockerfile-procfile/check_deploy
Executable file
2
tests/apps/dockerfile-procfile/check_deploy
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express"
|
||||
13
tests/apps/dockerfile-procfile/package.json
Normal file
13
tests/apps/dockerfile-procfile/package.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "node-example",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"express": "2.5.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.2.x"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "false"
|
||||
}
|
||||
}
|
||||
12
tests/apps/dockerfile-procfile/web.js
Normal file
12
tests/apps/dockerfile-procfile/web.js
Normal file
@@ -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);
|
||||
});
|
||||
6
tests/apps/dockerfile-procfile/worker.js
Normal file
6
tests/apps/dockerfile-procfile/worker.js
Normal file
@@ -0,0 +1,6 @@
|
||||
function worker() {
|
||||
console.log('sleeping for 60 seconds');
|
||||
setTimeout(worker, 60 * 1000);
|
||||
}
|
||||
|
||||
worker();
|
||||
@@ -116,3 +116,128 @@ teardown() {
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(ps) dockerfile with procfile" {
|
||||
deploy_app dockerfile-procfile
|
||||
run bash -c "dokku ps:stop $TEST_APP"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do
|
||||
run bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_failure
|
||||
done
|
||||
|
||||
run bash -c "dokku ps:start $TEST_APP"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do
|
||||
run bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
done
|
||||
|
||||
run bash -c "dokku ps:restart $TEST_APP"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do
|
||||
run bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
done
|
||||
|
||||
run bash -c "dokku ps:rebuild $TEST_APP"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do
|
||||
run bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
done
|
||||
}
|
||||
|
||||
@test "(ps:scale) dockerfile with procfile" {
|
||||
run bash -c "dokku ps:scale $TEST_APP web=2 worker=2"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
deploy_app dockerfile-procfile
|
||||
for PROC_TYPE in web worker; do
|
||||
run bash -c "docker ps --format '{{.ID}} {{.Command}}' --no-trunc"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
goodlines=""
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do
|
||||
cid=$(< $CID_FILE)
|
||||
assert_output_contains "$cid"
|
||||
goodlines+=$(echo "$output" | grep "$cid")
|
||||
done
|
||||
output="$goodlines"
|
||||
assert_output_contains "node ${PROC_TYPE}.js" 2
|
||||
done
|
||||
|
||||
run bash -c "dokku ps:scale $TEST_APP web=1 worker=1"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
for PROC_TYPE in web worker; do
|
||||
run bash -c "docker ps --format '{{.ID}} {{.Command}}' --no-trunc"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
goodlines=""
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do
|
||||
cid=$(< $CID_FILE)
|
||||
assert_output_contains "$cid"
|
||||
goodlines+=$(echo "$output" | grep "$cid")
|
||||
done
|
||||
output="$goodlines"
|
||||
assert_output_contains "node ${PROC_TYPE}.js"
|
||||
done
|
||||
|
||||
run bash -c "dokku ps:scale $TEST_APP web=0 worker=0"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
for PROC_TYPE in web worker; do
|
||||
CIDS=""
|
||||
shopt -s nullglob
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do
|
||||
CIDS+=$(< $CID_FILE)
|
||||
CIDS+=" "
|
||||
done
|
||||
shopt -u nullglob
|
||||
run bash -c "[[ -z \"$CIDS\" ]]"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
done
|
||||
}
|
||||
|
||||
@test "(ps:scale) procfile commands extraction" {
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions"
|
||||
cat <<EOF > "$DOKKU_ROOT/$TEST_APP/DOKKU_PROCFILE"
|
||||
web: node web.js
|
||||
worker: node worker.js
|
||||
EOF
|
||||
run get_cmd_from_procfile "$TEST_APP" web
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "node web.js"
|
||||
|
||||
run get_cmd_from_procfile "$TEST_APP" worker
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "node worker.js"
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ teardown() {
|
||||
shopt -s nullglob
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do
|
||||
CIDS+=$(< $CID_FILE)
|
||||
CIDS+=" "1
|
||||
CIDS+=" "
|
||||
done
|
||||
shopt -u nullglob
|
||||
run bash -c "[[ -z \"$CIDS\" ]]"
|
||||
|
||||
@@ -57,6 +57,17 @@ assert_output() {
|
||||
assert_equal "$expected" "$output"
|
||||
}
|
||||
|
||||
# ShellCheck doesn't know about $output from Bats
|
||||
# shellcheck disable=SC2154
|
||||
assert_output_contains() {
|
||||
local input="$output"; local expected="$1"; local count="${2:-1}"; local found=0
|
||||
until [ "${input/$expected/}" = "$input" ]; do
|
||||
input="${input/$expected/}"
|
||||
let found+=1
|
||||
done
|
||||
assert_equal $count $found
|
||||
}
|
||||
|
||||
# ShellCheck doesn't know about $lines from Bats
|
||||
# shellcheck disable=SC2154
|
||||
assert_line() {
|
||||
|
||||
Reference in New Issue
Block a user