discharger 0.2.16 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/lib/discharger/setup_runner/commands/docker_command.rb +89 -21
- data/lib/discharger/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 91b395df4575048270a328aecfc8a2d8c96822aebcba96abac36bd9309d05704
         | 
| 4 | 
            +
              data.tar.gz: bbeb1373a770b5156235cb1ee695157a5d7317f50ff9c116d6dad7156c8bddd1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e8439d2b4ab107c1565580868d13722783848cec3c96d14d890227b56488541e0d4476ea335719caf7adffc083424bf157bb8211b93a98f810d3e2ed0aa2c70b
         | 
| 7 | 
            +
              data.tar.gz: 1d8a6167062761e9ec86e05b9aa784d4745f587c2aa63706efe19dc8ced530621af2b0b0ea03daaa7d1ef311ce8003522dbf4877cf25504ceca4da19f6ea50bf
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -5,4 +5,6 @@ All notable changes to this project will be documented in this file. | |
| 5 5 | 
             
            The format is based on [Keep a Changelog](http://keepachangelog.com/)
         | 
| 6 6 | 
             
            and this project adheres to [Semantic Versioning](http://semver.org/).
         | 
| 7 7 |  | 
| 8 | 
            +
            ## [0.2.17] - 2025-10-27
         | 
| 9 | 
            +
             | 
| 8 10 | 
             
            ## [0.2.16] - 2025-10-24
         | 
| @@ -7,28 +7,22 @@ module Discharger | |
| 7 7 | 
             
                module Commands
         | 
| 8 8 | 
             
                  class DockerCommand < BaseCommand
         | 
| 9 9 | 
             
                    def execute
         | 
| 10 | 
            -
                      log "Ensure Docker is running"
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                      unless system_quiet("docker info > /dev/null 2>&1")
         | 
| 13 | 
            -
                        log "Starting Docker..."
         | 
| 14 | 
            -
                        system_quiet("open -a Docker")
         | 
| 15 | 
            -
                        sleep 10
         | 
| 16 | 
            -
                        unless system_quiet("docker info > /dev/null 2>&1")
         | 
| 17 | 
            -
                          log "Docker is not running. Please start Docker manually."
         | 
| 18 | 
            -
                          return
         | 
| 19 | 
            -
                        end
         | 
| 20 | 
            -
                      end
         | 
| 21 | 
            -
             | 
| 22 10 | 
             
                      # Setup database container if configured
         | 
| 23 11 | 
             
                      if config.respond_to?(:database) && config.database
         | 
| 24 | 
            -
                         | 
| 25 | 
            -
                           | 
| 26 | 
            -
                           | 
| 27 | 
            -
             | 
| 28 | 
            -
                           | 
| 29 | 
            -
                           | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 12 | 
            +
                        if native_postgresql_available?
         | 
| 13 | 
            +
                          log "Native PostgreSQL detected on port #{native_postgresql_port}, skipping Docker container setup"
         | 
| 14 | 
            +
                          ENV["DB_PORT"] ||= native_postgresql_port.to_s
         | 
| 15 | 
            +
                        else
         | 
| 16 | 
            +
                          ensure_docker_running
         | 
| 17 | 
            +
                          setup_container(
         | 
| 18 | 
            +
                            name: config.database.name || "db-app",
         | 
| 19 | 
            +
                            port: config.database.port || 5432,
         | 
| 20 | 
            +
                            image: "postgres:#{config.database.version || "14"}",
         | 
| 21 | 
            +
                            env: {"POSTGRES_PASSWORD" => config.database.password || "postgres"},
         | 
| 22 | 
            +
                            volume: "#{config.database.name || "db-app"}:/var/lib/postgresql/data",
         | 
| 23 | 
            +
                            internal_port: 5432
         | 
| 24 | 
            +
                          )
         | 
| 25 | 
            +
                        end
         | 
| 32 26 | 
             
                      end
         | 
| 33 27 |  | 
| 34 28 | 
             
                      # Setup Redis container if configured
         | 
| @@ -44,7 +38,7 @@ module Discharger | |
| 44 38 |  | 
| 45 39 | 
             
                    def can_execute?
         | 
| 46 40 | 
             
                      # Only execute if Docker is available and containers are configured
         | 
| 47 | 
            -
                       | 
| 41 | 
            +
                      docker_available? && (
         | 
| 48 42 | 
             
                        (config.respond_to?(:database) && config.database) ||
         | 
| 49 43 | 
             
                        (config.respond_to?(:redis) && config.redis)
         | 
| 50 44 | 
             
                      )
         | 
| @@ -94,6 +88,80 @@ module Discharger | |
| 94 88 |  | 
| 95 89 | 
             
                      system!(*cmd)
         | 
| 96 90 | 
             
                    end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                    def docker_available?
         | 
| 93 | 
            +
                      return true if system_quiet("which docker > /dev/null 2>&1")
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                      ["/usr/bin/docker", "/usr/local/bin/docker"].each do |path|
         | 
| 96 | 
            +
                        return true if File.executable?(path)
         | 
| 97 | 
            +
                      end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                      false
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                    def docker_running?
         | 
| 103 | 
            +
                      system_quiet("docker info > /dev/null 2>&1")
         | 
| 104 | 
            +
                    end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                    def start_docker_for_platform
         | 
| 107 | 
            +
                      case RUBY_PLATFORM
         | 
| 108 | 
            +
                      when /darwin/
         | 
| 109 | 
            +
                        system_quiet("open -a Docker")
         | 
| 110 | 
            +
                      when /linux/
         | 
| 111 | 
            +
                        if system_quiet("which systemctl > /dev/null 2>&1")
         | 
| 112 | 
            +
                          log "Attempting to start Docker service..."
         | 
| 113 | 
            +
                          system_quiet("sudo systemctl start docker")
         | 
| 114 | 
            +
                        else
         | 
| 115 | 
            +
                          log "Docker service management not available. Please ensure Docker is running."
         | 
| 116 | 
            +
                        end
         | 
| 117 | 
            +
                      else
         | 
| 118 | 
            +
                        log "Unsupported platform for automatic Docker startup: #{RUBY_PLATFORM}"
         | 
| 119 | 
            +
                      end
         | 
| 120 | 
            +
                    end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                    def ensure_docker_running
         | 
| 123 | 
            +
                      log "Ensure Docker is running"
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                      unless docker_running?
         | 
| 126 | 
            +
                        log "Starting Docker..."
         | 
| 127 | 
            +
                        start_docker_for_platform
         | 
| 128 | 
            +
                        sleep 10
         | 
| 129 | 
            +
                        unless docker_running?
         | 
| 130 | 
            +
                          log "Docker is not running. Please start Docker manually."
         | 
| 131 | 
            +
                          return false
         | 
| 132 | 
            +
                        end
         | 
| 133 | 
            +
                      end
         | 
| 134 | 
            +
                      true
         | 
| 135 | 
            +
                    end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                    def native_postgresql_available?
         | 
| 138 | 
            +
                      # Check common PostgreSQL ports
         | 
| 139 | 
            +
                      [5432, 5433].each do |port|
         | 
| 140 | 
            +
                        if postgresql_running_on_port?(port)
         | 
| 141 | 
            +
                          @native_pg_port = port
         | 
| 142 | 
            +
                          return true
         | 
| 143 | 
            +
                        end
         | 
| 144 | 
            +
                      end
         | 
| 145 | 
            +
                      false
         | 
| 146 | 
            +
                    end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                    def native_postgresql_port
         | 
| 149 | 
            +
                      @native_pg_port || 5432
         | 
| 150 | 
            +
                    end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                    def postgresql_running_on_port?(port)
         | 
| 153 | 
            +
                      # Method 1: Try pg_isready if available
         | 
| 154 | 
            +
                      if system_quiet("which pg_isready > /dev/null 2>&1")
         | 
| 155 | 
            +
                        return system_quiet("pg_isready -h localhost -p #{port} > /dev/null 2>&1")
         | 
| 156 | 
            +
                      end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                      # Method 2: Try psql connection
         | 
| 159 | 
            +
                      if system_quiet("which psql > /dev/null 2>&1")
         | 
| 160 | 
            +
                        return system_quiet("psql -h localhost -p #{port} -U postgres -c '\\q' > /dev/null 2>&1")
         | 
| 161 | 
            +
                      end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                      false
         | 
| 164 | 
            +
                    end
         | 
| 97 165 | 
             
                  end
         | 
| 98 166 | 
             
                end
         | 
| 99 167 | 
             
              end
         | 
    
        data/lib/discharger/version.rb
    CHANGED