Skip to content

Commit

Permalink
Merge remote-tracking branch 'joseph/feat/exec-in-container'
Browse files Browse the repository at this point in the history
  • Loading branch information
robplan committed Dec 30, 2023
2 parents 0b58997 + ab8628f commit 8f22a12
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ GEM
zeitwerk (2.6.11)

PLATFORMS
arm64-darwin-21
x86_64-darwin-21
x86_64-darwin-22
x86_64-linux
Expand Down
2 changes: 1 addition & 1 deletion lib/neptuno/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module CLI
register "ls", List, aliases: ["ps"]
register "activate", Activate, aliases: ["a"]
register "config", Configure, aliases: %w[configure conf cc]
register "execute", Execute, aliases: ["e"]
register "execute", Execute, aliases: ["e", "exec"]
register "build", ::Neptuno::Docker::Build, aliases: ["b"]
register "up", Docker::Up, aliases: ["u"]
register "down", Docker::Down, aliases: ["d"]
Expand Down
29 changes: 17 additions & 12 deletions lib/neptuno/cli/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ module CLI
class Execute < Neptuno::CLI::Base
include TTY::File
include TTY::Config

desc "Execute command inside of container"

desc "Execute service script"

def call(**options)
command_service_to("execute", service_as_args: options[:args]&.first) do |service, _project|
commands = Dir.glob("#{neptuno_path}/scripts/#{service}/*").map { |x| x.split("/") }.map(&:last)
command = options[:args].last if commands.include?(options[:args]&.last)
puts "#{neptuno_path}/scripts/#{service}/*"
puts service
puts commands.to_s
puts Dir.glob("#{neptuno_path}/scripts/#{service}/*").to_s
command ||= prompt.select("execute", commands || [])
`cd #{neptuno_path}/scripts/#{service} && ./#{command}`
def call(services: [],**options)
command_service_to('execute', service_as_args: services) do |service, _project|
command = options[:args][-1]
# Creates a hash of processes from Procfile
procHash = File.foreach("#{neptuno_path}/procfiles/#{service}/Procfile").with_object({}) do |line, hash|
name, process = line.strip.split(':', 2)
hash[name] = process
end
if procHash.has_key?(command)
puts "Found #{command} in procfile, executing #{command}"
system("cd #{neptuno_path} && #{procHash[command]}")
else
puts "Executing #{command} inside of #{service} container"
system("cd #{neptuno_path} && docker compose exec #{service} $0 -c \"#{command}\"")
end
end
end
end
Expand Down

0 comments on commit 8f22a12

Please sign in to comment.