Add export, import and clone commands

This commit is contained in:
Loïc Guitaut
2015-09-13 23:32:05 +02:00
parent 126ce8f8f7
commit 57e4b08158
5 changed files with 139 additions and 11 deletions

View File

@@ -20,13 +20,13 @@ dokku plugins-install
```
redis:alias <name> <alias> Set an alias for the docker link
redis:clone <name> <new-name> NOT IMPLEMENTED
redis:clone <name> <new-name> Create container <new-name> then copy data from <name> into <new-name>
redis:connect <name> Connect via redis-cli to a redis service
redis:create <name> Create a redis service
redis:destroy <name> Delete the service and stop its container if there are no links left
redis:export <name> NOT IMPLEMENTED
redis:export <name> Export a dump of the redis service database
redis:expose <name> [port] Expose a redis service on custom port if provided (random port otherwise)
redis:import <name> <file> NOT IMPLEMENTED
redis:import <name> <file> Import a dump into the redis service database
redis:info <name> Print the connection information
redis:link <name> <app> Link the redis service to the app
redis:list List all redis services
@@ -86,6 +86,15 @@ dokku redis:unlink lolipop playground
dokku redis:logs lolipop
dokku redis:logs lolipop -t # to tail
# you can dump the database
dokku redis:export lolipop > lolipop.rdb
# you can import a dump
dokku redis:import lolipop < database.rdb
# you can clone an existing database to a new one
dokku redis:clone lolipop new_database
# finally, you can destroy the container
dokku redis:destroy lolipop
```

View File

@@ -106,16 +106,24 @@ case "$1" in
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
SERVICE_NAME=$(get_service_name "$SERVICE")
dokku_log_fail "Not yet implemented"
docker exec "$SERVICE_NAME" bash -c "echo SAVE | redis-cli" > /dev/null 2>&1
docker exec "$SERVICE_NAME" cat /data/dump.rdb
;;
$PLUGIN_COMMAND_PREFIX:import)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
SERVICE="$2"
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
SERVICE_NAME=$(get_service_name "$SERVICE")
dokku_log_fail "Not yet implemented"
if [[ -t 0 ]]; then
dokku_log_fail "No data provided on stdin."
fi
dokku "$PLUGIN_COMMAND_PREFIX:stop" "$SERVICE" > /dev/null 2>&1
docker run --rm -i -v "$SERVICE_ROOT/data:/data" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" bash -c "cat > /data/dump.rdb && chown redis: /data/dump.rdb"
dokku "$PLUGIN_COMMAND_PREFIX:start" "$SERVICE" > /dev/null 2>&1
;;
$PLUGIN_COMMAND_PREFIX:logs)
@@ -166,10 +174,14 @@ case "$1" in
$PLUGIN_COMMAND_PREFIX:clone)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
[[ -z $3 ]] && dokku_log_fail "Please specify a name for the new service"
verify_service_name "$2"
SERVICE="$2"
dokku_log_fail "Not yet implemented"
NEW_SERVICE="$3"
dokku "$PLUGIN_COMMAND_PREFIX:create" "$NEW_SERVICE"
dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
dokku "$PLUGIN_COMMAND_PREFIX:export" "$SERVICE" | dokku "$PLUGIN_COMMAND_PREFIX:import" "$NEW_SERVICE" > /dev/null 2>&1 || true
dokku_log_info1 "Done"
;;
$PLUGIN_COMMAND_PREFIX:expose)
@@ -191,14 +203,14 @@ case "$1" in
$PLUGIN_COMMAND_PREFIX:destroy <name>, Delete the $PLUGIN_SERVICE service and stop its container if there are no links left
$PLUGIN_COMMAND_PREFIX:link <name> <app>, Link the $PLUGIN_SERVICE service to the app
$PLUGIN_COMMAND_PREFIX:unlink <name> <app>, Unlink the $PLUGIN_SERVICE service from the app
$PLUGIN_COMMAND_PREFIX:export <name>, NOT IMPLEMENTED
$PLUGIN_COMMAND_PREFIX:import <name> <file>, NOT IMPLEMENTED
$PLUGIN_COMMAND_PREFIX:export <name>, Export a dump of the $PLUGIN_SERVICE service database
$PLUGIN_COMMAND_PREFIX:import <name> < <file>, Import a dump into the $PLUGIN_SERVICE service database
$PLUGIN_COMMAND_PREFIX:connect <name>, Connect via redis-cli to a $PLUGIN_SERVICE service
$PLUGIN_COMMAND_PREFIX:logs <name> [-t], Print the most recent log(s) for this service
$PLUGIN_COMMAND_PREFIX:restart <name>, Graceful shutdown and restart of the $PLUGIN_SERVICE service container
$PLUGIN_COMMAND_PREFIX:info <name>, Print the connection information
$PLUGIN_COMMAND_PREFIX:list, List all $PLUGIN_SERVICE services
$PLUGIN_COMMAND_PREFIX:clone <name> <new-name>, NOT IMPLEMENTED
$PLUGIN_COMMAND_PREFIX:clone <name> <new-name>, Create container <new-name> then copy data from <name> into <new-name>
$PLUGIN_COMMAND_PREFIX:expose <name> [port], Expose a $PLUGIN_SERVICE service on custom port if provided (random port otherwise)
$PLUGIN_COMMAND_PREFIX:unexpose <name>, Unexpose a previously exposed $PLUGIN_SERVICE service
$PLUGIN_COMMAND_PREFIX:start <name>, Start a previously stopped $PLUGIN_SERVICE service

42
tests/redis_clone.bats Executable file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env bats
load test_helper
setup() {
export ECHO_DOCKER_COMMAND="false"
dokku "$PLUGIN_COMMAND_PREFIX:create" l >&2
}
teardown() {
export ECHO_DOCKER_COMMAND="false"
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l >&2
}
@test "($PLUGIN_COMMAND_PREFIX:clone) error when there are no arguments" {
run dokku "$PLUGIN_COMMAND_PREFIX:clone"
assert_contains "${lines[*]}" "Please specify a name for the service"
}
@test "($PLUGIN_COMMAND_PREFIX:clone) error when service does not exist" {
run dokku "$PLUGIN_COMMAND_PREFIX:clone" not_existing_service new_service
assert_contains "${lines[*]}" "service not_existing_service does not exist"
}
@test "($PLUGIN_COMMAND_PREFIX:clone) error when new service isn't provided" {
run dokku "$PLUGIN_COMMAND_PREFIX:clone" l
assert_contains "${lines[*]}" "Please specify a name for the new service"
}
@test "($PLUGIN_COMMAND_PREFIX:clone) error when new service already exists" {
dokku "$PLUGIN_COMMAND_PREFIX:create" new_service
run dokku "$PLUGIN_COMMAND_PREFIX:clone" l new_service
assert_contains "${lines[*]}" "service new_service already exists"
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" new_service
}
@test "($PLUGIN_COMMAND_PREFIX:clone) success" {
run dokku "$PLUGIN_COMMAND_PREFIX:clone" l new_service
[[ -f $PLUGIN_DATA_ROOT/new_service/ID ]]
assert_contains "${lines[*]}" "Copying data from l to new_service"
assert_contains "${lines[*]}" "Done"
}

29
tests/redis_export.bats Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bats
load test_helper
setup() {
export ECHO_DOCKER_COMMAND="false"
dokku "$PLUGIN_COMMAND_PREFIX:create" l >&2
}
teardown() {
export ECHO_DOCKER_COMMAND="false"
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l >&2
}
@test "($PLUGIN_COMMAND_PREFIX:export) error when there are no arguments" {
run dokku "$PLUGIN_COMMAND_PREFIX:export"
assert_contains "${lines[*]}" "Please specify a name for the service"
}
@test "($PLUGIN_COMMAND_PREFIX:export) error when service does not exist" {
run dokku "$PLUGIN_COMMAND_PREFIX:export" not_existing_service
assert_contains "${lines[*]}" "service not_existing_service does not exist"
}
@test "($PLUGIN_COMMAND_PREFIX:export) success" {
export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:export" l
assert_output "docker exec dokku.redis.l cat /data/dump.rdb"
}

36
tests/redis_import.bats Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bats
load test_helper
setup() {
export ECHO_DOCKER_COMMAND="false"
dokku "$PLUGIN_COMMAND_PREFIX:create" l >&2
echo "data" > "$PLUGIN_DATA_ROOT/fake.rdb"
}
teardown() {
export ECHO_DOCKER_COMMAND="false"
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l >&2
rm -f "$PLUGIN_DATA_ROOT/fake.rdb"
}
@test "($PLUGIN_COMMAND_PREFIX:import) error when there are no arguments" {
run dokku "$PLUGIN_COMMAND_PREFIX:import"
assert_contains "${lines[*]}" "Please specify a name for the service"
}
@test "($PLUGIN_COMMAND_PREFIX:import) error when service does not exist" {
run dokku "$PLUGIN_COMMAND_PREFIX:import" not_existing_service
assert_contains "${lines[*]}" "service not_existing_service does not exist"
}
@test "($PLUGIN_COMMAND_PREFIX:import) error when data is not provided" {
run dokku "$PLUGIN_COMMAND_PREFIX:import" l
assert_contains "${lines[*]}" "No data provided on stdin"
}
@test "($PLUGIN_COMMAND_PREFIX:import) success" {
export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:import" l < "$PLUGIN_DATA_ROOT/fake.rdb"
assert_output "docker run --rm -i -v $PLUGIN_DATA_ROOT/l/data:/data redis:3.0.3 bash -c cat > /data/dump.rdb && chown redis: /data/dump.rdb"
}