Initial project setup with basic plugin structure
- Created plugin.toml with metadata - Added main command script - Implemented core functions - Added basic tests - Created README.md - Set up project structure
This commit is contained in:
79
README.md
Normal file
79
README.md
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# Dokku Docker Compose Plugin
|
||||||
|
|
||||||
|
A Dokku plugin for importing Docker Compose files into Dokku applications.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Import `docker-compose.yml` files into Dokku
|
||||||
|
- Map Compose services to Dokku apps
|
||||||
|
- Handle volumes, networks, and environment variables
|
||||||
|
- Support for Docker Compose v2 and v3 formats
|
||||||
|
- Integration with existing Dokku plugins
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# On your dokku server
|
||||||
|
sudo dokku plugin:install https://github.com/deanmarano/dokku-docker-compose.git docker-compose
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Import a Docker Compose file
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# In a directory containing docker-compose.yml
|
||||||
|
dokku docker-compose:import
|
||||||
|
|
||||||
|
# Or specify a custom compose file
|
||||||
|
dokku docker-compose:import -f docker-compose.prod.yml
|
||||||
|
|
||||||
|
# Dry run to see what will be created
|
||||||
|
dokku docker-compose:import --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Help
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Show help
|
||||||
|
dokku docker-compose:help
|
||||||
|
|
||||||
|
# Show version
|
||||||
|
dokku docker-compose:version
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- Bash 4.0+
|
||||||
|
- Dokku 0.30.0+
|
||||||
|
- Docker
|
||||||
|
- Docker Compose or Docker Compose Plugin
|
||||||
|
|
||||||
|
### Running Tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install test dependencies
|
||||||
|
bats_install="https://git.io/bats-install"
|
||||||
|
curl -sSL $bats_install | bash
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
bats tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
1. Fork the repository
|
||||||
|
2. Create a feature branch
|
||||||
|
3. Make your changes
|
||||||
|
4. Add tests
|
||||||
|
5. Submit a pull request
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
Dean Marano
|
||||||
71
commands/docker-compose
Executable file
71
commands/docker-compose
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Commands for the docker-compose plugin
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
|
# Import common functions
|
||||||
|
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
||||||
|
|
||||||
|
# Show help if no arguments are provided
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
cat <<EOF
|
||||||
|
Usage: dokku docker-compose:COMMAND
|
||||||
|
|
||||||
|
Import docker-compose.yml files into Dokku.
|
||||||
|
|
||||||
|
Additional commands:
|
||||||
|
dokku docker-compose:help Print this help message
|
||||||
|
dokku docker-compose:version Show version information
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
case "$1" in
|
||||||
|
help|--help|-h)
|
||||||
|
cat <<EOF
|
||||||
|
Usage: dokku docker-compose:COMMAND
|
||||||
|
|
||||||
|
Manage Docker Compose deployments in Dokku.
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
dokku docker-compose:import [path] Import a docker-compose.yml file
|
||||||
|
dokku docker-compose:help Show this help message
|
||||||
|
dokku docker-compose:version Show version information
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--file, -f Specify an alternate compose file (default: docker-compose.yml)
|
||||||
|
--project, -p Specify an alternate project name (default: directory name)
|
||||||
|
--dry-run Show what would be created without making changes
|
||||||
|
--verbose, -v Increase verbosity
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
# Import default docker-compose.yml in current directory
|
||||||
|
dokku docker-compose:import
|
||||||
|
|
||||||
|
# Import specific compose file
|
||||||
|
dokku docker-compose:import -f docker-compose.prod.yml
|
||||||
|
|
||||||
|
# Dry run to see what would be created
|
||||||
|
dokku docker-compose:import --dry-run
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
|
||||||
|
version|--version|-v)
|
||||||
|
echo "dokku-docker-compose version $(cat "$(dirname "$0")/../VERSION" 2>/dev/null || echo 'unknown')"
|
||||||
|
;;
|
||||||
|
|
||||||
|
import|--import)
|
||||||
|
shift
|
||||||
|
# Import logic will be implemented in the import command
|
||||||
|
echo "Import functionality coming soon!"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unknown command: $1"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# Dokku Docker Compose Plugin - Implementation Plan
|
# Dokku Docker Compose Plugin - Implementation Plan
|
||||||
|
|
||||||
## Phase 1: Project Setup
|
## Phase 1: Project Setup
|
||||||
- [ ] Initialize Git repository
|
- [x] Initialize Git repository
|
||||||
- [ ] Set up project structure
|
- [ ] Set up project structure
|
||||||
- [ ] Create basic plugin files
|
- [ ] Create basic plugin files
|
||||||
- [ ] `plugin.toml` - Plugin metadata
|
- [ ] `plugin.toml` - Plugin metadata
|
||||||
|
|||||||
207
functions/core
Executable file
207
functions/core
Executable file
@@ -0,0 +1,207 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Core functions for the docker-compose plugin
|
||||||
|
|
||||||
|
# Set strict mode
|
||||||
|
set -eo pipefail
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
|
# Import dokku functions
|
||||||
|
if [[ -f "/var/lib/dokku/core-plugins/available/common/functions" ]]; then
|
||||||
|
source /var/lib/dokku/core-plugins/available/common/functions
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Logging functions
|
||||||
|
log() {
|
||||||
|
echo "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
log " ! $*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
log " ! WARNING: $*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
[[ $QUIET ]] || log "-----> $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Version checking
|
||||||
|
check_dokku_version() {
|
||||||
|
local required_version="${1:-0.30.0}"
|
||||||
|
local current_version
|
||||||
|
current_version=$(dokku --version | head -n 1 | cut -d' ' -f3)
|
||||||
|
|
||||||
|
if [[ "$(printf "%s\n%s" "$required_version" "$current_version" | sort -V | head -n1)" != "$required_version" ]]; then
|
||||||
|
error "Dokku version $required_version or higher is required. Current version: $current_version"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Argument parsing
|
||||||
|
parse_args() {
|
||||||
|
local args=("$@")
|
||||||
|
local i=0
|
||||||
|
|
||||||
|
while [[ $i -lt ${#args[@]} ]]; do
|
||||||
|
case "${args[$i]}" in
|
||||||
|
-f|--file)
|
||||||
|
((i++))
|
||||||
|
COMPOSE_FILE="${args[$i]}"
|
||||||
|
;;
|
||||||
|
-p|--project)
|
||||||
|
((i++))
|
||||||
|
PROJECT_NAME="${args[$i]}"
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DRY_RUN=true
|
||||||
|
;;
|
||||||
|
-v|--verbose)
|
||||||
|
set -x
|
||||||
|
;;
|
||||||
|
-q|--quiet)
|
||||||
|
QUIET=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Handle non-flag arguments
|
||||||
|
if [[ -z "$COMMAND" ]]; then
|
||||||
|
COMMAND="${args[$i]}"
|
||||||
|
else
|
||||||
|
error "Unknown argument: ${args[$i]}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
((i++))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if a command exists
|
||||||
|
command_exists() {
|
||||||
|
command -v "$1" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if a file exists and is readable
|
||||||
|
file_exists() {
|
||||||
|
[[ -r "$1" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the project directory
|
||||||
|
get_project_dir() {
|
||||||
|
echo "${DOKKU_DOCKER_COMPOSE_PROJECT_DIR:-$(pwd)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the compose file path
|
||||||
|
get_compose_file() {
|
||||||
|
local project_dir="$(get_project_dir)"
|
||||||
|
echo "${COMPOSE_FILE:-${project_dir}/docker-compose.yml}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Validate compose file
|
||||||
|
validate_compose_file() {
|
||||||
|
local compose_file="$(get_compose_file)"
|
||||||
|
|
||||||
|
if ! file_exists "$compose_file"; then
|
||||||
|
error "Compose file not found: $compose_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if docker-compose or docker compose is available
|
||||||
|
if ! command_exists docker-compose && ! command_exists docker compose; then
|
||||||
|
error "Neither 'docker-compose' nor 'docker compose' command found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Validate compose file syntax
|
||||||
|
if command_exists docker-compose; then
|
||||||
|
docker-compose -f "$compose_file" config -q || error "Invalid compose file: $compose_file"
|
||||||
|
else
|
||||||
|
docker compose -f "$compose_file" config -q || error "Invalid compose file: $compose_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main entry point
|
||||||
|
main() {
|
||||||
|
# Ensure dokku is available
|
||||||
|
if ! command_exists dokku; then
|
||||||
|
error "Dokku is not installed or not in PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check dokku version
|
||||||
|
check_dokku_version "0.30.0"
|
||||||
|
|
||||||
|
# Parse arguments
|
||||||
|
parse_args "$@"
|
||||||
|
|
||||||
|
# Execute command
|
||||||
|
case "$COMMAND" in
|
||||||
|
help|--help|-h)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
version|--version|-v)
|
||||||
|
show_version
|
||||||
|
;;
|
||||||
|
import)
|
||||||
|
validate_compose_file
|
||||||
|
import_compose_file
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error "Unknown command: $COMMAND"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Import compose file (stub for now)
|
||||||
|
import_compose_file() {
|
||||||
|
local compose_file="$(get_compose_file)"
|
||||||
|
info "Importing compose file: $compose_file"
|
||||||
|
|
||||||
|
if [[ -n "$DRY_RUN" ]]; then
|
||||||
|
info "Dry run: Would import $compose_file"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Actual import logic will be implemented here
|
||||||
|
info "Import functionality coming soon!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
show_help() {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: dokku docker-compose:COMMAND [options]
|
||||||
|
|
||||||
|
Manage Docker Compose deployments in Dokku.
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
import [path] Import a docker-compose.yml file
|
||||||
|
help Show this help message
|
||||||
|
version Show version information
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
|
||||||
|
-p, --project NAME Specify an alternate project name (default: directory name)
|
||||||
|
--dry-run Show what would be created without making changes
|
||||||
|
-v, --verbose Increase verbosity
|
||||||
|
-q, --quiet Suppress output
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
# Import default docker-compose.yml in current directory
|
||||||
|
dokku docker-compose:import
|
||||||
|
|
||||||
|
# Import specific compose file
|
||||||
|
dokku docker-compose:import -f docker-compose.prod.yml
|
||||||
|
|
||||||
|
# Dry run to see what would be created
|
||||||
|
dokku docker-compose:import --dry-run
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show version
|
||||||
|
show_version() {
|
||||||
|
local version_file="$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/VERSION"
|
||||||
|
local version="$(cat "$version_file" 2>/dev/null || echo 'unknown')"
|
||||||
|
echo "dokku-docker-compose $version"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main function if this file is executed directly
|
||||||
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
20
plugin.toml
Normal file
20
plugin.toml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
[plugin]
|
||||||
|
# The name of the plugin
|
||||||
|
name = "docker-compose"
|
||||||
|
# The version of the plugin
|
||||||
|
version = "0.1.0"
|
||||||
|
# A short description of the plugin
|
||||||
|
description = "Import docker-compose.yml files into Dokku"
|
||||||
|
# The author of the plugin
|
||||||
|
author = "Dean Marano"
|
||||||
|
# The URL of the plugin's documentation
|
||||||
|
documentation = "https://github.com/deanmarano/dokku-docker-compose"
|
||||||
|
# The URL of the plugin's issue tracker
|
||||||
|
repository = "https://github.com/deanmarano/dokku-docker-compose/issues"
|
||||||
|
# The minimum Dokku version required
|
||||||
|
[dependencies]
|
||||||
|
core = ">= 0.30.0"
|
||||||
|
# Commands provided by this plugin
|
||||||
|
[commands]
|
||||||
|
# The main command that will be executed when running `dokku docker-compose`
|
||||||
|
docker-compose = "/var/lib/dokku/plugins/available/docker-compose/commands"
|
||||||
63
tests/docker-compose.bats
Executable file
63
tests/docker-compose.bats
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load 'test_helper/bats-support/load'
|
||||||
|
load 'test_helper/bats-assert/load'
|
||||||
|
load 'test_helper/bats-file/load'
|
||||||
|
|
||||||
|
# Set up test environment
|
||||||
|
setup() {
|
||||||
|
# Create a temporary directory for tests
|
||||||
|
TEST_DIR=$(mktemp -d)
|
||||||
|
cd "$TEST_DIR" || exit 1
|
||||||
|
|
||||||
|
# Create a simple docker-compose.yml for testing
|
||||||
|
cat > docker-compose.yml <<EOF
|
||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: nginx:alpine
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
db:
|
||||||
|
image: postgres:13
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: example
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clean up after tests
|
||||||
|
teardown() {
|
||||||
|
if [ -d "$TEST_DIR" ]; then
|
||||||
|
rm -rf "$TEST_DIR"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "plugin is installed" {
|
||||||
|
run dokku plugin:installed docker-compose
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "help command works" {
|
||||||
|
run dokku docker-compose:help
|
||||||
|
assert_success
|
||||||
|
assert_output --partial "Manage Docker Compose deployments in Dokku"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version command works" {
|
||||||
|
run dokku docker-compose:version
|
||||||
|
assert_success
|
||||||
|
assert_output --partial "dokku-docker-compose"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "import command with dry run" {
|
||||||
|
run dokku docker-compose:import --dry-run
|
||||||
|
assert_success
|
||||||
|
assert_output --partial "Dry run: Would import"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "fails with invalid compose file" {
|
||||||
|
echo "invalid yaml" > docker-compose.yml
|
||||||
|
run dokku docker-compose:import
|
||||||
|
assert_failure
|
||||||
|
assert_output --partial "Invalid compose file"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user