Previously we were exporting `DATABASE_URL` via the docker-args* hooks. This seems to confuse our users (since the env var is not displayed when calling `dokku config`) and in some cases it also seems that the env var is not correctly set. Another problem is if several services are linked to the same app and if they are exporting `DATABASE_URL` as well. Then we don’t know what will be set. To resolve theses issues, this patch changes the way we manage the env vars. We use standard dokku commands (`config` and `docker-options`) so config is set on the linked application and can be reviewed by the user easily. We also handle the case where `DATABASE_URL` is already set on the linked application. When it’s the case, we automatically generate another env var based on the following pattern: DOKKU_<service name>_<random unused color>_URL. For example, this can give: DOKKU_POSTGRES_BLACK_URL. Since naming is now handled automatically, the `alias` command has been removed. If the user wants to set a different env var on her app, it’s just a matter of using `dokku config:set` and pasting the wanted value. IP in DSN has been removed in favor of host name exported by docker in the container. This is more robust and simpler since the IP can change but the name will remain the same if the service container restarts for instance. With all those changes, a new command has been introduced: `promote`. The goal of this command is to easily set a service as the primary one when several are linked to an app. (see README for an example)
62 lines
2.2 KiB
Bash
Executable File
62 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
load test_helper
|
|
|
|
setup() {
|
|
dokku "$PLUGIN_COMMAND_PREFIX:create" l >&2
|
|
dokku apps:create my_app >&2
|
|
}
|
|
|
|
teardown() {
|
|
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l >&2
|
|
rm "$DOKKU_ROOT/my_app" -rf
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) error when there are no arguments" {
|
|
run dokku "$PLUGIN_COMMAND_PREFIX:link"
|
|
assert_contains "${lines[*]}" "Please specify a name for the service"
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) error when the app argument is missing" {
|
|
run dokku "$PLUGIN_COMMAND_PREFIX:link" l
|
|
assert_contains "${lines[*]}" "Please specify an app to run the command on"
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) error when the app does not exist" {
|
|
run dokku "$PLUGIN_COMMAND_PREFIX:link" l not_existing_app
|
|
assert_contains "${lines[*]}" "App not_existing_app does not exist"
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) error when the service does not exist" {
|
|
run dokku "$PLUGIN_COMMAND_PREFIX:link" not_existing_service my_app
|
|
assert_contains "${lines[*]}" "service not_existing_service does not exist"
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) error when the service is already linked to app" {
|
|
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
|
|
run dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
|
|
assert_contains "${lines[*]}" "Already linked as DATABASE_URL"
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) exports DATABASE_URL to app" {
|
|
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
|
|
url=$(dokku config:get my_app DATABASE_URL)
|
|
password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
|
|
assert_contains "$url" "postgres://postgres:$password@dokku-postgres-l:5432/l"
|
|
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) generates an alternate config url when DATABASE_URL already in use" {
|
|
dokku config:set my_app DATABASE_URL=postgres://user:pass@host:5432/db
|
|
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
|
|
run dokku config my_app
|
|
assert_contains "${lines[*]}" "DOKKU_POSTGRES_"
|
|
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
|
|
}
|
|
|
|
@test "($PLUGIN_COMMAND_PREFIX:link) links to app with docker-options" {
|
|
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
|
|
run dokku docker-options my_app
|
|
assert_contains "${lines[*]}" "--link dokku.postgres.l:dokku-postgres-l"
|
|
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
|
|
}
|