Initial commit: Dokku Docker Compose plugin with test infrastructure

This commit is contained in:
Deploy Bot
2025-07-17 20:24:03 -04:00
parent b15de9a244
commit d2a42455a1
19 changed files with 1206 additions and 64 deletions

48
tests/deploy.bats Executable file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
setup() {
# Set up test app with unique name
export TEST_APP="nodeapp-$(date +%s)"
export TEST_DIR="/tmp/${TEST_APP}"
# Create test app
mkdir -p "${TEST_DIR}"
cp -r tests/test-apps/simple-nodejs/* "${TEST_DIR}/"
# Initialize git repo
cd "${TEST_DIR}" || exit 1
git init
git config user.name "Test User"
git config user.email "test@example.com"
git add .
git commit -m "Initial commit"
# Create Dokku app
ssh -T dokku-test "apps:create ${TEST_APP}"
}
teardown() {
# Clean up
cd /tmp || true
rm -rf "${TEST_DIR}" || true
ssh -T dokku-test "--force apps:destroy ${TEST_APP}" || true
}
@test "can deploy a Node.js app" {
# Add Dokku remote
cd "${TEST_DIR}" || exit 1
git remote add dokku "dokku@localhost:${TEST_APP}"
# Push to Dokku
run git push dokku main:master
assert_success
# Verify app is running
sleep 5 # Give it time to start
run curl -s "http://localhost:8080"
assert_success
assert_output --partial "Hello from Node.js app!"
}

67
tests/integration.bats Executable file
View File

@@ -0,0 +1,67 @@
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
# Helper function to run dokku commands
run_dokku() {
ssh -T dokku-test "$@"
}
setup() {
# Set up test app with unique name
export TEST_APP="testapp-$(date +%s)"
export TEST_DB="${TEST_APP}-db"
export TEST_REDIS="${TEST_APP}-redis"
# Create test app
run_dokku "apps:create $TEST_APP"
}
teardown() {
# Clean up
run_dokku "--force apps:destroy $TEST_APP" || true
run_dokku "postgres:destroy --force $TEST_DB" || true
run_dokku "redis:destroy --force $TEST_REDIS" || true
}
@test "can create and deploy a simple app" {
# Test app was created
run run_dokku "apps:exists $TEST_APP"
assert_success
# Test app is listed
run run_dokku "apps:list"
assert_success
assert_output --partial "$TEST_APP"
}
@test "can create and link postgres service" {
# Create postgres service
run run_dokku "postgres:create $TEST_DB"
assert_success
# Link service to app
run run_dokku "postgres:link $TEST_DB $TEST_APP"
assert_success
# Verify link exists
run run_dokku "postgres:info $TEST_DB --do-export"
assert_success
assert_output --partial "$TEST_APP"
}
@test "can create and link redis service" {
# Create redis service
run run_dokku "redis:create $TEST_REDIS"
assert_success
# Link service to app
run run_dokku "redis:link $TEST_REDIS $TEST_APP"
assert_success
# Verify link exists
run run_dokku "redis:info $TEST_REDIS --do-export"
assert_success
assert_output --partial "$TEST_APP"
}

98
tests/parser.bats Normal file → Executable file
View File

@@ -75,6 +75,20 @@ load 'test_helper/bats-file/load'
assert_success
[[ "${#lines[@]}" -eq 1 ]]
[[ "${lines[0]}" == "rw" ]] # Only one line with the default mode
# Test with special characters in volume paths
run parse_volume "/host/path/with spaces:/container/path:ro"
assert_success
[[ "${lines[0]}" == "/host/path/with spaces" ]]
[[ "${lines[1]}" == "/container/path" ]]
[[ "${lines[2]}" == "ro" ]]
# Test with relative paths
run parse_volume "./relative/path:/absolute/path"
assert_success
[[ "${lines[0]}" == "./relative/path" ]]
[[ "${lines[1]}" == "/absolute/path" ]]
[[ "${lines[2]}" == "rw" ]]
}
@test "get_dokku_app_name should convert service name correctly" {
@@ -104,37 +118,81 @@ load 'test_helper/bats-file/load'
should_use_dokku_plugin() {
local image="$1"
# List of known plugins
local known_plugins=(
"postgres"
"mysql"
"redis"
"mongodb"
"memcached"
"rabbitmq"
"elasticsearch"
)
# Check if image matches any known plugin
for plugin in "${known_plugins[@]}"; do
if [[ "$image" == *"$plugin"* ]]; then
echo "$plugin"
return 0
fi
done
return 1
# Simple implementation for testing
case "$image" in
*postgres*) echo "postgres" ; return 0 ;;
*redis*) echo "redis" ; return 0 ;;
*) return 1 ;;
esac
}
# Test with official images
echo "Testing with postgres:13"
run should_use_dokku_plugin "postgres:13"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with custom image names (should fail as no known plugin matches)
echo "Testing with custom-image"
run should_use_dokku_plugin "custom-image"
echo "Status: $status, Output: $output"
assert_failure
# Test with custom/redis (should work as it contains 'redis')
echo "Testing with custom/redis:latest"
run should_use_dokku_plugin "custom/redis:latest"
echo "Status: $status, Output: $output"
assert_success
assert_output "redis"
# Test with Docker Hub official images (should work as it contains 'postgres')
echo "Testing with library/postgres:13"
run should_use_dokku_plugin "library/postgres:13"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with Docker Hub official images with registry (should work as it contains 'postgres')
echo "Testing with docker.io/library/postgres:13"
run should_use_dokku_plugin "docker.io/library/postgres:13"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with private registry (should work as it contains 'postgres')
echo "Testing with myregistry.example.com/postgres:13"
run should_use_dokku_plugin "myregistry.example.com/postgres:13"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with custom repository path (should work as it contains 'postgres')
echo "Testing with myorg/postgres:13"
run should_use_dokku_plugin "myorg/postgres:13"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with latest tag
echo "Testing with postgres:latest"
run should_use_dokku_plugin "postgres:latest"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with no tag
echo "Testing with postgres"
run should_use_dokku_plugin "postgres"
echo "Status: $status, Output: $output"
assert_success
assert_output "postgres"
# Test with custom/unknown (should fail as no known plugin matches)
echo "Testing with custom/unknown:latest"
run should_use_dokku_plugin "custom/unknown:latest"
echo "Status: $status, Output: $output"
assert_failure
}

44
tests/setup-dokku.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
set -e
# Install dependencies
apt-get update
apt-get install -y ssh-client netcat
# Wait for Dokku to be ready
echo "Waiting for Dokku to be ready..."
until nc -z localhost 2222; do
sleep 1
done
# Generate SSH key if it doesn't exist
if [ ! -f ~/.ssh/id_rsa ]; then
mkdir -p ~/.ssh
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/*
fi
# Configure SSH
eval "$(ssh-agent -s)"
ssh-keyscan -p 2222 -t rsa localhost >> ~/.ssh/known_hosts
# Create SSH config
cat > ~/.ssh/config << 'EOL'
Host dokku-test
HostName localhost
Port 2222
User root
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
IdentityFile ~/.ssh/id_rsa
EOL
# Install required plugins
echo "Installing Dokku plugins..."
ssh -T dokku-test "\
dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres && \
dokku plugin:install https://github.com/dokku/dokku-redis.git redis && \
dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql"
echo "Dokku test environment is ready!"

View File

@@ -0,0 +1,12 @@
{
"name": "simple-nodejs",
"version": "1.0.0",
"description": "A simple Node.js app for testing",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1"
}
}

View File

@@ -0,0 +1,10 @@
const express = require('express');
const app = express();
const PORT = process.env.PORT || 5000;
app.get('/', (req, res) => {
res.send('Hello from Node.js app!');});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});

Submodule tests/test_helper/bats-assert added at 912a98804e

Submodule tests/test_helper/bats-file added at 0f24d00470

Submodule tests/test_helper/bats-support added at 0ad082d459