chagall 0.0.1.beta7 → 0.0.1.beta9

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: 4f8df566c5608a68224f0cda8ee7ec4dc2ad6b9c3657476052271c033104ccc5
4
- data.tar.gz: fc9fdbd3a3c2035459d7239a9f245a030df45994bd7b1346dbed62a735014493
3
+ metadata.gz: 3b71d4dc675330a21d335828083d5df59f2185c162da6ff7f148cf892d5e1c02
4
+ data.tar.gz: e36708f4106e520c05b012ad217e730af13e641e6cbd60fab27dcd325ed2a05e
5
5
  SHA512:
6
- metadata.gz: 1cb86c45fe1af47f7c8791ed73025903ae5338ecfaee7b6b287c96b4959fa21670f5677cbc228715e4949603329601d0a8fe4fe2584d15090206830b526908ca
7
- data.tar.gz: 5b9cd2bb23766a47c6f1727dcd4a04d4c068fdbdeec942115adfa11aac01ac739b131c1314156f201db2a5868d24ae0ae396b1f9b41fa720f1e52f0691c6ddb4
6
+ metadata.gz: 29e65ddb06d27576d2783ec7ab77e580e15e55198cf57dced7df01e573b6c0280ed81017382708d68cfb32028aa1947dc6d7b752bc81917d3f0cdb9d835c62f8
7
+ data.tar.gz: 6ae10fbadb652749a53493cd42d3f997c446f5bcfdab8b8ac59c3df76cdc4b1b58f4de03d4b7577093e561840ff495902f712eb5cdb37cd2824d54000160682c
data/lib/chagall/base.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "logger"
2
2
  require_relative "ssh"
3
+ require_relative "settings"
3
4
 
4
5
  module Chagall
5
6
  class Base < Clamp::Command
@@ -14,6 +15,7 @@ module Chagall
14
15
 
15
16
  def logger
16
17
  @logger ||= Logger.new($stdout).tap do |l|
18
+ l.level = LOG_LEVELS[Chagall::Settings[:log_level]]
17
19
  l.formatter = proc do |severity, _, _, msg|
18
20
  if severity == "DEBUG"
19
21
  "[#{severity}] #{msg}\n"
@@ -21,13 +23,11 @@ module Chagall
21
23
  "#{msg}\n"
22
24
  end
23
25
  end
24
-
25
- l.level = LOG_LEVELS[ENV.fetch("LOG_LEVEL", "info")]
26
26
  end
27
27
  end
28
28
 
29
29
  def ssh
30
- @ssh ||= SSH.new(logger: logger)
30
+ @ssh ||= Chagall::Ssh.new(logger: logger)
31
31
  end
32
32
  end
33
33
  end
@@ -5,8 +5,6 @@ module Chagall
5
5
  class Compose < Base
6
6
  attr_reader :command, :arguments
7
7
 
8
-
9
- # Override parse method to handle all arguments after the subcommand
10
8
  def parse(arguments)
11
9
  if arguments.empty?
12
10
  puts "ERROR: Missing required arguments"
@@ -14,13 +12,10 @@ module Chagall
14
12
  exit(1)
15
13
  end
16
14
 
17
- # Extract the first argument as command
18
15
  @command = arguments.shift
19
16
 
20
- # Store the rest as raw args
21
17
  @raw_args = arguments
22
18
 
23
- # Validate required arguments
24
19
  if @command.nil? || @command.empty?
25
20
  puts "ERROR: Command is required"
26
21
  puts "Usage: chagall compose COMMAND [OPTIONS]"
@@ -32,7 +27,6 @@ module Chagall
32
27
  cmd = "cd #{Settings.instance.project_folder_path} && #{build_docker_compose_command} #{@command}"
33
28
  cmd << " #{@raw_args.join(" ")}" unless @raw_args.empty?
34
29
 
35
- logger.debug "Executing: #{cmd}"
36
30
  ssh.execute(cmd, tty: true)
37
31
  end
38
32
 
@@ -13,14 +13,15 @@ module Chagall
13
13
  @interrupted = false
14
14
  @total_time = 0.0
15
15
  setup_signal_handlers
16
- Time.now
16
+
17
+ # binding.irb
17
18
 
18
19
  t("Checking uncommitted changes") { check_uncommit_changes } unless Settings[:skip_uncommit]
19
20
  t("Check image or build") { check_image_or_build }
20
- t("tag as production") { tag_as_production }
21
- t("update compose files") { update_compose_files }
22
- t("deploy compose files") { deploy_compose_files }
23
- t("rotate release") { rotate_releases }
21
+ t("Tag as production") { tag_as_production }
22
+ t("Update compose files") { update_compose_files }
23
+ t("Deploy compose files") { deploy_compose_files }
24
+ t("Rotate release") { rotate_releases }
24
25
 
25
26
  print_total_time
26
27
  rescue Interrupt
@@ -78,8 +79,17 @@ module Chagall
78
79
 
79
80
  private
80
81
 
82
+ def format_time(seconds)
83
+ minutes, secs = seconds.abs.divmod(60)
84
+ hours, mins = minutes.divmod(60)
85
+ [ [ hours, "h" ], [ mins, "m" ], [ secs.round(2), "s" ] ]
86
+ .reject { |n, _| n.zero? && !(_=="s") }
87
+ .map { |n, u| "#{n}#{u}" }
88
+ .join(" ")
89
+ end
90
+
81
91
  def print_total_time
82
- logger.info "Total execution time: #{format('%.2f', @total_time)}s"
92
+ logger.info "Total execution time: #{format_time(@total_time)}"
83
93
  end
84
94
 
85
95
  def t(title)
@@ -171,9 +181,9 @@ module Chagall
171
181
  args.push(Settings[:docker_context])
172
182
 
173
183
  args = args.map { |arg| " #{arg}" }
174
- .join(" \\\n")
184
+ .join(" \\\n")
175
185
 
176
- cmd = "docker build \\\n#{args}"
186
+ cmd = "docker buildx build \\\n#{args}"
177
187
  if Settings[:remote]
178
188
  ssh.command(cmd)
179
189
  else
@@ -194,7 +204,6 @@ module Chagall
194
204
  logger.debug "Updating compose services..."
195
205
  deploy_command = [ "docker compose" ]
196
206
 
197
- # Use the remote file paths for docker compose command
198
207
  Settings[:compose_files].each do |file|
199
208
  deploy_command << "-f #{File.basename(file)}"
200
209
  end
@@ -216,10 +225,8 @@ module Chagall
216
225
  release_folder = "#{Settings.instance.project_folder_path}/releases"
217
226
  release_file = "#{release_folder}/#{Settings[:release]}"
218
227
 
219
- # Create releases directory if it doesn't exist
220
228
  ssh.execute("mkdir -p #{release_folder}")
221
229
 
222
- # Save current release
223
230
  ssh.execute("touch #{release_file}")
224
231
 
225
232
  # Get list of releases sorted by modification time (newest first)
@@ -249,9 +256,5 @@ module Chagall
249
256
 
250
257
  result
251
258
  end
252
-
253
- def ssh
254
- @ssh ||= SSH.new
255
- end
256
259
  end
257
260
  end
@@ -9,16 +9,15 @@ module Chagall
9
9
 
10
10
  attr_accessor :options, :missing_options, :missing_compose_files
11
11
  CHAGALL_PROJECTS_FOLDER = "~/projects"
12
- TMP_CACHE_FOLDER = "tmp"
13
12
 
14
13
  OPTIONS = [
15
14
  {
16
- key: :debug,
17
- flags: [ "--debug" ],
18
- description: "Debug mode with pry attaching",
19
- type: :boolean,
20
- default: false,
21
- environment_variable: "CHAGALL_DEBUG"
15
+ key: :log_level,
16
+ flags: [ "--log-level" ],
17
+ description: "Log level",
18
+ type: :string,
19
+ default: "info",
20
+ environment_variable: "CHAGALL_LOG_LEVEL"
22
21
  },
23
22
  {
24
23
  key: :skip_uncommit,
@@ -105,7 +104,7 @@ module Chagall
105
104
  {
106
105
  key: :cache_from,
107
106
  type: :string,
108
- default: "#{TMP_CACHE_FOLDER}/.buildx-cache",
107
+ default: "tmp/.buildx-cache",
109
108
  flags: [ "--cache-from" ],
110
109
  environment_variable: "CHAGALL_CACHE_FROM",
111
110
  description: "Cache from"
@@ -113,7 +112,7 @@ module Chagall
113
112
  {
114
113
  key: :cache_to,
115
114
  type: :string,
116
- default: "#{TMP_CACHE_FOLDER}/.buildx-cache-new",
115
+ default: "tmp/.buildx-cache-new",
117
116
  flags: [ "--cache-to" ],
118
117
  environment_variable: "CHAGALL_CACHE_TO",
119
118
  description: "Cache to"
@@ -201,23 +200,6 @@ module Chagall
201
200
  raise Chagall::SettingsError, error_message_string unless @options[:dry_run]
202
201
  end
203
202
 
204
- def options_from_config_file
205
- @options_from_config_file ||= begin
206
- config_path = File.join(Dir.pwd, "chagall.yml") || File.join(Dir.pwd, "chagall.yaml")
207
- return {} unless File.exist?(config_path)
208
-
209
- config = YAML.load_file(config_path)
210
- config.transform_keys(&:to_sym)
211
- rescue StandardError => e
212
- puts "Warning: Error loading chagall.yml: #{e.message}"
213
- {}
214
- end
215
- end
216
-
217
- def true?(value)
218
- value.to_s.strip.downcase == "true"
219
- end
220
-
221
203
  def image_tag
222
204
  @image_tag ||= "#{options[:name]}:#{options[:release]}"
223
205
  end
data/lib/chagall/setup.rb CHANGED
@@ -34,7 +34,6 @@ module Chagall
34
34
  end
35
35
 
36
36
  def unable_to_access_docker_deamon?
37
- return true
38
37
  docker_result = ssh.command("docker ps")
39
38
  docker_output = `#{docker_result} 2>&1`.strip
40
39
  logger.debug "Docker output: #{docker_output}"
@@ -72,8 +71,11 @@ module Chagall
72
71
  compose_output = `#{ssh.command("docker compose version")} 2>&1`.strip
73
72
  logger.debug "Docker Compose output: '#{compose_output}'"
74
73
 
75
- return true if docker_output.include?("Docker version") &&
76
- compose_output.include?("Docker Compose version")
74
+ if docker_output.downcase.include?("docker version") &&
75
+ compose_output.downcase.include?("docker compose version")
76
+ logger.info "Docker and Docker Compose installed"
77
+ return true
78
+ end
77
79
 
78
80
  logger.warn "Docker check failed:"
79
81
  logger.warn "Docker output: #{docker_output}"
data/lib/chagall/ssh.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require "English"
2
2
 
3
3
  module Chagall
4
- class SSH
4
+ class Ssh
5
5
  attr_reader :server, :ssh_args, :logger
6
6
 
7
7
  DEFAULT_SSH_ARGS = "-o StrictHostKeyChecking=no -o ServerAliveInterval=60".freeze
8
8
 
9
- def initialize(server: Settings.instance.options[:server], ssh_args: DEFAULT_SSH_ARGS, logger: Logger.new($stdout))
9
+ def initialize(server: Settings.instance.options[:server], ssh_args: DEFAULT_SSH_ARGS, logger:)
10
10
  @server = server
11
11
  @ssh_args = ssh_args
12
12
  @logger = logger
@@ -14,7 +14,7 @@ module Chagall
14
14
 
15
15
  def execute(command, directory: nil, tty: false)
16
16
  cmd = build_command(command, directory, tty)
17
- logger.debug "SSH: #{cmd}"
17
+ logger.debug "SSH: #{cmd}" if logger.debug?
18
18
  system(cmd)
19
19
  $CHILD_STATUS.success?
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module Chagall
2
- VERSION = "0.0.1.beta7"
2
+ VERSION = "0.0.1.beta9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chagall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta7
4
+ version: 0.0.1.beta9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Klevtsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-10 00:00:00.000000000 Z
11
+ date: 2025-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp