mirror of
https://github.com/dokku/dokku.git
synced 2026-07-11 04:51:57 +02:00
The `dokku.com/cron-id` label could exceed Kubernetes' 63-byte cap because the cron ID is `base36(appName === command === schedule)`, which expands roughly 1.5x per byte. The label is now keyed `dokku.com/cron-hash` and holds the `sha1` hex digest of the cron-id, a fixed 40-character value that always fits the cap. The same hex digest is mirrored into the `dokku.com/cron-hash` annotation, and the original base36 cron-id stays in the `dokku.com/cron-id` annotation that `cron:list` reads when surfacing user-facing IDs. Per-task lookups stay server-side via label selectors, so `cron:set --maintenance` and the forbid/replace concurrency checks on `dokku run --cron-id` keep working without any in-memory filtering.
345 lines
10 KiB
Bash
345 lines
10 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
setup_file() {
|
|
install_pack
|
|
}
|
|
|
|
setup() {
|
|
global_setup
|
|
create_app
|
|
}
|
|
|
|
teardown() {
|
|
destroy_app
|
|
global_teardown
|
|
}
|
|
|
|
@test "(builder-pack:report) info-flag works before deploy" {
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-projecttoml-path"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path project.alt.toml"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-projecttoml-path"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output "project.alt.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-invalid-flag"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_failure
|
|
assert_output_contains "Invalid flag passed"
|
|
}
|
|
|
|
@test "(builder-pack:report) --global --builder-pack-global-projecttoml-path" {
|
|
run /bin/bash -c "dokku builder-pack:set --global projecttoml-path project.alt.toml"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:report --global --builder-pack-global-projecttoml-path"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output "project.alt.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:set --global projecttoml-path"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
}
|
|
|
|
@test "(builder-pack:report) projecttoml-path raw vs computed vs global" {
|
|
run /bin/bash -c "dokku builder-pack:set --global projecttoml-path"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-projecttoml-path"
|
|
assert_success
|
|
assert_output_not_exists
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-global-projecttoml-path"
|
|
assert_success
|
|
assert_output_not_exists
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-computed-projecttoml-path"
|
|
assert_success
|
|
assert_output "project.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:set --global projecttoml-path project.global.toml"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-global-projecttoml-path"
|
|
assert_success
|
|
assert_output "project.global.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-computed-projecttoml-path"
|
|
assert_success
|
|
assert_output "project.global.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path project.app.toml"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-projecttoml-path"
|
|
assert_success
|
|
assert_output "project.app.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-global-projecttoml-path"
|
|
assert_success
|
|
assert_output "project.global.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:report $TEST_APP --builder-pack-computed-projecttoml-path"
|
|
assert_success
|
|
assert_output "project.app.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder-pack:set --global projecttoml-path"
|
|
assert_success
|
|
}
|
|
|
|
@test "(builder-pack:set)" {
|
|
run /bin/bash -c "dokku config:set $TEST_APP SECRET_KEY=fjdkslafjdk"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder:set $TEST_APP selected pack"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku buildpacks:set-property $TEST_APP stack heroku/builder:24"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt_cnb
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'Building with buildpack 1' 0
|
|
assert_output_contains 'Installing dependencies using pip'
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path nonexistent.toml"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'Building with buildpack 1' 0
|
|
assert_output_contains 'Installing dependencies using pip'
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path project2.toml"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'Building with buildpack 1'
|
|
assert_output_contains 'Installing dependencies using pip' 0
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'Building with buildpack 1' 0
|
|
assert_output_contains 'Installing dependencies using pip'
|
|
}
|
|
|
|
@test "(builder-pack) run" {
|
|
run /bin/bash -c "dokku config:set $TEST_APP SECRET_KEY=fjdkslafjdk"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder:set $TEST_APP selected pack"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt_cnb
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'from cnb stack'
|
|
assert_output_contains 'Building with buildpack 1' 0
|
|
assert_output_contains 'Installing dependencies using pip'
|
|
|
|
run /bin/bash -c "dokku run $TEST_APP python3 task.py test"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output "['task.py', 'test']"
|
|
|
|
run /bin/bash -c "dokku --quiet run $TEST_APP task"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output "['task.py', 'test']"
|
|
|
|
run /bin/bash -c "dokku run $TEST_APP env"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains "SECRET_KEY=fjdkslafjdk"
|
|
}
|
|
|
|
@test "(builder-pack) git:from-image without a Procfile" {
|
|
run /bin/bash -c "dokku git:from-image $TEST_APP dokku/smoke-test-gradle-app:1"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
}
|
|
|
|
@test "(ps) cnb env vars" {
|
|
run /bin/bash -c "dokku config:set $TEST_APP APP_RESPECTS_ENV_VARS=1"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder:set $TEST_APP selected pack"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt_cnb
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "curl $(dokku url $TEST_APP)/env"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains '"APP_RESPECTS_ENV_VARS": "1"'
|
|
}
|
|
|
|
@test "(builder-pack) cron:run" {
|
|
run /bin/bash -c "dokku config:set $TEST_APP SECRET_KEY=fjdkslafjdk"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder:set $TEST_APP selected pack"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP cron_run_wrapper
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'from cnb stack'
|
|
assert_output_contains 'Building with buildpack 1' 0
|
|
assert_output_contains 'Installing dependencies using pip'
|
|
|
|
cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')"
|
|
run /bin/bash -c "echo $cron_id"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_exists
|
|
|
|
run /bin/bash -c "dokku cron:run $TEST_APP $cron_id"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output "['task.py', 'some', 'cron', 'task']"
|
|
}
|
|
|
|
@test "(builder-pack) cron:run with Procfile reference" {
|
|
run /bin/bash -c "dokku config:set $TEST_APP SECRET_KEY=fjdkslafjdk"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "dokku builder:set $TEST_APP selected pack"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP cron_run_procfile_wrapper
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains 'from cnb stack'
|
|
assert_output_contains 'Building with buildpack 1' 0
|
|
assert_output_contains 'Installing dependencies using pip'
|
|
|
|
cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')"
|
|
run /bin/bash -c "echo $cron_id"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_exists
|
|
|
|
run /bin/bash -c "dokku --quiet cron:run $TEST_APP $cron_id"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output "['task.py', 'test']"
|
|
}
|
|
|
|
@test "(builder-pack) core-post-extract renames the configured project.toml" {
|
|
echo "" >"$BATS_TEST_TMPDIR/project2.toml"
|
|
|
|
run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path project2.toml"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run_plugin_script builder-pack core-post-extract "$TEST_APP" "$BATS_TEST_TMPDIR" HEAD
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
|
|
run /bin/bash -c "test -f $BATS_TEST_TMPDIR/project.toml"
|
|
assert_success
|
|
|
|
run /bin/bash -c "test ! -e $BATS_TEST_TMPDIR/project2.toml"
|
|
assert_success
|
|
}
|
|
|
|
cron_run_wrapper() {
|
|
local APP="$1"
|
|
local APP_REPO_DIR="$2"
|
|
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
|
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
|
|
|
add_requirements_txt "$APP" "$APP_REPO_DIR"
|
|
ls -lah "$APP_REPO_DIR"
|
|
mv -f "$APP_REPO_DIR/app-cnb-cron.json" "$APP_REPO_DIR/app.json"
|
|
}
|
|
|
|
cron_run_procfile_wrapper() {
|
|
local APP="$1"
|
|
local APP_REPO_DIR="$2"
|
|
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
|
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
|
|
|
add_requirements_txt "$APP" "$APP_REPO_DIR"
|
|
ls -lah "$APP_REPO_DIR"
|
|
mv -f "$APP_REPO_DIR/app-cnb-cron-procfile.json" "$APP_REPO_DIR/app.json"
|
|
}
|