boxing 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be259e85a114d20ff05ffcc30a4342e5f678a5c1b6a4249e0c99111978dc7061
4
- data.tar.gz: 35092941e6927158bab8530cfa678f6c2ff99533630e47b9034ba09c6a88f8fd
3
+ metadata.gz: cd1ab96ae737b37be480b3d7d862a5925b951062f7ccae22eb200d26e55f3a14
4
+ data.tar.gz: 8cd2271e0cb3fc6736c2440f978bdee63b0ba43c90a57596f9064f5b576788ae
5
5
  SHA512:
6
- metadata.gz: a6f1023671f6ca0c2f364bdcdb7f8804b8d87e39ae22cd905209c59f4234fe8a438c6423f73012451bf21d780d8bbe2caedd70cfe51f08cfc2ad5607c2dec01a
7
- data.tar.gz: 94acc2f1314279b78e884c3f7361e02cff3935cd720a266bb5d4cf67ed92f7db8791a08f12b7a862fc8be2e39dbe686d3aff865375a7a93e0cebc031d777b0af
6
+ metadata.gz: 0c4c43055ed9973e21b4e1660fff4bc5f6cd870f08f82339a0ea88be4edde2914c2e37086a5bf92a48e493c12fb2ba20c68bb28c936fcd2e3f77a6fe5e5edf29
7
+ data.tar.gz: 25dd924fc89a7aa20361acbcdc2c52b0e320c007308ac1a79a227df9938c2b575f7ee468a0dac1dd5cda8d17a820ea0c6e2fcb18de3ad7e7c15c5fa8746205cd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxing (0.5.0)
4
+ boxing (0.6.0)
5
5
  bundler (~> 2.0)
6
6
  thor (~> 1.0)
7
7
 
data/README.md CHANGED
@@ -86,7 +86,7 @@ If `config/boxing.rb` is found, it will be loaded and change the generated `Dock
86
86
 
87
87
  ```ruby
88
88
  Boxing.config do |c|
89
- c.root = '/var/www'
89
+ c.root = '/var/www'
90
90
  end
91
91
  ```
92
92
 
@@ -94,9 +94,30 @@ end
94
94
 
95
95
  ```ruby
96
96
  Boxing.config do |c|
97
- c.ignores = %w[
98
- vendor/gems
99
- ]
97
+ c.ignores = %w[
98
+ vendor/gems
99
+ ]
100
+ end
101
+ ```
102
+
103
+ ### Extra Packages
104
+
105
+ ```ruby
106
+ Boxing.config do |c|
107
+ c.build_packages = %w[nodejs]
108
+ c.runtime_packages = %w[git]
109
+ end
110
+ ```
111
+
112
+ ### Assets Precompile
113
+
114
+ This feature is disabled by default and suggest to use CI to build it.
115
+
116
+ ```ruby
117
+ Boxing.config do |c|
118
+ c.assets_precompile = true
119
+ # If not given the `node -v` will be execute
120
+ c.node_version = '14.18'
100
121
  end
101
122
  ```
102
123
 
@@ -104,8 +125,8 @@ end
104
125
 
105
126
  ```ruby
106
127
  Boxing.config do |c|
107
- c.health_check = true
108
- c.health_check_path = '/api/status.json'
128
+ c.health_check = true
129
+ c.health_check_path = '/api/status.json'
109
130
  end
110
131
  ```
111
132
 
@@ -120,6 +141,8 @@ end
120
141
  * [ ] Docker Compose generator
121
142
  * [ ] Production Version
122
143
  * [x] Development Version
144
+ * [x] Allow run Assets Precompile in Container
145
+ * [ ] Disable `RAILS_SERVE_STATIC_FILES` by default
123
146
  * [x] Customize config file `config/boxing.rb`
124
147
  * [x] Customize `APP_ROOT`
125
148
  * [ ] Extra packages
@@ -127,7 +150,7 @@ end
127
150
  * [ ] Build Stage
128
151
  * [ ] Entrypoint
129
152
  * [ ] Command
130
- * [ ] Expose Port
153
+ * [x] Expose Port
131
154
  * [x] Health Check
132
155
  * [x] [Liveness](https://github.com/elct9620/openbox) gem detection
133
156
  * [x] Add `curl` for web application
data/lib/boxing/config.rb CHANGED
@@ -9,7 +9,10 @@ module Boxing
9
9
  # @return [String] the application root
10
10
  #
11
11
  # @since 0.5.0
12
- attr_accessor :root, :name, :registry, :ignores, :port, :health_check, :health_check_path
12
+ attr_accessor :root, :name, :registry, :ignores, :port,
13
+ :health_check, :health_check_path,
14
+ :assets_precompile, :node_version,
15
+ :build_packages, :runtime_packages
13
16
 
14
17
  # @since 0.5.0
15
18
  def initialize(&block)
@@ -17,6 +20,7 @@ module Boxing
17
20
  @root = '/srv/app'
18
21
  @port = 9292
19
22
  @health_path = '/status'
23
+ @assets_precompile = false
20
24
 
21
25
  instance_exec(self, &block) if defined?(yield)
22
26
  end
@@ -29,7 +29,7 @@ module Boxing
29
29
  def packages
30
30
  @packages ||=
31
31
  Set
32
- .new(default_packages)
32
+ .new(default_packages + extra_packages)
33
33
  .merge(
34
34
  @dependencies
35
35
  .map(&:name)
@@ -71,6 +71,31 @@ module Boxing
71
71
  .compact
72
72
  end
73
73
 
74
+ # Extra Packages
75
+ #
76
+ # @return [Array<Boxing::Package>]
77
+ #
78
+ # @since 0.6.0
79
+ def extra_packages
80
+ Array[config.build_packages, config.runtime_packages].compact.flat_map do |name|
81
+ mode = 0
82
+ mode |= Package::BUILD if config.build_packages&.include?(name)
83
+ mode |= Package::RUNTIME if config.runtime_packages&.include?(name)
84
+ Package.new(name, mode: mode)
85
+ end
86
+ end
87
+
88
+ # Return node.js version
89
+ #
90
+ # @return [String]
91
+ #
92
+ # @since 0.6.0
93
+ def node_version
94
+ return config.node_version if config.node_version
95
+
96
+ `node -v`.gsub(/^v/, '')
97
+ end
98
+
74
99
  # Convert to binding
75
100
  #
76
101
  # @return [Binding]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Boxing
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
@@ -1,5 +1,6 @@
1
1
  ARG APP_ROOT=<%= config.root %>
2
2
  ARG RUBY_VERSION=<%= RUBY_VERSION %>
3
+ <%- if config.assets_precompile -%>ARG NODE_VERSION=<%= node_version %><%- end -%>
3
4
 
4
5
  FROM ruby:${RUBY_VERSION}-alpine AS gem
5
6
  ARG APP_ROOT
@@ -23,6 +24,29 @@ RUN gem install bundler:<%= Bundler::VERSION %> \
23
24
  && find /usr/local/bundle -type f -name '*.o' -delete \
24
25
  && rm -rf /usr/local/bundle/cache/*.gem
25
26
 
27
+ <%- if config.assets_precompile -%>
28
+ FROM node:${NODE_VERSION}-alpine as node
29
+ FROM ruby:${RUBY_VERSION}-alpine as assets
30
+ ARG APP_ROOT
31
+
32
+ <%- if packages.select(&:runtime?).any? -%>
33
+ RUN apk add --no-cache <%= packages.select(&:runtime?).join(' ') %> yarn
34
+
35
+ <%- end -%>
36
+ COPY --from=node /usr/local/bin/node /usr/local/bin/node
37
+
38
+ COPY --from=gem /usr/local/bundle/config /usr/local/bundle/config
39
+ COPY --from=gem /usr/local/bundle /usr/local/bundle
40
+ COPY --from=gem /${APP_ROOT}/vendor/bundle /${APP_ROOT}/vendor/bundle
41
+
42
+ RUN mkdir -p ${APP_ROOT}
43
+ COPY . ${APP_ROOT}
44
+
45
+ ENV RAILS_ENV production
46
+ WORKDIR ${APP_ROOT}
47
+ RUN bundle exec rake assets:precompile
48
+
49
+ <%- end -%>
26
50
  FROM ruby:${RUBY_VERSION}-alpine
27
51
  ARG APP_ROOT
28
52
 
@@ -39,10 +63,12 @@ RUN mkdir -p ${APP_ROOT}
39
63
  <%- if has?('rails') -%>
40
64
  ENV RAILS_ENV=production
41
65
  ENV RAILS_LOG_TO_STDOUT=true
66
+ ENV RAILS_SERVE_STATIC_FILES=yes
42
67
  <%- end -%>
43
68
  ENV APP_ROOT=$APP_ROOT
44
69
 
45
70
  COPY . ${APP_ROOT}
71
+ COPY --from=assets /${APP_ROOT}/public /${APP_ROOT}/public
46
72
 
47
73
  ARG REVISION
48
74
  ENV REVISION $REVISION
@@ -60,7 +86,6 @@ RUN adduser -h ${APP_ROOT} -D -s /bin/nologin ruby ruby && \
60
86
  USER ruby
61
87
  WORKDIR ${APP_ROOT}
62
88
 
63
-
64
89
  EXPOSE <%= config.port %>
65
90
  <%- if has?('liveness') || config.health_check -%>
66
91
  HEALTHCHECK CMD curl -f http://localhost:<%= config.port %><%= config.health_check_path %> || exit 1
@@ -30,6 +30,9 @@ rspec.xml
30
30
  log/*
31
31
  tmp/*
32
32
 
33
+ # Frontend
34
+ node_modules/
35
+
33
36
  # Licensed
34
37
  .licensed.yml
35
38
  .licenses
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-11 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler