Merge pull request #1472 from progrium/1442_mh-default-scaling

Use processes defined in `Procfile` when generating `DOKKU_SCALE` file
This commit is contained in:
Jose Diaz-Gonzalez
2015-09-16 20:44:36 -07:00
3 changed files with 31 additions and 10 deletions

View File

@@ -15,7 +15,7 @@ ps:stop <app> Stop app container(s)
## Scaling
Dokku allows you to run multiple process types at different container counts. For example, if you had an app that contained 1 web app listener and 1 background job processor, dokku can, spin up 1 container for each process type defined in the Procfile. *By default, dokku will only start a single web process.* However, if you wanted 2 job processors running simultaneously, you can modify this behavior in a few ways.
Dokku allows you to run multiple process types at different container counts. For example, if you had an app that contained 1 web app listener and 1 background job processor, dokku can, spin up 1 container for each process type defined in the Procfile. *By default, dokku will only start a single web process (if defined.)* However, if you wanted, for example, 2 job processors running simultaneously, you can modify this behavior in one of the following ways.
### DOKKU_SCALE file

View File

@@ -90,10 +90,17 @@ case "$1" in
DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
shift 2
generate_scale_file "$APP" "$IMAGE_TAG"
if [[ -z "$@" ]]; then
dokku_log_info1 "Scaling for $APP"
dokku_log_info2 "$(< $DOKKU_SCALE_FILE)"
[[ ! -e $DOKKU_SCALE_FILE ]] && generate_scale_file "$APP" "$IMAGE_TAG"
if [[ -z "$@" ]];then
dokku_log_info1_quiet "Scaling for $APP"
dokku_col_log_info1_quiet "proctype" "qty"
dokku_col_log_info1_quiet "--------" "---"
while read line || [[ -n "$line" ]]; do
[[ -z "$line" ]] && continue
PROC_NAME=${line%%=*}
PROC_COUNT=${line#*=}
dokku_col_log_info1 "$PROC_NAME" "$PROC_COUNT"
done < "$DOKKU_SCALE_FILE"
else
set_scale "$APP" "$@"
release_and_deploy "$APP" "$IMAGE_TAG"
@@ -103,7 +110,7 @@ case "$1" in
help | ps:help)
cat<<EOF
ps <app>, List processes running in app container(s)
ps:scale <app> <proc>=<count> [<proc>=<count>], Set how many instances of a given process to run
ps:scale [<app> <proc>=<count> [<proc>=<count>]], Get/Set how many instances of a given process to run
ps:start <app>, Start app container(s)
ps:stop <app>, Stop app container(s)
ps:rebuild <app>, Rebuild an app

View File

@@ -15,15 +15,29 @@ generate_scale_file() {
copy_from_image "$IMAGE" "/app/DOKKU_SCALE" "$DOKKU_ROOT/$APP" 2>/dev/null || true
if [[ ! -f $DOKKU_SCALE_FILE ]]; then
dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Defaulting to a single web process"
echo "web=1" >> $DOKKU_SCALE_FILE
dokku_log_info1_quiet "DOKKU_SCALE file not found in app image. Generating one based on Procfile..."
TMP_WORK_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_WORK_DIR" > /dev/null' RETURN
copy_from_image "$IMAGE" "/app/Procfile" "$TMP_WORK_DIR" 2>/dev/null || true
local PROCFILE="$TMP_WORK_DIR/Procfile"
if [[ ! -e "$PROCFILE" ]]; then
echo "web=1" >> $DOKKU_SCALE_FILE
else
while read line || [[ -n "$line" ]]; do
[[ -z "$line" ]] && continue
NAME=${line%%:*}
NUM_PROCS=0
[[ "$NAME" == "web" ]] && NUM_PROCS=1
echo "$NAME=$NUM_PROCS" >> $DOKKU_SCALE_FILE
done < "$PROCFILE"
fi
dokku_log_info1_quiet "New DOKKU_SCALE file generated"
else
dokku_log_info1_quiet "DOKKU_SCALE file found"
print_dokku_scale_file $APP
fi
print_dokku_scale_file $APP
}
set_scale() {