Skip to content

Commit

Permalink
Merge pull request #3 from elct9620/feature/2-detect-git-from-gemfile
Browse files Browse the repository at this point in the history
Support gems from git repoistory
  • Loading branch information
elct9620 authored Dec 30, 2021
2 parents d005b1b + 8aa089c commit 009f6dc
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
boxing (0.3.1)
boxing (0.4.0)
bundler (~> 2.0)
thor (~> 1.0)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ bundle exec boxing update
* [ ] Package Database
* [x] Built-in (Move to standalone repoistory in future)
* [x] Standalone Repoistory
* [x] Support gems from `git` repoistory
* [x] Customize Source
* [ ] Base Image
* [x] Alpine
Expand Down
36 changes: 31 additions & 5 deletions lib/boxing/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ def initialize(database, dependencies = [])
#
# @since 0.1.0
def packages
@packages ||= Set.new(
@dependencies
.map(&:name)
.flat_map { |name| @database.package_for(name).to_a }
)
@packages ||=
Set
.new(default_packages)
.merge(
@dependencies
.map(&:name)
.flat_map { |name| @database.package_for(name).to_a }
)
end

# Check rubygems exists
Expand All @@ -38,6 +41,29 @@ def has?(*names)
@dependencies.any? { |dep| names.include?(dep.name) }
end

# Does any gem from git
#
# @return [TrueClass|FalseClass]
#
# @since 0.4.0
def git?
pp @dependencies
@dependencies.any?(&:git)
end

# Default packages
#
# @return [Array<Boxing::Package>]
#
# @since 0.4.0
def default_packages
[
Package.new('build-base', mode: Package::BUILD)
]
.push(git? ? Package.new('git', mode: Package::BUILD) : nil)
.compact
end

# Convert to binding
#
# @return [Binding]
Expand Down
2 changes: 1 addition & 1 deletion lib/boxing/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Boxing
VERSION = '0.3.1'
VERSION = '0.4.0'
end
35 changes: 31 additions & 4 deletions spec/boxing/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
describe '#packages' do
subject { context.packages }

it { is_expected.to be_empty }
it { is_expected.to include(Boxing::Package.new('build-base')) }

context '#when package exists' do
let(:context) { described_class.new(database, [instance_double('Bundler::Dependency', name: 'rails')]) }
context '#when extra package exists' do
let(:context) { described_class.new(database, [instance_double('Bundler::Dependency', name: 'rails', git: nil)]) }

before do
allow(database).to receive(:package_for).with('rails').and_return([Boxing::Package.new('tzdata')])
Expand All @@ -21,13 +21,40 @@
end
end

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

it { is_expected.to include(Boxing::Package.new('build-base')) }
it { is_expected.not_to include(Boxing::Package.new('git')) }

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

it { is_expected.to include(Boxing::Package.new('git')) }
end
end

describe '#git?' do
it { is_expected.not_to be_git }

context '#when git source exists' do
subject do
described_class.new(database, [instance_double('Bundler::Dependency', name: 'rails', git: true)])
end

it { is_expected.to be_git }
end
end

describe '#has?' do
subject { context.has?('rails') }

it { is_expected.to be_falsy }

context '#when gem exists' do
let(:context) { described_class.new(database, [instance_double('Bundler::Dependency', name: 'rails')]) }
let(:context) { described_class.new(database, [instance_double('Bundler::Dependency', name: 'rails', git: nil)]) }

it { is_expected.to be_truthy }
end
Expand Down
8 changes: 4 additions & 4 deletions templates/Dockerfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG RUBY_VERSION=<%= RUBY_VERSION %>
FROM ruby:${RUBY_VERSION}-alpine AS gem
ARG APP_ROOT

RUN apk add --no-cache build-base <%= packages.select(&:build?).join(' ') %>
RUN apk add --no-cache <%= packages.select(&:build?).join(' ') %>

RUN mkdir -p ${APP_ROOT}
COPY Gemfile Gemfile.lock ${APP_ROOT}/
Expand All @@ -29,9 +29,6 @@ ARG APP_ROOT
<%- if packages.select(&:runtime?).any? -%>
RUN apk add --no-cache <%= packages.select(&:runtime?).join(' ') %>

ARG REVISION
ENV REVISION $REVISION

<%- end -%>
COPY --from=gem /usr/local/bundle/config /usr/local/bundle/config
COPY --from=gem /usr/local/bundle /usr/local/bundle
Expand All @@ -46,6 +43,9 @@ ENV RAILS_LOG_TO_STDOUT=true
ENV APP_ROOT=$APP_ROOT

COPY . ${APP_ROOT}

ARG REVISION
ENV REVISION $REVISION
RUN echo $REVISION > ${SERVER_ROOT}/REVISION

# Apply Execute Permission
Expand Down

0 comments on commit 009f6dc

Please sign in to comment.