roro 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Guardfile +9 -5
- data/lib/roro.rb +1 -1
- data/lib/roro/cli.rb +5 -1
- data/lib/roro/cli/base/base.rb +2 -1
- data/lib/roro/cli/base/base_files.rb +1 -7
- data/lib/roro/cli/base/check_dependencies.rb +98 -0
- data/lib/roro/cli/base/insert_gems.rb +15 -7
- data/lib/roro/cli/base/insertions.rb +3 -1
- data/lib/roro/cli/configuration.rb +68 -0
- data/lib/roro/cli/generate/config.rb +13 -0
- data/lib/roro/cli/generate/config/rails.rb +17 -0
- data/lib/roro/cli/generate/generate.rb +1 -0
- data/lib/roro/cli/generate/generate_keys.rb +79 -0
- data/lib/roro/cli/greenfield.rb +15 -16
- data/lib/roro/cli/rollon.rb +66 -20
- data/lib/roro/cli/rollon/database/database.rb +31 -0
- data/lib/roro/cli/rollon/database/with_mysql.rb +22 -0
- data/lib/roro/cli/rollon/database/with_postgres.rb +21 -0
- data/lib/roro/cli/rollon/stories.rb +3 -3
- data/lib/roro/cli/roro_configurator.yml +157 -0
- data/{.keep → lib/roro/cli/templates/base/.env/.keep} +0 -0
- data/lib/roro/cli/templates/base/.env/database.mysql.env.tt +4 -0
- data/lib/roro/cli/templates/base/.env/database.pg.env.tt +5 -0
- data/lib/roro/cli/templates/base/.env/web.env.tt +1 -0
- data/lib/roro/cli/templates/base/.roro_config.yml +15 -0
- data/lib/roro/cli/templates/base/Dockerfile.tt +44 -0
- data/lib/roro/cli/templates/base/config/database.mysql.yml +19 -0
- data/lib/roro/cli/templates/base/config/{database.yml.pg.tt → database.pg.yml} +0 -0
- data/lib/roro/cli/templates/{base/circleci → circleci}/config.yml.tt +0 -0
- data/lib/roro/cli/templates/greenfield/Dockerfile.tt +29 -7
- data/lib/roro/cli/templates/{base/livereload → livereload}/hosts.example +0 -0
- data/lib/roro/cli/templates/{base/roro → roro}/.keep +0 -0
- data/lib/roro/cli/templates/{greenfield → roro}/docker-compose.yml.tt +18 -13
- data/lib/roro/cli/templates/{base/roro/containers → roro/roro}/.keep +0 -0
- data/lib/roro/cli/templates/{base/roro/containers/app → roro/roro/containers}/.keep +0 -0
- data/lib/roro/cli/templates/{base/roro/containers/frontend → roro/roro/containers/app}/.keep +0 -0
- data/lib/roro/cli/templates/roro/roro/containers/frontend/.keep +0 -0
- data/lib/roro/cli/templates/roro/roro/docker-entrypoint.sh.tt +8 -0
- data/lib/roro/cli/templates/stories/.keep +0 -0
- data/lib/roro/cli/templates/stories/with_mysql/_service.yml +10 -0
- data/lib/roro/cli/templates/stories/with_postgresql/.keep +0 -0
- data/lib/roro/cli/templates/stories/with_postgresql/_service.yml +7 -0
- data/lib/roro/version.rb +1 -1
- metadata +33 -25
- data/lib/roro/cli/base/configuration.rb +0 -118
- data/lib/roro/cli/rollon/rollon_as_dockerize.rb +0 -42
- data/lib/roro/cli/rollon/rollon_as_quickstart.rb +0 -17
- data/lib/roro/cli/rollon/rollon_as_roro.rb +0 -30
- data/lib/roro/cli/templates/base/docker-compose.yml.tt +0 -53
- data/lib/roro/cli/templates/base/pg/config/database.yml.pg.tt +0 -20
- data/lib/roro/cli/templates/base/pg/database.yml.pg.tt +0 -20
- data/lib/roro/cli/templates/base/roro/containers/app/Dockerfile.tt +0 -32
- data/lib/roro/cli/templates/base/roro/containers/app/development.env.tt +0 -1
- data/lib/roro/cli/templates/base/roro/containers/app/docker-entrypoint.sh +0 -8
- data/lib/roro/cli/templates/base/roro/containers/app/test.env.tt +0 -1
- data/lib/roro/cli/templates/base/roro/containers/database/development.env.tt +0 -4
- data/lib/roro/cli/templates/base/roro/containers/database/test.env.tt +0 -4
- data/roro-0.3.4.gem +0 -0
data/lib/roro/cli/rollon.rb
CHANGED
@@ -4,35 +4,81 @@ module Roro
|
|
4
4
|
|
5
5
|
class CLI < Thor
|
6
6
|
|
7
|
-
desc "rollon", "Generates files and makes changes to your
|
8
|
-
|
7
|
+
desc "rollon", "Generates files for and makes changes to your app
|
8
|
+
so it can run using Docker containers."
|
9
9
|
method_option :interactive, desc: "Set up your environment variables as
|
10
10
|
you go."
|
11
11
|
|
12
12
|
def rollon
|
13
|
+
confirm_directory_not_empty
|
13
14
|
confirm_dependencies
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
suggestion: "$ roro greenfield",
|
22
|
-
conditional: "!Dir.glob('*').empty?" })
|
23
|
-
@env_hash || get_configuration_variables
|
24
|
-
# case ask("Configure using the Quickstart, Curated, or HandsomeFencer way?\n\n(1) Quikstart\n\n(2) Curated\n\n(3) HandsomeFencer\n\n", { default: '2', limited_to: %w(1 2 3) })
|
25
|
-
# when '1'
|
26
|
-
# rollon_as_quickstart
|
27
|
-
# when '2'
|
28
|
-
# rollon_as_dockerized
|
29
|
-
# when '3'
|
30
|
-
# end
|
31
|
-
rollon_as_dockerize
|
15
|
+
remove_roro_artifacts
|
16
|
+
|
17
|
+
configure_for_rollon
|
18
|
+
|
19
|
+
copy_roro_files
|
20
|
+
generate_roro_config
|
21
|
+
startup_commands
|
32
22
|
end
|
33
23
|
|
34
24
|
no_commands do
|
25
|
+
|
26
|
+
def configure_for_rollon
|
27
|
+
@config ||= Roro::Configuration.new(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def yaml_from_template(file)
|
31
|
+
File.read(File.dirname(__FILE__) + "/templates/#{file}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def copy_roro_files
|
35
|
+
configure_database
|
36
|
+
directory 'roro', './', @config.app
|
37
|
+
template 'base/Dockerfile.tt', 'roro/containers/app/Dockerfile', @config.app
|
38
|
+
take_thor_actions
|
39
|
+
end
|
40
|
+
|
41
|
+
def take_thor_actions
|
42
|
+
@config.thor_actions.each {|k, v| eval(k) if v.eql?('y') }
|
43
|
+
end
|
44
|
+
|
45
|
+
def startup_commands
|
46
|
+
system 'docker-compose build'
|
47
|
+
system 'docker-compose run web bundle'
|
48
|
+
system 'docker-compose run web bin/rails webpacker:install'
|
49
|
+
system 'docker-compose run web bin/rails yarn:install'
|
50
|
+
system 'docker-compose run web bin/rails db:create'
|
51
|
+
system 'docker-compose run web bin/rails db:migrate'
|
52
|
+
system 'docker-compose up'
|
53
|
+
end
|
54
|
+
|
55
|
+
def confirm_directory_empty
|
56
|
+
confirm = confirm_dependency({
|
57
|
+
system_query: "ls -A",
|
58
|
+
warning: "this is not an empty directory. Roro will not greenfield a new Rails app unless either a) the current directory is empty or b) you run greenfield with the --force flag",
|
59
|
+
suggestion: "$ roro greenfield --force",
|
60
|
+
conditional: "Dir.glob('*').empty?" })
|
61
|
+
confirm || true
|
62
|
+
end
|
63
|
+
|
35
64
|
|
65
|
+
def confirm_dependency(options)
|
66
|
+
msg = []
|
67
|
+
msg << ""
|
68
|
+
msg << delineator
|
69
|
+
msg << "It looks like #{options[:warning]}. The following bash command returns false:"
|
70
|
+
msg << "\t$ #{options[:system_query]}"
|
71
|
+
msg << "Please try these instructions:"
|
72
|
+
msg << ("\t" + options[:suggestion])
|
73
|
+
msg << delineator
|
74
|
+
conditional = options[:conditional] ? eval(options[:conditional]) : system(options[:system_query])
|
75
|
+
if conditional == false
|
76
|
+
raise(Roro::Error.new(msg.join("\n\n")))
|
77
|
+
else
|
78
|
+
true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
36
82
|
end
|
37
83
|
end
|
38
84
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Roro
|
2
|
+
|
3
|
+
class CLI < Thor
|
4
|
+
|
5
|
+
no_commands do
|
6
|
+
|
7
|
+
def configure_database
|
8
|
+
database = @config.thor_actions['configure_database']
|
9
|
+
vendor = @config.master['services']['database']['vendors']
|
10
|
+
case database
|
11
|
+
when 'p'
|
12
|
+
@config.app['database_vendor'] = 'postgresql'
|
13
|
+
@config.app['postgresql_env_vars'] = vendor['postgresql']['env_vars']
|
14
|
+
configure_for_pg
|
15
|
+
when 'm'
|
16
|
+
@config.app['database_vendor'] = 'mysql'
|
17
|
+
@config.app['mysql_env_vars'] = vendor['mysql']['env_vars']
|
18
|
+
configure_for_mysql
|
19
|
+
end
|
20
|
+
|
21
|
+
%w(development production test staging ci).each do |environment|
|
22
|
+
template(
|
23
|
+
'base/.env/web.env.tt',
|
24
|
+
"roro/containers/app/#{environment}.env", @config.app
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Roro
|
2
|
+
|
3
|
+
class CLI < Thor
|
4
|
+
|
5
|
+
no_commands do
|
6
|
+
|
7
|
+
def configure_for_mysql
|
8
|
+
insert_db_gem('mysql2')
|
9
|
+
copy_file 'base/config/database.mysql.yml', 'config/database.yml', force: true
|
10
|
+
config = @config.app.clone
|
11
|
+
|
12
|
+
%w(development production test staging ci).each do |environment|
|
13
|
+
config['rails_env'] = environment
|
14
|
+
|
15
|
+
source = 'base/.env/database.mysql.env.tt'
|
16
|
+
target = "roro/containers/database/#{environment}.env"
|
17
|
+
template( source, target, config )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Roro
|
2
|
+
|
3
|
+
class CLI < Thor
|
4
|
+
|
5
|
+
no_commands do
|
6
|
+
|
7
|
+
def configure_for_pg
|
8
|
+
insert_db_gem('pg')
|
9
|
+
copy_file 'base/config/database.pg.yml', 'config/database.yml', force: true
|
10
|
+
config = @config.app.clone
|
11
|
+
%w(development production test staging ci).each do |environment|
|
12
|
+
config['rails_env'] = environment
|
13
|
+
|
14
|
+
source = 'base/.env/database.pg.env.tt'
|
15
|
+
target = "roro/containers/database/#{environment}.env"
|
16
|
+
template( source, target, config )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
3
|
-
require_relative '
|
1
|
+
require_relative 'database/with_postgres.rb'
|
2
|
+
require_relative 'database/with_mysql.rb'
|
3
|
+
require_relative 'database/database.rb'
|
@@ -0,0 +1,157 @@
|
|
1
|
+
---
|
2
|
+
main_app_name: <%= Dir.pwd.split('/').last %>
|
3
|
+
developer:
|
4
|
+
name: your-name
|
5
|
+
email: your.email@example.com
|
6
|
+
|
7
|
+
services:
|
8
|
+
server_app:
|
9
|
+
name: app
|
10
|
+
vendors:
|
11
|
+
rails:
|
12
|
+
version:
|
13
|
+
image:
|
14
|
+
official_name: ruby
|
15
|
+
variants:
|
16
|
+
- alpine
|
17
|
+
- buster
|
18
|
+
- slim
|
19
|
+
- slim-buster
|
20
|
+
- stretch
|
21
|
+
|
22
|
+
choices:
|
23
|
+
|
24
|
+
config_std_out_true:
|
25
|
+
question: |
|
26
|
+
The team at Heroku, among others, recommend logging to STDOUT
|
27
|
+
and treating your logs as streams. We'll set this to
|
28
|
+
true as an environment variable but it may also be helpful
|
29
|
+
to configure './config/boot.rb' with '$stdout.sync = true'
|
30
|
+
just in case that doesn't work.
|
31
|
+
Would you like to configure this?
|
32
|
+
choices:
|
33
|
+
y: 'Yes'
|
34
|
+
n: 'No'
|
35
|
+
default: y
|
36
|
+
|
37
|
+
insert_roro_gem_into_gemfile:
|
38
|
+
question: |
|
39
|
+
Many developers believe it's good idea to secure sensitive
|
40
|
+
environment files and variables. You can use RoRo to
|
41
|
+
generate secret keys known only to you for use in any
|
42
|
+
environment, and then use them to encrypt and decrypt
|
43
|
+
these files. Would you like to add RoRo to your Gemfile?
|
44
|
+
choices:
|
45
|
+
y: 'Yes'
|
46
|
+
n: 'No'
|
47
|
+
default: y
|
48
|
+
|
49
|
+
gitignore_sensitive_files:
|
50
|
+
question: |
|
51
|
+
If you plan to use the environment files RoRo generates for
|
52
|
+
your own environment variables, it's a good idea to keep
|
53
|
+
these files out of source control. Would you like RoRo to
|
54
|
+
modify your .gitignore file to accomplish this for you ?
|
55
|
+
choices:
|
56
|
+
y: 'Yes'
|
57
|
+
n: 'No'
|
58
|
+
default: y
|
59
|
+
|
60
|
+
insert_hfci_gem_into_gemfile:
|
61
|
+
question: |
|
62
|
+
Jim Weirich passed too soon and remains missed. In addition
|
63
|
+
to Rake, Jim wrote a beautiful gem called 'Given' that makes
|
64
|
+
Rspec and Minitest less ugly and thus your tests more easy to
|
65
|
+
write. Would you like to install a gem called
|
66
|
+
handsome_fencer-test that allows you to try it out?
|
67
|
+
choices:
|
68
|
+
y: 'Yes'
|
69
|
+
n: 'No'
|
70
|
+
default: n
|
71
|
+
|
72
|
+
backup_existing_files:
|
73
|
+
question: |
|
74
|
+
RoRo will be generating a number of files, some of which will
|
75
|
+
replace existing ones. Would you like to back them up?
|
76
|
+
choices:
|
77
|
+
y: 'Yes'
|
78
|
+
n: 'No'
|
79
|
+
default: n
|
80
|
+
|
81
|
+
copy_dockerignore:
|
82
|
+
question: |
|
83
|
+
Would you like to create a .dockerignore file?
|
84
|
+
choices:
|
85
|
+
y: 'Yes'
|
86
|
+
n: 'No'
|
87
|
+
default: y
|
88
|
+
|
89
|
+
configure_database:
|
90
|
+
question: |
|
91
|
+
RoRo can reliably dockerize your Rails app with either
|
92
|
+
MySQL or PostgreSQL stories. Which story would you prefer
|
93
|
+
to roll on?
|
94
|
+
choices:
|
95
|
+
p: PostgreSQL
|
96
|
+
m: MySQL
|
97
|
+
default: p
|
98
|
+
|
99
|
+
env_vars:
|
100
|
+
DATABASE_HOST: database
|
101
|
+
|
102
|
+
database:
|
103
|
+
name: database
|
104
|
+
vendor: postgresql
|
105
|
+
vendors:
|
106
|
+
postgresql:
|
107
|
+
images:
|
108
|
+
official_name:
|
109
|
+
versions:
|
110
|
+
- latest
|
111
|
+
env_vars:
|
112
|
+
POSTGRES_USER: postgres
|
113
|
+
POSTGRES_PASSWORD: your-postgres-password
|
114
|
+
|
115
|
+
mysql:
|
116
|
+
env_vars:
|
117
|
+
MYSQL_ROOT_PASSWORD: root
|
118
|
+
MYSQL_PASSWORD: root
|
119
|
+
MYSQL_USERNAME: root
|
120
|
+
MYSQL_DATABASE_PORT: '3306'
|
121
|
+
|
122
|
+
frontend:
|
123
|
+
name: frontend
|
124
|
+
vendors:
|
125
|
+
|
126
|
+
- frontend
|
127
|
+
- vuejs
|
128
|
+
- react
|
129
|
+
- angular
|
130
|
+
webserver:
|
131
|
+
default: nginx
|
132
|
+
vendors:
|
133
|
+
- nginx
|
134
|
+
application_server:
|
135
|
+
name: appserver
|
136
|
+
vendors:
|
137
|
+
- unicorn:
|
138
|
+
- puma:
|
139
|
+
registries:
|
140
|
+
dockerhub:
|
141
|
+
env_vars:
|
142
|
+
DOCKERHUB_EMAIL: your-docker-hub-email
|
143
|
+
DOCKERHUB_ORG: your-docker-hub-org-name
|
144
|
+
DOCKERHUB_PASSWORD: your-docker-hub-password
|
145
|
+
DOCKERHUB_USER: your-docker-hub-user-name
|
146
|
+
|
147
|
+
ci_cd:
|
148
|
+
semaphore:
|
149
|
+
circleci:
|
150
|
+
env_vars:
|
151
|
+
DEPLOY_TAG: "${CIRCLE_SHA1:0:7}"
|
152
|
+
|
153
|
+
deployment:
|
154
|
+
env_vars:
|
155
|
+
SERVER_HOST: "ip-address-of-your-server"
|
156
|
+
SERVER_PORT: '22'
|
157
|
+
SERVER_USER: root
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
DATABASE_HOST=database
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
main_app_name: greenfield
|
3
|
+
database_host: database
|
4
|
+
ruby_version: '2.7'
|
5
|
+
frontend_service: frontend
|
6
|
+
webserver_service: nginx
|
7
|
+
database_service: database
|
8
|
+
database_vendor: mysql
|
9
|
+
mysql_env_vars:
|
10
|
+
MYSQL_ROOT_PASSWORD: root
|
11
|
+
MYSQL_PASSWORD: root
|
12
|
+
MYSQL_USERNAME: root
|
13
|
+
MYSQL_DATABASE_PORT: '3306'
|
14
|
+
thor_actions:
|
15
|
+
insert_hfci_gem_into_gemfile: y
|
@@ -0,0 +1,44 @@
|
|
1
|
+
FROM ruby:<%= config['ruby_version'] %>
|
2
|
+
LABEL maintainer="<%= config['dockerhub_email'] %>"
|
3
|
+
|
4
|
+
|
5
|
+
## Make sure we have yarn properly sourced:
|
6
|
+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
|
7
|
+
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
|
8
|
+
|
9
|
+
## Update OS and download yarm from source specified above:
|
10
|
+
RUN apt-get update -qq && apt-get install -y build-essential git nodejs yarn
|
11
|
+
|
12
|
+
## Set up our workspace directories:
|
13
|
+
ENV APP_HOME /usr/src/app/
|
14
|
+
RUN mkdir ${APP_HOME}
|
15
|
+
|
16
|
+
## Tell bundler where to store downloaded gems:
|
17
|
+
ENV BUNDLE_PATH /gems
|
18
|
+
RUN mkdir ${BUNDLE_PATH}}
|
19
|
+
|
20
|
+
## Tell Docker to create volumes for our workspace and gems
|
21
|
+
## so other containers can access them.
|
22
|
+
VOLUME ${APP_HOME}
|
23
|
+
VOLUME /gems
|
24
|
+
|
25
|
+
## To speed up development, copy Gemfile and Gemfile.lock from host
|
26
|
+
## and then bundle so changing other parts of the app don't trigger
|
27
|
+
## a full gem install.
|
28
|
+
COPY Gemfile* ./
|
29
|
+
|
30
|
+
WORKDIR ${APP_HOME}
|
31
|
+
|
32
|
+
RUN bundle
|
33
|
+
|
34
|
+
COPY roro/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
|
35
|
+
RUN chmod +x /usr/bin/docker-entrypoint.sh
|
36
|
+
ENTRYPOINT ["docker-entrypoint.sh"]
|
37
|
+
|
38
|
+
COPY . /usr/src/app/
|
39
|
+
|
40
|
+
# RUN chmod +x /usr/src/app/roro/docker-entrypoint.sh
|
41
|
+
# ENTRYPOINT ["/usr/src/app/roro/docker-entrypoint.sh"]
|
42
|
+
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: mysql2
|
3
|
+
encoding: utf8
|
4
|
+
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
|
5
|
+
host: <%= ENV.fetch('DATABASE_HOST') %>
|
6
|
+
username: <%= ENV.fetch('MYSQL_USERNAME') %>
|
7
|
+
password: <%= ENV.fetch('MYSQL_PASSWORD') %>
|
8
|
+
database: <%= ENV.fetch('MYSQL_DATABASE') %>
|
9
|
+
port: <%= ENV.fetch('MYSQL_DATABASE_PORT') %>
|
10
|
+
socket: /var/run/mysqld/mysqlx.sock
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
|
15
|
+
test:
|
16
|
+
<<: *default
|
17
|
+
|
18
|
+
production:
|
19
|
+
<<: *default
|
File without changes
|