Skip to content

Commit

Permalink
allow build arguments to docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
robplan committed Oct 2, 2023
1 parent 2aaf5b3 commit 105fbaa
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
neptuno (1.2.3)
neptuno (1.3.0)
dotiw
dry-cli
hirb
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion lib/neptuno/docker/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions lib/neptuno/docker/down.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
28 changes: 20 additions & 8 deletions lib/neptuno/docker/restart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions lib/neptuno/services/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.2.3'
VERSION = '1.3.0'
end

0 comments on commit 105fbaa

Please sign in to comment.