Skip to content

Commit

Permalink
Add customize command support
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Dec 22, 2022
1 parent 0356e58 commit 277838e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/boxing/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Config
:health_check, :health_check_path,
:assets_precompile, :node_version,
:build_packages, :runtime_packages,
:revision, :sentry_release
:revision, :sentry_release,
:entrypoint, :command

# @since 0.5.0
def initialize(&block)
Expand Down
26 changes: 26 additions & 0 deletions lib/boxing/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,31 @@ def mode_of(name)
mode |= Package::RUNTIME if config.runtime_packages&.include?(name)
mode
end

# Return entrypoint options
#
# @return [Array<String>]
#
# @since 0.9.0
def entrypoint
return config.entrypoint.map(&:to_s) if config.entrypoint
return ['bin/openbox'] if has?('openbox')
return ['bin/rails'] if has?('rails')

%w[bundle exec]
end

# Return command options
#
# @return [Array<String>]
#
# @since 0.9.0
def command
return config.command.map(&:to_s) if config.command
return ['server'] if has?('openbox')
return ['server', '-b', '0.0.0.0'] if has?('rails')

['rackup', '-o', '0.0.0.0']
end
end
end
60 changes: 60 additions & 0 deletions spec/boxing/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,64 @@
it { is_expected.to be_truthy }
end
end

describe '#entrypoint' do
subject { context.entrypoint }

it { is_expected.to include('bundle', 'exec') }

context 'when customized entrypoint' do
before do
config.entrypoint = ['bin/rackup']
end

it { is_expected.to include('bin/rackup') }
end

context 'when openbox exists' do
let(:context) do
described_class.new(config, database, [instance_double('Bundler::Dependency', name: 'openbox', git: nil)])
end

it { is_expected.to include('bin/openbox') }
end

context 'when rails exists' do
let(:context) do
described_class.new(config, database, [instance_double('Bundler::Dependency', name: 'rails', git: nil)])
end

it { is_expected.to include('bin/rails') }
end
end

describe '#command' do
subject { context.command }

it { is_expected.to include('rackup', '-o', '0.0.0.0') }

context 'when customized command' do
before do
config.command = ['console']
end

it { is_expected.to include('console') }
end

context 'when openbox exists' do
let(:context) do
described_class.new(config, database, [instance_double('Bundler::Dependency', name: 'openbox', git: nil)])
end

it { is_expected.to include('server') }
end

context 'when rails exists' do
let(:context) do
described_class.new(config, database, [instance_double('Bundler::Dependency', name: 'rails', git: nil)])
end

it { is_expected.to include('server', '-b', '0.0.0.0') }
end
end
end
12 changes: 2 additions & 10 deletions templates/Dockerfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,5 @@ EXPOSE <%= config.port %>
<%- if has?('liveness') || config.health_check -%>
HEALTHCHECK CMD curl -f http://localhost:<%= config.port %><%= config.health_check_path %> || exit 1
<%- end -%>
<%- if has?('openbox') -%>
ENTRYPOINT ["bin/openbox"]
CMD ["server"]
<%- elsif has?('rails') -%>
ENTRYPOINT ["bin/rails"]
CMD ["server", "-b", "0.0.0.0"]
<%- else -%>
ENTRYPOINT ["bundle", "exec"]
CMD ["rackup", "-o", "0.0.0.0"]
<%- end -%>
ENTRYPOINT <%= entrypoint %>
CMD <%= command %>

0 comments on commit 277838e

Please sign in to comment.