Skip to content

Commit

Permalink
refactor: move app.json script execution into it's own plugin
Browse files Browse the repository at this point in the history
Rather than have this live in 00_dokku-standard, move it out so that it may start to support various other features around the app.json manifest.
  • Loading branch information
josegonzalez committed Jan 7, 2019
1 parent 1a36c77 commit 952db83
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 31 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions plugins/app-json/plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[plugin]
description = "dokku core app-json plugin"
version = "0.13.4"
[plugin.config]
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/00_dokku-standard/exec-app-json-scripts"
source "$PLUGIN_CORE_AVAILABLE_PATH/app-json/internal-functions"

exec_app_json_scripts() {
declare desc="core app.json scripts execution"
local trigger="post-deploy app_json_scripts"
app_json_post_deploy() {
declare desc="app-json scripts execution"
local trigger="app_json_post_deploy"
local APP="$1"
local IMAGE_TAG="$4"
local PHASE_SCRIPT_KEY="postdeploy"
Expand All @@ -15,4 +15,4 @@ exec_app_json_scripts() {
execute_script "$APP" "$IMAGE_TAG" "$PHASE_SCRIPT_KEY"
}

exec_app_json_scripts "$@"
app_json_post_deploy "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/00_dokku-standard/exec-app-json-scripts"
source "$PLUGIN_CORE_AVAILABLE_PATH/app-json/internal-functions"

exec_app_json_scripts() {
declare desc="core app.json scripts execution"
local trigger="pre-deploy app_json_scripts"
app_json_pre_deploy() {
declare desc="app-json scripts execution"
local trigger="app_json_pre_deploy"
local APP="$1"
local IMAGE_TAG="$2"
local PHASE_SCRIPT_KEY="predeploy"
Expand All @@ -15,4 +15,4 @@ exec_app_json_scripts() {
execute_script "$APP" "$IMAGE_TAG" "$PHASE_SCRIPT_KEY"
}

exec_app_json_scripts "$@"
app_json_pre_deploy "$@"
21 changes: 0 additions & 21 deletions tests/unit/30_core_1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,3 @@ EOF
echo "status: $status"
assert_output "3001/udp 3000/tcp 3003"
}

@test "(core) app.json scripts" {
deploy_app

run /bin/bash -c "dokku run $TEST_APP ls /app/prebuild.test"
echo "output: $output"
echo "status: $status"
assert_failure

run /bin/bash -c "dokku run $TEST_APP ls /app/predeploy.test"
echo "output: $output"
echo "status: $status"
assert_success

CID=$(docker ps -a -q -f "ancestor=dokku/${TEST_APP}" -f "label=dokku_phase_script=postdeploy")
IMAGE_ID=$(docker commit $CID dokku-test/${TEST_APP})
run /bin/bash -c "docker run -ti $IMAGE_ID ls /app/postdeploy.test"
echo "output: $output"
echo "status: $status"
assert_success
}
38 changes: 38 additions & 0 deletions tests/unit/40_app-json.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bats

load test_helper

setup() {
global_setup
create_app
DOCKERFILE="$BATS_TMPDIR/Dockerfile"
}

teardown() {
rm -rf /home/dokku/$TEST_APP/tls
destroy_app
dokku config:unset --global DOKKU_RM_CONTAINER
rm -f "$DOCKERFILE"
global_teardown
}

@test "(app-json) app.json scripts" {
deploy_app

run /bin/bash -c "dokku run $TEST_APP ls /app/prebuild.test"
echo "output: $output"
echo "status: $status"
assert_failure

run /bin/bash -c "dokku run $TEST_APP ls /app/predeploy.test"
echo "output: $output"
echo "status: $status"
assert_success

CID=$(docker ps -a -q -f "ancestor=dokku/${TEST_APP}" -f "label=dokku_phase_script=postdeploy")
IMAGE_ID=$(docker commit $CID dokku-test/${TEST_APP})
run /bin/bash -c "docker run -ti $IMAGE_ID ls /app/postdeploy.test"
echo "output: $output"
echo "status: $status"
assert_success
}

0 comments on commit 952db83

Please sign in to comment.