Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/exec in container #12

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
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.7)

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