boxing 0.4.1 → 0.5.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +52 -7
- data/lib/boxing/command.rb +2 -0
- data/lib/boxing/commands/base.rb +39 -0
- data/lib/boxing/commands/compose.rb +24 -0
- data/lib/boxing/commands/generate.rb +1 -17
- data/lib/boxing/commands/update.rb +1 -1
- data/lib/boxing/config.rb +24 -0
- data/lib/boxing/context.rb +9 -1
- data/lib/boxing/version.rb +1 -1
- data/lib/boxing.rb +18 -0
- data/templates/Dockerfile.tt +6 -2
- data/templates/docker-compose.yml.tt +47 -0
- data/templates/dockerignore.tt +8 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be259e85a114d20ff05ffcc30a4342e5f678a5c1b6a4249e0c99111978dc7061
|
4
|
+
data.tar.gz: 35092941e6927158bab8530cfa678f6c2ff99533630e47b9034ba09c6a88f8fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6f1023671f6ca0c2f364bdcdb7f8804b8d87e39ae22cd905209c59f4234fe8a438c6423f73012451bf21d780d8bbe2caedd70cfe51f08cfc2ad5607c2dec01a
|
7
|
+
data.tar.gz: 94acc2f1314279b78e884c3f7361e02cff3935cd720a266bb5d4cf67ed92f7db8791a08f12b7a862fc8be2e39dbe686d3aff865375a7a93e0cebc031d777b0af
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -78,18 +78,63 @@ bundle exec boxing update
|
|
78
78
|
|
79
79
|
> If the generated `Dockerfile` is not satisfy, please try to update it.
|
80
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
|
+
|
81
114
|
## Roadmap
|
82
115
|
|
83
116
|
* [x] `Dockerfile` generator
|
84
|
-
* [x] `.
|
117
|
+
* [x] `.dockerignore` generator
|
85
118
|
* [x] Common ignore files
|
86
|
-
* [
|
87
|
-
* [ ]
|
88
|
-
* [ ]
|
89
|
-
* [x]
|
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)
|
90
136
|
* [x] Ruby on Rails
|
91
|
-
* [
|
92
|
-
* [ ] Ruby
|
137
|
+
* [x] Rack (Default)
|
93
138
|
* [ ] Package Database
|
94
139
|
* [x] Built-in (Move to standalone repoistory in future)
|
95
140
|
* [x] Standalone Repoistory
|
data/lib/boxing/command.rb
CHANGED
@@ -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 <
|
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')
|
@@ -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
|
data/lib/boxing/context.rb
CHANGED
@@ -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
|
@@ -60,6 +67,7 @@ module Boxing
|
|
60
67
|
Package.new('build-base', mode: Package::BUILD)
|
61
68
|
]
|
62
69
|
.push(git? ? Package.new('git', mode: Package::BUILD) : nil)
|
70
|
+
.push(has?('liveness') ? Package.new('curl', mode: Package::RUNTIME) : nil)
|
63
71
|
.compact
|
64
72
|
end
|
65
73
|
|
data/lib/boxing/version.rb
CHANGED
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
|
data/templates/Dockerfile.tt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
ARG APP_ROOT
|
1
|
+
ARG APP_ROOT=<%= config.root %>
|
2
2
|
ARG RUBY_VERSION=<%= RUBY_VERSION %>
|
3
3
|
|
4
4
|
FROM ruby:${RUBY_VERSION}-alpine AS gem
|
@@ -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
|
-
|
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
|
data/templates/dockerignore.tt
CHANGED
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.
|
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:
|
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: []
|