From 9bc3905d96d99b46c836ba8f369dbd712ae376aa Mon Sep 17 00:00:00 2001 From: Deploy Bot Date: Thu, 17 Jul 2025 19:20:59 -0400 Subject: [PATCH] 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 --- README.md | 79 +++++++++++++++ VERSION | 1 + commands/docker-compose | 71 +++++++++++++ docs/todo.md | 2 +- functions/core | 207 ++++++++++++++++++++++++++++++++++++++ plugin.toml | 20 ++++ tests/docker-compose.bats | 63 ++++++++++++ 7 files changed, 442 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 VERSION create mode 100755 commands/docker-compose create mode 100755 functions/core create mode 100644 plugin.toml create mode 100755 tests/docker-compose.bats diff --git a/README.md b/README.md new file mode 100644 index 0000000..53b4956 --- /dev/null +++ b/README.md @@ -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 diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/commands/docker-compose b/commands/docker-compose new file mode 100755 index 0000000..5f015a0 --- /dev/null +++ b/commands/docker-compose @@ -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 </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 diff --git a/docs/todo.md b/docs/todo.md index 2f9ebed..a2ba0d8 100644 --- a/docs/todo.md +++ b/docs/todo.md @@ -1,7 +1,7 @@ # Dokku Docker Compose Plugin - Implementation Plan ## Phase 1: Project Setup -- [ ] Initialize Git repository +- [x] Initialize Git repository - [ ] Set up project structure - [ ] Create basic plugin files - [ ] `plugin.toml` - Plugin metadata diff --git a/functions/core b/functions/core new file mode 100755 index 0000000..74c4f45 --- /dev/null +++ b/functions/core @@ -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 </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 diff --git a/plugin.toml b/plugin.toml new file mode 100644 index 0000000..1cb7a8c --- /dev/null +++ b/plugin.toml @@ -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" diff --git a/tests/docker-compose.bats b/tests/docker-compose.bats new file mode 100755 index 0000000..39514e6 --- /dev/null +++ b/tests/docker-compose.bats @@ -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 < docker-compose.yml + run dokku docker-compose:import + assert_failure + assert_output --partial "Invalid compose file" +}