boxing 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '068827160fc7ffc1cdf5e95a35808275112cd91e60b99495b027fe4421cdfbf9'
4
- data.tar.gz: a0135cf5842af935caa075da6571ea746348a72a617b7152db279b81b5d3a297
3
+ metadata.gz: be259e85a114d20ff05ffcc30a4342e5f678a5c1b6a4249e0c99111978dc7061
4
+ data.tar.gz: 35092941e6927158bab8530cfa678f6c2ff99533630e47b9034ba09c6a88f8fd
5
5
  SHA512:
6
- metadata.gz: cd230cd0f3f3e3d16395fdd5b5ed30c5ef740aeb1ea5eba80eb48af37d76a85b4f0480f739cbcb8209a2f90fd32983ea9e11f0550c2a2492d6e7f9832329081c
7
- data.tar.gz: cec3dc49149dc97d7350c827a5351709c629a20be9fc677ab8b90afe964a7df0559d6a855113501f06c7c44036737cdd4cd924c345f7176daffe89b8624adc04
6
+ metadata.gz: a6f1023671f6ca0c2f364bdcdb7f8804b8d87e39ae22cd905209c59f4234fe8a438c6423f73012451bf21d780d8bbe2caedd70cfe51f08cfc2ad5607c2dec01a
7
+ data.tar.gz: 94acc2f1314279b78e884c3f7361e02cff3935cd720a266bb5d4cf67ed92f7db8791a08f12b7a862fc8be2e39dbe686d3aff865375a7a93e0cebc031d777b0af
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- boxing (0.3.0)
4
+ boxing (0.5.0)
5
5
  bundler (~> 2.0)
6
6
  thor (~> 1.0)
7
7
 
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  The zero-configuration Dockerfile generator for Ruby.
4
4
 
5
+ > The [Database Repository](https://github.com/elct9620/ruby-boxing-db) will be used for package information.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile development group:
@@ -76,21 +78,67 @@ bundle exec boxing update
76
78
 
77
79
  > If the generated `Dockerfile` is not satisfy, please try to update it.
78
80
 
81
+ ## Configuration
82
+
83
+ If `config/boxing.rb` is found, it will be loaded and change the generated `Dockerfile` and `.dockerignore`
84
+
85
+ ### Source Code Root
86
+
87
+ ```ruby
88
+ Boxing.config do |c|
89
+ c.root = '/var/www'
90
+ end
91
+ ```
92
+
93
+ ### Ignore Files
94
+
95
+ ```ruby
96
+ Boxing.config do |c|
97
+ c.ignores = %w[
98
+ vendor/gems
99
+ ]
100
+ end
101
+ ```
102
+
103
+ ### Health Check
104
+
105
+ ```ruby
106
+ Boxing.config do |c|
107
+ c.health_check = true
108
+ c.health_check_path = '/api/status.json'
109
+ end
110
+ ```
111
+
112
+ > If `liveness` gem is installed, the health check will enabled by default with `/status` path.
113
+
79
114
  ## Roadmap
80
115
 
81
116
  * [x] `Dockerfile` generator
82
- * [x] `.gitignore` generator
117
+ * [x] `.dockerignore` generator
83
118
  * [x] Common ignore files
84
- * [ ] Customizable ignore files
85
- * [ ] Customize config file `config/boxing.rb`
86
- * [ ] Entrypoint Detection
87
- * [x] Openbox (Suggested)
119
+ * [x] Customizable ignore files
120
+ * [ ] Docker Compose generator
121
+ * [ ] Production Version
122
+ * [x] Development Version
123
+ * [x] Customize config file `config/boxing.rb`
124
+ * [x] Customize `APP_ROOT`
125
+ * [ ] Extra packages
126
+ * [ ] DSL to customize `Dockerfile`
127
+ * [ ] Build Stage
128
+ * [ ] Entrypoint
129
+ * [ ] Command
130
+ * [ ] Expose Port
131
+ * [x] Health Check
132
+ * [x] [Liveness](https://github.com/elct9620/openbox) gem detection
133
+ * [x] Add `curl` for web application
134
+ * [x] Entrypoint Detection
135
+ * [x] [Openbox](https://github.com/elct9620/openbox) (Suggested)
88
136
  * [x] Ruby on Rails
89
- * [ ] Rack
90
- * [ ] Ruby
137
+ * [x] Rack (Default)
91
138
  * [ ] Package Database
92
139
  * [x] Built-in (Move to standalone repoistory in future)
93
140
  * [x] Standalone Repoistory
141
+ * [x] Support gems from `git` repoistory
94
142
  * [x] Customize Source
95
143
  * [ ] Base Image
96
144
  * [x] Alpine
@@ -12,7 +12,9 @@ module Boxing
12
12
  true
13
13
  end
14
14
 
15
+ require_relative 'commands/base'
15
16
  require_relative 'commands/generate'
17
+ require_relative 'commands/compose'
16
18
  require_relative 'commands/update'
17
19
  end
18
20
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boxing
4
+ # :nodoc:
5
+ module Commands
6
+ # The Base Command
7
+ #
8
+ # @since 0.5.0
9
+ class Base < Thor::Group
10
+ include Thor::Actions
11
+
12
+ # :nodoc:
13
+ def self.source_root
14
+ Pathname.new(File.dirname(__FILE__)).join('../../..')
15
+ end
16
+
17
+ # Prepare command environment
18
+ #
19
+ # @since 0.5.0
20
+ def prepare
21
+ config = Bundler.root.join('config/boxing.rb')
22
+ return unless config.exist?
23
+
24
+ load config
25
+ end
26
+
27
+ private
28
+
29
+ # :nodoc:
30
+ def context
31
+ @context = Context.new(
32
+ Boxing.config,
33
+ Database.new,
34
+ Boxing.dependencies
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boxing
4
+ # :nodoc:
5
+ module Commands
6
+ # The Docker Compose Generator
7
+ #
8
+ # @since 0.1.0
9
+ class Compose < Base
10
+ # Create Dockerfile
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Database.download! unless Database.exist?
15
+
16
+ # TODO: Allow set image registry
17
+ # TODO: Allow set application name
18
+ template('templates/docker-compose.yml.tt', 'docker-compose.yml', context: context.to_binding)
19
+ end
20
+ end
21
+
22
+ Boxing::Command.register(Compose, 'compose', 'compose', 'Generate docker-compose.yml')
23
+ end
24
+ end
@@ -9,14 +9,7 @@ module Boxing
9
9
  # The Dockerfle Generator
10
10
  #
11
11
  # @since 0.1.0
12
- class Generate < Thor::Group
13
- include Thor::Actions
14
-
15
- # :nodoc:
16
- def self.source_root
17
- Pathname.new(File.dirname(__FILE__)).join('../../..')
18
- end
19
-
12
+ class Generate < Base
20
13
  # Create Dockerfile
21
14
  #
22
15
  # @since 0.1.0
@@ -26,15 +19,6 @@ module Boxing
26
19
  template('templates/Dockerfile.tt', 'Dockerfile', context: context.to_binding)
27
20
  template('templates/dockerignore.tt', '.dockerignore', context: context.to_binding)
28
21
  end
29
-
30
- private
31
-
32
- def context
33
- @context = Context.new(
34
- Database.new,
35
- Boxing.dependencies
36
- )
37
- end
38
22
  end
39
23
 
40
24
  Boxing::Command.register(Generate, 'generate', 'generate', 'Generate Dockerfile')
@@ -6,7 +6,7 @@ module Boxing
6
6
  # The Database Updater
7
7
  #
8
8
  # @since 0.3.0
9
- class Update < Thor::Group
9
+ class Update < Base
10
10
  # Update Database
11
11
  #
12
12
  # @since 0.3.0
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boxing
4
+ # The config of boxing
5
+ #
6
+ # @since 0.5.0
7
+ class Config
8
+ # @!attribute root
9
+ # @return [String] the application root
10
+ #
11
+ # @since 0.5.0
12
+ attr_accessor :root, :name, :registry, :ignores, :port, :health_check, :health_check_path
13
+
14
+ # @since 0.5.0
15
+ def initialize(&block)
16
+ @name = 'myapp'
17
+ @root = '/srv/app'
18
+ @port = 9292
19
+ @health_path = '/status'
20
+
21
+ instance_exec(self, &block) if defined?(yield)
22
+ end
23
+ end
24
+ end
@@ -5,13 +5,20 @@ module Boxing
5
5
  #
6
6
  # @since 0.1.0
7
7
  class Context
8
+ # @since 0.5.0
9
+ attr_reader :config
10
+
11
+ # @param config [Boxing::Config]
8
12
  # @param database [Boxing::Database]
9
13
  # @param dependencies [Array<Bundler::Dependency>]
10
14
  #
11
15
  # @since 0.1.0
12
- def initialize(database, dependencies = [])
16
+ def initialize(config, database, dependencies = [])
17
+ @config = config
13
18
  @database = database
14
19
  @dependencies = dependencies
20
+
21
+ @config.port = 3000 if has?('rails')
15
22
  end
16
23
 
17
24
  # Return required packages
@@ -20,11 +27,14 @@ module Boxing
20
27
  #
21
28
  # @since 0.1.0
22
29
  def packages
23
- @packages ||= Set.new(
24
- @dependencies
25
- .map(&:name)
26
- .flat_map { |name| @database.package_for(name).to_a }
27
- )
30
+ @packages ||=
31
+ Set
32
+ .new(default_packages)
33
+ .merge(
34
+ @dependencies
35
+ .map(&:name)
36
+ .flat_map { |name| @database.package_for(name).to_a }
37
+ )
28
38
  end
29
39
 
30
40
  # Check rubygems exists
@@ -38,6 +48,29 @@ module Boxing
38
48
  @dependencies.any? { |dep| names.include?(dep.name) }
39
49
  end
40
50
 
51
+ # Does any gem from git
52
+ #
53
+ # @return [TrueClass|FalseClass]
54
+ #
55
+ # @since 0.4.0
56
+ def git?
57
+ @dependencies.any?(&:git)
58
+ end
59
+
60
+ # Default packages
61
+ #
62
+ # @return [Array<Boxing::Package>]
63
+ #
64
+ # @since 0.4.0
65
+ def default_packages
66
+ [
67
+ Package.new('build-base', mode: Package::BUILD)
68
+ ]
69
+ .push(git? ? Package.new('git', mode: Package::BUILD) : nil)
70
+ .push(has?('liveness') ? Package.new('curl', mode: Package::RUNTIME) : nil)
71
+ .compact
72
+ end
73
+
41
74
  # Convert to binding
42
75
  #
43
76
  # @return [Binding]
@@ -78,7 +78,7 @@ module Boxing
78
78
  return unless git?
79
79
 
80
80
  Dir.chdir(@path) do
81
- command = %w[git pull --quiet origin master]
81
+ command = %w[git pull --quiet origin main]
82
82
  raise UpdateFailed, "failed to update #{@path}" unless system(*command)
83
83
  end
84
84
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Boxing
4
- VERSION = '0.3.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/boxing.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'boxing/version'
4
+ require_relative 'boxing/config'
4
5
  require_relative 'boxing/package'
5
6
  require_relative 'boxing/database'
6
7
  require_relative 'boxing/context'
@@ -10,6 +11,8 @@ require_relative 'boxing/command'
10
11
  #
11
12
  # @since 0.1.0
12
13
  module Boxing
14
+ LOCK = Mutex.new
15
+
13
16
  module_function
14
17
 
15
18
  # @return [Bundler::Dependency]
@@ -21,4 +24,19 @@ module Boxing
21
24
  .current_dependencies
22
25
  .select { |dep| (dep.groups & groups).any? }
23
26
  end
27
+
28
+ # @return [Boxing::Config]
29
+ #
30
+ # @since 0.5.0
31
+ def config(&block)
32
+ return @config if @config
33
+
34
+ LOCK.synchronize do
35
+ return @config if @config
36
+
37
+ @config = Config.new(&block)
38
+ end
39
+
40
+ @config
41
+ end
24
42
  end
@@ -1,10 +1,10 @@
1
- ARG APP_ROOT=/src/app
1
+ ARG APP_ROOT=<%= config.root %>
2
2
  ARG RUBY_VERSION=<%= RUBY_VERSION %>
3
3
 
4
4
  FROM ruby:${RUBY_VERSION}-alpine AS gem
5
5
  ARG APP_ROOT
6
6
 
7
- RUN apk add --no-cache build-base <%= packages.select(&:build?).join(' ') %>
7
+ RUN apk add --no-cache <%= packages.select(&:build?).join(' ') %>
8
8
 
9
9
  RUN mkdir -p ${APP_ROOT}
10
10
  COPY Gemfile Gemfile.lock ${APP_ROOT}/
@@ -29,9 +29,6 @@ ARG APP_ROOT
29
29
  <%- if packages.select(&:runtime?).any? -%>
30
30
  RUN apk add --no-cache <%= packages.select(&:runtime?).join(' ') %>
31
31
 
32
- ARG REVISION
33
- ENV REVISION $REVISION
34
-
35
32
  <%- end -%>
36
33
  COPY --from=gem /usr/local/bundle/config /usr/local/bundle/config
37
34
  COPY --from=gem /usr/local/bundle /usr/local/bundle
@@ -46,6 +43,9 @@ ENV RAILS_LOG_TO_STDOUT=true
46
43
  ENV APP_ROOT=$APP_ROOT
47
44
 
48
45
  COPY . ${APP_ROOT}
46
+
47
+ ARG REVISION
48
+ ENV REVISION $REVISION
49
49
  RUN echo $REVISION > ${SERVER_ROOT}/REVISION
50
50
 
51
51
  # Apply Execute Permission
@@ -60,7 +60,11 @@ RUN adduser -h ${APP_ROOT} -D -s /bin/nologin ruby ruby && \
60
60
  USER ruby
61
61
  WORKDIR ${APP_ROOT}
62
62
 
63
- EXPOSE <%= has?('rails') ? '3000' : '9292' %>
63
+
64
+ EXPOSE <%= config.port %>
65
+ <%- if has?('liveness') || config.health_check -%>
66
+ HEALTHCHECK CMD curl -f http://localhost:<%= config.port %><%= config.health_check_path %> || exit 1
67
+ <%- end -%>
64
68
  <%- if has?('openbox') -%>
65
69
  ENTRYPOINT ["bin/openbox"]
66
70
  CMD ["server"]
@@ -0,0 +1,47 @@
1
+ version: '3.4'
2
+
3
+ volumes:
4
+ database:
5
+ driver: local
6
+
7
+ services:
8
+ <%- if has?('pg') -%>
9
+ postgres:
10
+ image: postgres:13.1
11
+ volumes:
12
+ - database:/var/lib/postgresql/data
13
+ environment:
14
+ - POSTGRES_DB=<%= config.name %>
15
+ - POSTGRES_USER=<%= config.name %>
16
+ - POSTGRES_PASSWORD=<%= config.name %>
17
+ <%- end -%>
18
+ <%- if has?('mysql2') -%>
19
+ mysql:
20
+ image: mysql:8.0
21
+ volumes:
22
+ - database:/var/lib/mysql
23
+ environment:
24
+ - MYSQL_USER=<%= config.name %>
25
+ - MYSQL_PASSWORD=<%= config.name %>
26
+ - MYSQL_DATABASE=<%= config.name %>
27
+ - MYSQL_ROOT_PASSWORD=<%= config.name %>
28
+ <%- end -%>
29
+ application:
30
+ <%- if config.registry.nil? -%>
31
+ build:
32
+ context: .
33
+ <%- else -%>
34
+ image: <%= config.registry %>
35
+ <%- end -%>
36
+ environment:
37
+ - RAILS_MASTER_KEY
38
+ - AUTO_MIGRATION=yes
39
+ <%- if has?('pg') -%>
40
+ - DATABASE_URL=postgres://<%= config.name %>:<%= config.name %>@postgres/<%= config.name %>
41
+ <%- elsif has?('mysql2') %>
42
+ - DATABASE_URL=mysql2://<%= config.name %>:<%= config.name %>@mysql/<%= config.name %>
43
+ <%- end -%>
44
+ ports:
45
+ - "3000:3000"
46
+ depends_on:
47
+ - postgres
@@ -8,8 +8,10 @@ docker-compose*.yml
8
8
  # CI/CD
9
9
  .github/
10
10
  .cache/
11
+ .circleci/
11
12
  coverage/
12
13
  spec/
14
+ test/
13
15
  features/
14
16
  .gitlab-ci.yml
15
17
  .travis.yml
@@ -31,3 +33,11 @@ tmp/*
31
33
  # Licensed
32
34
  .licensed.yml
33
35
  .licenses
36
+
37
+ # Boxing
38
+ config/boxing.rb
39
+ <% if config.ignores -%>
40
+
41
+ # Customize Ignores
42
+ <%= Array[config.ignores].join("\n") %>
43
+ <%- end -%>
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.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-29 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,13 +60,17 @@ files:
60
60
  - exe/boxing
61
61
  - lib/boxing.rb
62
62
  - lib/boxing/command.rb
63
+ - lib/boxing/commands/base.rb
64
+ - lib/boxing/commands/compose.rb
63
65
  - lib/boxing/commands/generate.rb
64
66
  - lib/boxing/commands/update.rb
67
+ - lib/boxing/config.rb
65
68
  - lib/boxing/context.rb
66
69
  - lib/boxing/database.rb
67
70
  - lib/boxing/package.rb
68
71
  - lib/boxing/version.rb
69
72
  - templates/Dockerfile.tt
73
+ - templates/docker-compose.yml.tt
70
74
  - templates/dockerignore.tt
71
75
  homepage: https://github.com/elct9620/boxing
72
76
  licenses: []