Skip to content

Commit

Permalink
last commit from intel
Browse files Browse the repository at this point in the history
  • Loading branch information
robplan committed Feb 29, 2024
1 parent 8f22a12 commit 82bee1f
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 15 deletions.
20 changes: 16 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
neptuno (1.3.0)
neptuno (1.5.3)
dotiw
dry-cli
hirb
Expand All @@ -17,19 +17,29 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.7.2)
activesupport (7.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ansi (1.5.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.5)
builder (3.2.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
diff-lcs (1.5.0)
dotiw (5.3.3)
activesupport
i18n
drb (2.2.0)
ruby2_keywords
dry-cli (1.0.0)
hirb (0.7.3)
i18n (1.14.1)
Expand All @@ -41,6 +51,7 @@ GEM
builder
minitest (>= 5.0)
ruby-progressbar
mutex_m (0.2.0)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
Expand All @@ -67,6 +78,7 @@ GEM
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
standard (1.18.0)
rubocop (= 1.39.0)
rubocop-performance (= 1.15.0)
Expand All @@ -86,15 +98,15 @@ GEM
tty-cursor (~> 0.7)
tty-screen (~> 0.8)
wisper (~> 2.0)
tty-screen (0.8.1)
tty-screen (0.8.2)
tty-spinner (0.9.3)
tty-cursor (~> 0.7)
tty-which (0.5.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
wisper (2.0.1)
zeitwerk (2.6.11)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-21
Expand Down
1 change: 1 addition & 0 deletions lib/neptuno/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ module CLI
register "install", ::Neptuno::CLI::Install
register "environment update", Environment::Update
register "environment config", Environment::Config
register "jump", Jump, aliases: ['j']
end
end
6 changes: 3 additions & 3 deletions lib/neptuno/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ def initialize
end

def command_service_to(request, service_as_args: "")
chosen_service ||= service_as_args.to_a.empty? ? nil : service_as_args
chosen_service ||= Array(service_as_args).empty? ? nil : service_as_args
chosen_service ||= service if in_service?
chosen_service ||= prompt.select("Command service to #{request}:", services)
yield chosen_service, project
end

def command_services_to(request, all: nil, services_as_args: [])
chosen_services = services if all
chosen_services ||= services_as_args.to_a.empty? ? nil : services_as_args
chosen_services ||= Array(services_as_args).empty? ? nil : services_as_args
chosen_services ||= [service] if in_service?
chosen_services ||= configured_services.to_a.empty? ? nil : configured_services
chosen_services ||= Array(configured_services).empty? ? nil : configured_services
chosen_services ||= prompt.multi_select("Command services to #{request}:", services)
yield chosen_services, project
end
Expand Down
17 changes: 17 additions & 0 deletions lib/neptuno/cli/jump.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Neptuno
module CLI
class Jump < Neptuno::CLI::Base
include ::Neptuno::TTY::Config
desc "Jump between a service's files"

def call(**options)
command_service_to("jump", service_as_args: options[:args]&.first) do |service, project|
files = [:procfiles, :dockerfiles, :environments, :services]
chosen_folder ||= prompt.select("Jump to #{service}'s:", files)

puts "#{neptuno_path}/#{chosen_folder}/#{service}"
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/neptuno/cli/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def services_and_procs
def service_current_branches
branches = `cd #{neptuno_path} && git submodule foreach 'git branch --show-current'`
branches.lines.each_slice(2).map do |service, branch|
[service.match(%r{services/(.*)'}).to_a.last, branch.to_s.strip]
[service.match(%r{services\/(.*)'}).to_a.last, branch.to_s.strip]
end.to_h
end

Expand Down
2 changes: 1 addition & 1 deletion lib/neptuno/docker/up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Up < Neptuno::CLI::Base
def call(services: [], **options)
command_services_to('come up', all: options.fetch(:all), services_as_args: services) do |services, _project|
make_service_files(services)
system("cd #{neptuno_path} && docker compose up -d --wait #{services.join(' ')}")
system("cd #{neptuno_path} && docker compose up --wait #{services.join(' ')}")
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/neptuno/overmind/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Start < Neptuno::CLI::Base

option :all, type: :boolean, default: false, desc: "Run on all services"
option :up, type: :boolean, default: true, desc: "Try to start containers before connecting"
option :inline, type: :boolean, default: false, desc: 'Start processes inline'
argument :services, type: :array, required: false, desc: "Optional list of services"

def call(services: [], **options)
Expand All @@ -27,9 +28,11 @@ def call(services: [], **options)
end
else
services.each do |service|
system("cd #{neptuno_path}/procfiles/#{service} && overmind start -D -N #{if auto_restart_procs.to_a.size > 0
inline = options.fetch(:inline) ? "" : "-D"
output = options.fetch(:inline) ? "" : "> /dev/null 2>&1"
system("cd #{neptuno_path}/procfiles/#{service} && overmind start #{inline} -N #{if auto_restart_procs.to_a.size > 0
("-r " + auto_restart_procs.join(",") + " ")
end} > /dev/null 2>&1")
end} #{output}")
end
end
end
Expand Down
21 changes: 19 additions & 2 deletions lib/neptuno/services/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def call(services: [], **options)
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
if `ls -hal #{neptuno_path}/services/#{service} 2>/dev/null | grep .git`.empty?
next if !initialize_submodule(service)
end
current_branch = `cd #{neptuno_path}/services/#{service} 2>/dev/null && git branch --show-current`
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`
Expand All @@ -33,6 +35,21 @@ def call(services: [], **options)
end
end
end

def initialize_submodule(service)
puts "Initializing submodule for #{service}"
if `git submodule | grep #{service} 2>/dev/null`.empty?
puts ("Skipping #{service}, it is not a git submodule.")
puts ""
return false
end
# TODO abort if the current user doesn't have access to the remote submodule repo

`cd #{neptuno_path}/services/#{service} && git submodule update --init --recursive`
`cd #{neptuno_path}/services/#{service} && git checkout master 2>/dev/null`
`cd #{neptuno_path}/services/#{service} && git checkout main 2>/dev/null`
return true
end
end
end
end
3 changes: 2 additions & 1 deletion lib/neptuno/tty/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def running_services
end

def json_services_status
JSON.parse(`cd #{neptuno_path} && docker compose ps --all --format json`).map do |service|
`cd #{neptuno_path} && docker compose ps --all --format json`.lines.map do |line|
service = JSON.parse(line)
[service.dig('Service'), service.dig('Status')]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/neptuno/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Neptuno
VERSION = '1.4.0'
VERSION = '1.5.3'
end
Binary file added neptuno-1.4.0.gem
Binary file not shown.

0 comments on commit 82bee1f

Please sign in to comment.