diff --git a/Gemfile.lock b/Gemfile.lock index 5783d00..b0e4ba9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - neptuno (1.2.3) + neptuno (1.3.0) dotiw dry-cli hirb @@ -17,7 +17,7 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (7.0.4.2) + activesupport (7.0.7.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -32,7 +32,7 @@ GEM i18n dry-cli (1.0.0) hirb (0.7.3) - i18n (1.12.0) + i18n (1.14.1) concurrent-ruby (~> 1.0) json (2.6.2) minitest (5.16.3) @@ -94,7 +94,7 @@ GEM concurrent-ruby (~> 1.0) unicode-display_width (2.3.0) wisper (2.0.1) - zeitwerk (2.6.7) + zeitwerk (2.6.11) PLATFORMS x86_64-darwin-21 diff --git a/lib/neptuno/docker/build.rb b/lib/neptuno/docker/build.rb index f347116..b29f44b 100644 --- a/lib/neptuno/docker/build.rb +++ b/lib/neptuno/docker/build.rb @@ -8,18 +8,30 @@ class Build < Neptuno::CLI::Base option :all, type: :boolean, default: false, desc: 'Run on all services' argument :services, type: :array, required: false, desc: 'Optional list of services' + option :options, required: false, desc: 'Optional string of options passed to build' def call(services: [], **options) command_services_to('build', all: options.fetch(:all), services_as_args: services) do |services| make_service_files(services) + opts = options.fetch(:options, nil) || get_gpr services.each do |service| puts '********************' puts "building #{service}" puts '********************' - system("cd #{neptuno_path} && docker compose build #{service}") + system("cd #{neptuno_path} && docker compose build #{opts} #{service}") end end end + + def get_gpr + begin + lines = File.readlines("#{Dir.home}/.bundle/config") + rescue Errno::ENOENT + return + end + gpr = lines&.select { |line| line[/BUNDLE_RUBYGEMS__PKG__GITHUB__COM/] }&.last&.split(' ')&.last + "--build-arg gpr=#{gpr}".gsub('\"', '') if gpr + end end end end diff --git a/lib/neptuno/docker/down.rb b/lib/neptuno/docker/down.rb index ea39511..ee169be 100644 --- a/lib/neptuno/docker/down.rb +++ b/lib/neptuno/docker/down.rb @@ -4,18 +4,18 @@ module Neptuno module Docker # Stop docker containers for Neptuno project class Down < Neptuno::CLI::Base - desc "Docker: Stop docker containers for current project" + desc 'Docker: Stop docker containers for current project' - option :all, type: :boolean, default: false, desc: "Run on all services" - argument :services, type: :array, required: false, desc: "Optional list of services" + option :all, type: :boolean, default: false, desc: 'Run on all services' + argument :services, type: :array, required: false, desc: 'Optional list of services' def call(services: [], **options) - command_services_to("go down", all: options.fetch(:all), services_as_args: services) do |services| + command_services_to('go down', all: options.fetch(:all), services_as_args: services) do |services| make_service_files(services) services_to_stop = services.intersection(services_with_procs).intersection(running_services) - system("cd #{neptuno_path} && docker compose stop -t 0 #{services.join(" ")}") - system("cd #{neptuno_path} && docker compose rm -f #{services.join(" ")}") - if config.fetch("procfile_manager") == "tmux" + system("cd #{neptuno_path} && docker compose stop -t 0 #{services.join(' ')}") + system("cd #{neptuno_path} && docker compose rm -f #{services.join(' ')}") + if config.fetch('procfile_manager') == 'tmux' services_to_stop.each do |service| system("tmux kill-session -t #{service} 2>/dev/null ") puts "Neptuno killed Tmux session for: #{service}" if `echo $TMUX`.strip.empty? diff --git a/lib/neptuno/docker/restart.rb b/lib/neptuno/docker/restart.rb index 368dd5c..65a4b83 100644 --- a/lib/neptuno/docker/restart.rb +++ b/lib/neptuno/docker/restart.rb @@ -4,20 +4,32 @@ module Neptuno module Docker # Restart docker containers for Neptuno project class Restart < Neptuno::CLI::Base - desc "Docker: Rebuild and restart docker containers for current project" + desc 'Docker: Rebuild and restart docker containers for current project' - option :all, type: :boolean, default: false, desc: "Run on all services" - argument :services, type: :array, required: false, desc: "Optional list of services" + option :all, type: :boolean, default: false, desc: 'Run on all services' + argument :services, type: :array, required: false, desc: 'Optional list of services' + option :options, required: false, desc: 'Optional string of options passed to build' def call(services: [], **options) - command_services_to("restart", all: options.fetch(:all), services_as_args: services) do |services| + command_services_to('restart', all: options.fetch(:all), services_as_args: services) do |services| make_service_files(services) - system("cd #{neptuno_path} && docker compose stop -t 0 #{services.join(" ")}") - system("cd #{neptuno_path} && docker compose rm -f #{services.join(" ")}") - system("cd #{neptuno_path} && docker compose build #{services.join(" ")}") - system("cd #{neptuno_path} && docker compose up -d #{services.join(" ")}") + opts = options.fetch(:options, nil) || get_gpr + system("cd #{neptuno_path} && docker compose stop -t 0 #{services.join(' ')}") + system("cd #{neptuno_path} && docker compose rm -f #{services.join(' ')}") + system("cd #{neptuno_path} && docker compose build #{opts} #{services.join(' ')}") + system("cd #{neptuno_path} && docker compose up -d #{services.join(' ')}") end end + + def get_gpr + begin + lines = File.readlines("#{Dir.home}/.bundle/config") + rescue Errno::ENOENT + return + end + gpr = lines&.select { |line| line[/BUNDLE_RUBYGEMS__PKG__GITHUB__COM/] }&.last&.split(' ')&.last + "--build-arg gpr=#{gpr}".gsub('\"', '') if gpr + end end end end diff --git a/lib/neptuno/services/update.rb b/lib/neptuno/services/update.rb index db90def..0c3f96a 100644 --- a/lib/neptuno/services/update.rb +++ b/lib/neptuno/services/update.rb @@ -4,32 +4,32 @@ module Neptuno module Services # Update project to to latest GH master/main class Update < Neptuno::CLI::Base - desc "Stashes changes and pulls latest from main/master" + desc 'Stashes changes and pulls latest from main/master' - option :all, type: :boolean, default: false, desc: "Run on all services" + option :all, type: :boolean, default: false, desc: 'Run on all services' option :main, type: :boolean, default: false, - desc: "Keep service on main/master after pull. Uncommited changes are stashed as 'neptuno_stash'" - argument :services, type: :array, required: false, desc: "Optional list of services" + desc: "Keep service on main/master after pull. Uncommited changes are stashed as 'neptuno_stash'" + argument :services, type: :array, required: false, desc: 'Optional list of services' def call(services: [], **options) - command_services_to("update", all: options.fetch(:all), services_as_args: services) do |services| + command_services_to('update', all: options.fetch(:all), services_as_args: services) do |services| services.each do |service| puts "---Updating #{service}---" current_branch = `git branch --show-current` puts current_branch - system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git stash save -u -q neptuno_stash") + system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git add . && git stash save -u -q neptuno_stash") `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout main 2>/dev/null` `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout master 2>/dev/null` system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git pull") unless options.fetch(:main) - stash_id = `git stash list`.lines.find { |str| str =~ /neptuno_stash/ }&.split(":")&.first + stash_id = `git stash list`.lines.find { |str| str =~ /neptuno_stash/ }&.split(':')&.first `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout #{current_branch} 2>/dev/null` if stash_id - puts "Applying stashed changes" + puts 'Applying stashed changes' system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git stash pop -q #{stash_id}") end end - puts "" + puts '' end end end diff --git a/lib/neptuno/version.rb b/lib/neptuno/version.rb index e29c668..dfb2610 100644 --- a/lib/neptuno/version.rb +++ b/lib/neptuno/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Neptuno - VERSION = '1.2.3' + VERSION = '1.3.0' end