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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8a737bf93543b1c7af2206ec1a49c80e7d9b4fce5f7757f4d2c948c6ec46335
4
- data.tar.gz: 3a4c510e4302ec0965c55cdadedeb9b003cbb491471ac6a9de45009137ad6644
3
+ metadata.gz: 91b395df4575048270a328aecfc8a2d8c96822aebcba96abac36bd9309d05704
4
+ data.tar.gz: bbeb1373a770b5156235cb1ee695157a5d7317f50ff9c116d6dad7156c8bddd1
5
5
  SHA512:
6
- metadata.gz: '0932bdebb821c1f1374e7a64bb677699c31a2fa10b9c7a892463885ababcbe7634acfb6701393c3ab4c8d4c9e521bd9d16b6c00417c639b4f817d55491d2559f'
7
- data.tar.gz: 982a66fe42eae19dc9b8cf08119e763a8f3c1b91b75b2d7d63e583484e8ec06296ada37445cddc5712710463268e82ba533bae65cc430aa312c8856a7630f26e
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
- setup_container(
25
- name: config.database.name || "db-app",
26
- port: config.database.port || 5432,
27
- image: "postgres:#{config.database.version || "14"}",
28
- env: {"POSTGRES_PASSWORD" => config.database.password || "postgres"},
29
- volume: "#{config.database.name || "db-app"}:/var/lib/postgresql/data",
30
- internal_port: 5432
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
- system_quiet("which docker") && (
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
@@ -1,3 +1,3 @@
1
1
  module Discharger
2
- VERSION = "0.2.16"
2
+ VERSION = "0.2.17"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discharger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay