-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Support scripts.dokku. in app.json #1836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Deployment Tasks | ||
|
|
||
| Sometimes you need to run a command on at deployment time, but before an app is completely deployed. | ||
| Common use cases include: | ||
|
|
||
| * Checking a database is initialised | ||
| * Running database migrations | ||
| * Any commands required to set up the server (e.g. something like a Django `collectstatic`) | ||
|
|
||
| ## `app.json` and `scripts.dokku` | ||
|
|
||
| Dokku accomplishes this by using an `app.json` file. We (mostly) use the same format as Heroku's [app.json](https://devcenter.heroku.com/articles/app-json-schema). | ||
| However, dokku currently only supports the nodes `scripts.dokku.predeploy` and `scripts.dokku.postdeploy`. | ||
| Simply place an `app.json` file in the root of your repository. | ||
| NOTE: `app.json` is only supported in buildpack-deployed apps and postdeploy changes are not committed to the app image. | ||
|
|
||
| ### Example app.json | ||
|
|
||
| ``` | ||
| { | ||
| "name": "barebones nodejs", | ||
| "description": "A barebones Node.js app using Express 4.", | ||
| "keywords": [ | ||
| "nodejs", | ||
| "express" | ||
| ], | ||
| "repository": "https://github.com/michaelshobbs/node-js-sample", | ||
| "scripts": { | ||
| "dokku": { | ||
| "predeploy": "touch /app/predeploy.test", | ||
| "postdeploy": "touch /app/postdeploy.test" | ||
| } | ||
| }, | ||
| "env": { | ||
| "SECRET_TOKEN": { | ||
| "description": "A secret key for verifying the integrity of signed cookies.", | ||
| "value": "secret" | ||
| }, | ||
| "WEB_CONCURRENCY": { | ||
| "description": "The number of processes to run.", | ||
| "generator": "echo 5" | ||
| } | ||
| }, | ||
| "image": "gliderlabs/herokuish", | ||
| "addons": [ | ||
| "dokku-postgres", | ||
| "dokku-redis" | ||
| ], | ||
| "buildpacks": [ | ||
| { | ||
| "url": "https://github.com/heroku/heroku-buildpack-nodejs" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,7 +207,7 @@ case "$1" in | |
| done < "$DOKKU_SCALE_FILE" | ||
|
|
||
| dokku_log_info1 "Running post-deploy" | ||
| plugn trigger post-deploy $APP $port $ipaddr | ||
| plugn trigger post-deploy $APP $port $ipaddr $IMAGE_TAG | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really be cleaned up imo.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wut?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The plugn trigger pre-deploy $APP $IMAGE_TAGMaybe we should follow that and instead do: plugn trigger post-deploy $APP $IMAGE_TAG $ipaddr $portOr similar? What uses the port/ipaddr from here that cannot retrieve it from some other helper?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see. This would break any
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I meant that too :) |
||
|
|
||
| # kill the old container | ||
| if [[ -n "$oldids" ]]; then | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x | ||
| source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" | ||
| APP="$1" | ||
|
|
||
| case "$0" in | ||
| *pre-deploy) | ||
| IMAGE_TAG="$2" | ||
| IMAGE=$(get_app_image_name $APP $IMAGE_TAG) | ||
| PHASE_SCRIPT_KEY="predeploy" | ||
| ;; | ||
| *post-deploy) | ||
| IMAGE_TAG="$4" | ||
| IMAGE=$(get_app_image_name $APP $IMAGE_TAG) | ||
| PHASE_SCRIPT_KEY="postdeploy" | ||
| ;; | ||
| esac | ||
|
|
||
| get_phase_script() { | ||
| local PHASE_SCRIPT_KEY="$1" | ||
| local TMP_WORK_DIR=$(mktemp -d) | ||
| local APP_JSON_FILE="$TMP_WORK_DIR/app.json" | ||
| trap 'rm -rf "$TMP_WORK_DIR" > /dev/null' RETURN | ||
|
|
||
| copy_from_image "$IMAGE" "/app/app.json" "$TMP_WORK_DIR" 2>/dev/null || true | ||
|
|
||
| if [[ -f "$APP_JSON_FILE" ]];then | ||
| local VALUE=$(get_json_value scripts.dokku.${PHASE_SCRIPT_KEY} < "$APP_JSON_FILE") | ||
| else | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "$VALUE" | ||
| } | ||
|
|
||
| execute_script() { | ||
| local SCRIPT_CMD=$(get_phase_script "$PHASE_SCRIPT_KEY") | ||
| if [[ -n "$SCRIPT_CMD" ]];then | ||
| dokku_log_info1 "Running '$SCRIPT_CMD' in app container" | ||
| local COMMAND="cd /app ; " | ||
| local COMMAND+=" for file in /app/.profile.d/*; do source \$file; done ; " | ||
| local COMMAND+=" echo restoring installation cache... ; " | ||
| local COMMAND+=" cp -rfp /cache /tmp/ || true ; " | ||
| local COMMAND+=" $SCRIPT_CMD ; " | ||
| local COMMAND+=" echo removing installation cache... ; " | ||
| local COMMAND+=" rm -rf /tmp/cache || true " | ||
| local DOCKER_ARGS=$(: | plugn trigger docker-args-deploy $APP) | ||
| local CACHE_DIR="$DOKKU_ROOT/$APP/cache" | ||
| id=$(docker run $DOKKU_GLOBAL_RUN_ARGS --label=dokku_phase_script=${PHASE_SCRIPT_KEY} -d -v $CACHE_DIR:/cache $DOCKER_ARGS $IMAGE /bin/bash -c "$COMMAND") | ||
| test "$(docker wait $id)" -eq 0 | ||
| dokku_container_log_verbose_quiet $id | ||
| if [[ "$PHASE_SCRIPT_KEY" != "postdeploy" ]];then | ||
| docker commit "$id" "$IMAGE" > /dev/null | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| dokku_log_info1 "Attempting to run scripts.dokku.$PHASE_SCRIPT_KEY from app.json (if defined)" | ||
| execute_script |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exec-app-json-scripts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exec-app-json-scripts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "name": "Sample node.js express app", | ||
| "description": "Used in dokku's test suite", | ||
| "keywords": [ | ||
| "nodejs", | ||
| "express", | ||
| "testing" | ||
| ], | ||
| "website": "http://dokku.viewdocs.io/dokku/", | ||
| "repository": "https://github.com/dokku/dokku", | ||
| "logo": "https://raw.githubusercontent.com/dokku/dokku/master/docs/assets/dokku.png", | ||
| "scripts": { | ||
| "dokku": { | ||
| "predeploy": "touch /app/predeploy.test", | ||
| "postdeploy": "touch /app/postdeploy.test" | ||
| } | ||
| }, | ||
| "env": { | ||
| "SECRET_TOKEN": { | ||
| "description": "A secret key for verifying the integrity of signed cookies.", | ||
| "value": "secret" | ||
| }, | ||
| "WEB_CONCURRENCY": { | ||
| "description": "The number of processes to run.", | ||
| "generator": "echo 5" | ||
| } | ||
| }, | ||
| "image": "gliderlabs/herokuish", | ||
| "addons": [ | ||
| "dokku-postgres", | ||
| "dokku-redis" | ||
| ], | ||
| "buildpacks": [ | ||
| { | ||
| "url": "https://github.com/heroku/heroku-buildpack-nodejs" | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we support
scripts.postdeployas well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. We said in #1824 that we didn't want to overload the heroku bits of
app.json. I took that to mean we would support only the things that correlate directly or implement our own. Meaning, Heroku says they only runscripts.postdeployat app creation and we wanted something different. With that understanding we can reuse things likebuildpacksandenvsince we'll use those in the same way as Heroku.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, what I'm saying is should we also implement their
scripts.postdeployhook at app creation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. It feels a little confusing from a user perspective though. As that wasn't part of the original issue (#1824), I propose we punt on this one and see if we get any user feedback asking for it.