platter 0.0.4 → 0.2.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/README.md +5 -1
- data/lib/platter/app_builder.rb +55 -27
- data/lib/platter/generators/app_generator.rb +32 -13
- data/lib/platter/version.rb +3 -3
- data/platter.gemspec +3 -3
- data/templates/Gemfile.erb +1 -1
- data/templates/README.md.erb +112 -9
- data/templates/attach.erb +16 -0
- data/templates/check_or_setup_db.erb +46 -0
- data/templates/dev-entrypoint.sh +53 -0
- data/templates/docker-compose.yml.erb +84 -0
- data/templates/restoredb.erb +15 -0
- metadata +23 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 781b2551b4178026179da0ef1ac2b9d11ae03869
|
4
|
+
data.tar.gz: 667862351c3601f7c05aa955735b03be896b245e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad23068a0eacf32de5146530ddbf89307c80d1959e0124693d8cb03e80eb6ac5d8e239dbafcb0c9cd4826ca904a07e534c49464d80b773908399eb4c22da069
|
7
|
+
data.tar.gz: 0f73ef4a3331dc7b66a598c6c8cece7b483b3b834e09d823ed2a911750cce4aa36692f3f07cc5312aec5b14ac935e015bfd6e3de85ad042298a4bd76a09ee180
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[](https://codeclimate.com/github/IcaliaLabs/platter)
|
2
|
+
[](https://codeclimate.com/github/IcaliaLabs/platter/coverage)
|
3
|
+
[](https://codeclimate.com/github/IcaliaLabs/platter)
|
4
|
+
|
1
5
|
# [Platter](https://github.com/IcaliaLabs/platter)
|
2
6
|
|
3
7
|
[](http://badge.fury.io/rb/platter)
|
@@ -145,4 +149,4 @@ Keep track of new feautres, development issues and community news.
|
|
145
149
|
|
146
150
|
## Copyright and license
|
147
151
|
|
148
|
-
Code and documentation copyright 2013-2014 Icalia Labs. Code released under [the MIT license](LICENSE).
|
152
|
+
Code and documentation copyright 2013-2014 Icalia Labs. Code released under [the MIT license](LICENSE).
|
data/lib/platter/app_builder.rb
CHANGED
@@ -11,6 +11,14 @@ module Platter
|
|
11
11
|
template "Gemfile.erb", "Gemfile"
|
12
12
|
end
|
13
13
|
|
14
|
+
def setup_gems
|
15
|
+
run "docker-compose run --rm web bundle"
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup_db
|
19
|
+
run "docker-compose run --rm web rake db:create"
|
20
|
+
end
|
21
|
+
|
14
22
|
#API builds
|
15
23
|
#
|
16
24
|
def add_api_support
|
@@ -48,6 +56,35 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
48
56
|
git commit: "-m 'Project initialization using Platter'"
|
49
57
|
end
|
50
58
|
|
59
|
+
# Docker Build
|
60
|
+
#
|
61
|
+
def setup_docker_compose
|
62
|
+
template "docker-compose.yml.erb", "docker-compose.yml"
|
63
|
+
create_file "dev.env"
|
64
|
+
end
|
65
|
+
|
66
|
+
def provide_dev_entrypoint
|
67
|
+
template "dev-entrypoint.sh", "dev-entrypoint"
|
68
|
+
run "chmod a+x dev-entrypoint"
|
69
|
+
end
|
70
|
+
|
71
|
+
def provide_db_script
|
72
|
+
template "check_or_setup_db.erb", "bin/check_or_setup_db"
|
73
|
+
run "chmod a+x bin/check_or_setup_db"
|
74
|
+
end
|
75
|
+
|
76
|
+
def provide_attach_script
|
77
|
+
template "attach.erb", "bin/attach"
|
78
|
+
run "chmod a+x bin/attach"
|
79
|
+
end
|
80
|
+
|
81
|
+
def provide_restoredb_script
|
82
|
+
empty_directory "db/dumps"
|
83
|
+
create_file "db/dumps/.keep"
|
84
|
+
template "restoredb.erb", "bin/restoredb"
|
85
|
+
run "chmod a+x bin/restoredb"
|
86
|
+
end
|
87
|
+
|
51
88
|
#Server build
|
52
89
|
#
|
53
90
|
def setup_server
|
@@ -56,11 +93,6 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
56
93
|
|
57
94
|
# Development builds
|
58
95
|
#
|
59
|
-
def provide_development_setup_bin
|
60
|
-
template "bin_development_setup.rb", "bin/setup", port: PORT, force: true
|
61
|
-
run "chmod a+x bin/setup"
|
62
|
-
end
|
63
|
-
|
64
96
|
def setup_development_mail_delivery_strategy
|
65
97
|
inject_into_file "config/environments/development.rb",
|
66
98
|
%Q{
|
@@ -93,7 +125,7 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
93
125
|
g.javascripts false
|
94
126
|
g.helper false
|
95
127
|
end
|
96
|
-
|
128
|
+
|
97
129
|
config.autoload_paths += %W(#{config.root}/lib)
|
98
130
|
},
|
99
131
|
after: "config.active_record.raise_in_transactional_callbacks = true"
|
@@ -102,7 +134,7 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
102
134
|
#TEST builds
|
103
135
|
#
|
104
136
|
def init_rspec
|
105
|
-
|
137
|
+
run "docker-compose run --rm web rspec:install"
|
106
138
|
end
|
107
139
|
|
108
140
|
def add_support_rspec_files
|
@@ -118,29 +150,12 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
118
150
|
template "production_env.erb", "config/environments/staging.rb"
|
119
151
|
end
|
120
152
|
|
121
|
-
#ACTIVE JOB builds
|
122
|
-
#
|
123
|
-
def init_delayed_job
|
124
|
-
generate "delayed_job:active_record"
|
125
|
-
run `bundle exec rake db:create db:migrate`
|
126
|
-
end
|
127
|
-
|
128
|
-
def add_delayed_job_active_job_configuration
|
129
|
-
inject_into_file 'config/application.rb',
|
130
|
-
%q{
|
131
|
-
|
132
|
-
# ActiveJob Configuration
|
133
|
-
config.active_job.queue_adapter = :delayed_job
|
134
|
-
},
|
135
|
-
after: "config.active_record.raise_in_transactional_callbacks = true"
|
136
|
-
end
|
137
|
-
|
138
153
|
#MAILER builds
|
139
154
|
#
|
140
155
|
def init_sendgrid_initialize_file
|
141
156
|
template "mailer_initializer_config.erb", "config/initializers/mailer_setup.rb"
|
142
157
|
end
|
143
|
-
|
158
|
+
|
144
159
|
|
145
160
|
def add_exception_notification_mailer_configuration
|
146
161
|
%w{ production staging }.each do |env|
|
@@ -150,8 +165,8 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
150
165
|
#Exception Notification configuration
|
151
166
|
config.middleware.use ExceptionNotification::Rack,
|
152
167
|
:email => {
|
153
|
-
:email_prefix => "[
|
154
|
-
:sender_address => %{"
|
168
|
+
:email_prefix => "[#{app_name}] ",
|
169
|
+
:sender_address => %{"Exception" <exception@#{app_name.downcase}-#{env}.com>},
|
155
170
|
:exception_recipients => %w{}
|
156
171
|
}
|
157
172
|
},
|
@@ -171,5 +186,18 @@ gem "active_model_serializers", github: "rails-api/active_model_serializers", br
|
|
171
186
|
after: "config.active_record.dump_schema_after_migration = false"
|
172
187
|
end
|
173
188
|
end
|
189
|
+
|
190
|
+
def app
|
191
|
+
super
|
192
|
+
if options["skip_assets"]
|
193
|
+
remove_dir "app/assets"
|
194
|
+
remove_dir "app/views"
|
195
|
+
remove_dir "app/helpers"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def vendor_stylesheets
|
200
|
+
empty_directory_with_keep_file 'vendor/assets/stylesheets' unless options[:skip_assets]
|
201
|
+
end
|
174
202
|
end
|
175
203
|
end
|
@@ -3,6 +3,18 @@ require 'rails/generators/rails/app/app_generator'
|
|
3
3
|
|
4
4
|
module Platter
|
5
5
|
class AppGenerator < Rails::Generators::AppGenerator
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
super
|
9
|
+
if @options["api"]
|
10
|
+
backup_options = Marshal.load(Marshal.dump(@options))
|
11
|
+
backup_options["skip_javascript"] = true
|
12
|
+
backup_options["skip_sprockets"] = true
|
13
|
+
backup_options["skip_assets"] = true
|
14
|
+
@options = backup_options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
class_option :database, type: :string, aliases: "-d", default: "postgresql",
|
7
19
|
desc: "Configure for selected database. PostgreSQL by default."
|
8
20
|
|
@@ -15,9 +27,6 @@ module Platter
|
|
15
27
|
class_option :api, type: :boolean, default: false,
|
16
28
|
desc: "Adds API support gems"
|
17
29
|
|
18
|
-
class_option :skip_bundle, type: :boolean, aliases: "-B", default: true,
|
19
|
-
desc: "Don't run bundle install"
|
20
|
-
|
21
30
|
def finish_template
|
22
31
|
invoke :platter
|
23
32
|
super
|
@@ -26,19 +35,27 @@ module Platter
|
|
26
35
|
def platter
|
27
36
|
invoke :custom_gemfile
|
28
37
|
invoke :setup_development_environment
|
29
|
-
invoke :setup_test_environment
|
30
38
|
invoke :setup_staging_environment
|
31
|
-
invoke :add_active_job_configuration
|
32
39
|
invoke :add_api_support
|
33
40
|
invoke :setup_mailer
|
34
41
|
invoke :setup_server
|
42
|
+
invoke :setup_docker
|
43
|
+
invoke :setup_gems
|
44
|
+
invoke :setup_db
|
45
|
+
invoke :setup_test_environment
|
35
46
|
invoke :setup_git
|
36
47
|
end
|
37
48
|
|
38
49
|
def custom_gemfile
|
39
50
|
build :replace_gemfile
|
51
|
+
end
|
52
|
+
|
53
|
+
def setup_gems
|
54
|
+
build :setup_gems
|
55
|
+
end
|
40
56
|
|
41
|
-
|
57
|
+
def setup_db
|
58
|
+
build :setup_db
|
42
59
|
end
|
43
60
|
|
44
61
|
def add_api_support
|
@@ -62,9 +79,17 @@ module Platter
|
|
62
79
|
build :setup_server
|
63
80
|
end
|
64
81
|
|
82
|
+
def setup_docker
|
83
|
+
say "Adding docker-compose.yml file"
|
84
|
+
build :setup_docker_compose
|
85
|
+
build :provide_db_script
|
86
|
+
build :provide_dev_entrypoint
|
87
|
+
build :provide_attach_script
|
88
|
+
build :provide_restoredb_script
|
89
|
+
end
|
90
|
+
|
65
91
|
def setup_development_environment
|
66
92
|
say "Setting up the development environment"
|
67
|
-
build :provide_development_setup_bin
|
68
93
|
build :setup_development_mail_delivery_strategy
|
69
94
|
build :fix_i18n_deprecation_warning
|
70
95
|
build :provide_generators_configuration
|
@@ -81,12 +106,6 @@ module Platter
|
|
81
106
|
build :copy_production_env_to_staging
|
82
107
|
end
|
83
108
|
|
84
|
-
def add_active_job_configuration
|
85
|
-
say "Setting up ActiveJob with DelayedJob"
|
86
|
-
build :init_delayed_job
|
87
|
-
build :add_delayed_job_active_job_configuration
|
88
|
-
end
|
89
|
-
|
90
109
|
def setup_mailer
|
91
110
|
say "Setting up Sendgrid configuration"
|
92
111
|
build :init_sendgrid_initialize_file
|
data/lib/platter/version.rb
CHANGED
data/platter.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'platter/version'
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency "rails", "~> #{Platter::RAILS_VERSION}"
|
26
|
+
spec.add_dependency "thor"
|
27
27
|
end
|
data/templates/Gemfile.erb
CHANGED
@@ -3,13 +3,13 @@ source "https://rubygems.org"
|
|
3
3
|
ruby "<%= Platter::RUBY_VERSION %>"
|
4
4
|
|
5
5
|
gem "rails", "<%= Platter::RAILS_VERSION %>"
|
6
|
-
gem "delayed_job_active_record"
|
7
6
|
gem "jquery-rails"
|
8
7
|
gem "pg"
|
9
8
|
gem "sass-rails", "~> 5.0"
|
10
9
|
gem "coffee-rails", "~> 4.1.0"
|
11
10
|
gem "uglifier", ">= 1.3.0"
|
12
11
|
gem "puma"
|
12
|
+
gem "therubyracer"
|
13
13
|
|
14
14
|
group :development do
|
15
15
|
gem "spring"
|
data/templates/README.md.erb
CHANGED
@@ -1,19 +1,122 @@
|
|
1
|
-
# <%= app_name.humanize %>
|
1
|
+
# Run <%= app_name.humanize %> using Docker
|
2
2
|
|
3
|
-
|
3
|
+
This guide will help you get started to setup the project using Docker, and keep using it as part of your development process.
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
## Table of contents
|
6
|
+
- [Installing Docker](#installing-docker)
|
7
|
+
- [Running <%= app_name.humanize %>](#running-<%= app_name %>)
|
8
|
+
- [Stop <%= app_name.humanize %>](#stop-<%= app_name %>)
|
9
|
+
- [Restoring DB](#restoring-db)
|
10
|
+
- [Debugging](#debugging)
|
11
|
+
- [Icalia Guides](#icalia-guides)
|
7
12
|
|
8
|
-
|
13
|
+
## Installing Docker
|
9
14
|
|
10
|
-
|
15
|
+
The first thing you need to do before start is to install `Docker`
|
11
16
|
|
12
|
-
|
17
|
+
[https://www.docker.com/products/docker](https://www.docker.com/products/docker)
|
13
18
|
|
14
|
-
|
19
|
+
If Docker was successfully installed, you should be good to go.
|
15
20
|
|
16
|
-
|
21
|
+
## Running <%= app_name.humanize %>
|
22
|
+
|
23
|
+
To run <%= app_name.humanize %> you can simple execute the following command inside the project directory:
|
24
|
+
|
25
|
+
```
|
26
|
+
% docker-compose up -d
|
27
|
+
```
|
28
|
+
|
29
|
+
That command will lift every service <%= app_name.humanize %> needs, such as the `rails server`, `postgres`.
|
30
|
+
|
31
|
+
|
32
|
+
It may take a while before you see anything, you can follow the logs of the containers with:
|
33
|
+
|
34
|
+
```
|
35
|
+
% docker-compose logs
|
36
|
+
```
|
37
|
+
|
38
|
+
Once you see an output like this:
|
39
|
+
|
40
|
+
```
|
41
|
+
web_1 | => Booting Puma
|
42
|
+
web_1 | => Rails 4.2.0 application starting in development on http://0.0.0.0:3000
|
43
|
+
web_1 | => Run `rails server -h` for more startup options
|
44
|
+
web_1 | => Ctrl-C to shutdown server
|
45
|
+
web_1 | Puma starting in single mode...
|
46
|
+
web_1 | * Version 3.4.0 (ruby 2.2.5-p319), codename: Owl Bowl Brawl
|
47
|
+
web_1 | * Min threads: 0, max threads: 16
|
48
|
+
web_1 | * Environment: development
|
49
|
+
web_1 | * Listening on tcp://0.0.0.0:3000
|
50
|
+
web_1 | Use Ctrl-C to stop
|
51
|
+
```
|
52
|
+
|
53
|
+
This means the project is up and running. It is worth mention that the `docker-compose` command will create the database if is not there yet.
|
54
|
+
|
55
|
+
## Stop <%= app_name.humanize %>
|
56
|
+
|
57
|
+
In order to stop <%= app_name.humanize %> as a whole you can run:
|
58
|
+
|
59
|
+
```
|
60
|
+
% docker-compose stop
|
61
|
+
```
|
62
|
+
|
63
|
+
This will stop every container, but if you need to stop one in particular, you can specify it like:
|
64
|
+
|
65
|
+
```
|
66
|
+
% docker-compose stop web
|
67
|
+
```
|
68
|
+
|
69
|
+
`web` is the service name located on the `docker-compose.yml` file, there you can see the services name and stop each of them if you need to.
|
70
|
+
|
71
|
+
## Restoring DB
|
72
|
+
|
73
|
+
You probably won't be working with a blank database, so once you are able to run <%= app_name.humanize %> you can restore the database, to do it, first stop all services:
|
74
|
+
|
75
|
+
```
|
76
|
+
% docker-compose stop
|
77
|
+
```
|
78
|
+
|
79
|
+
Then just lift up the `db` service:
|
80
|
+
|
81
|
+
```
|
82
|
+
% docker-compose up -d db
|
83
|
+
```
|
84
|
+
|
85
|
+
The next step is to login to the database container:
|
86
|
+
|
87
|
+
```
|
88
|
+
% docker exec -ti <%= app_name.downcase %>_db_1 bash
|
89
|
+
```
|
90
|
+
|
91
|
+
This will open up a bash session in to the database container.
|
92
|
+
|
93
|
+
Up to this point we just need to download or ask the project leader for a database dump and copy under `<%= app_name %>/db/dumps`, this directory is mounted on the container, so you will be able to restore it with:
|
94
|
+
|
95
|
+
```
|
96
|
+
root@a3f695b39869:/# bin/restoredb <%= app_name.downcase %>_dev db/dumps/<databaseDump>
|
97
|
+
```
|
98
|
+
|
99
|
+
If you want to see how this script works, you can find it under `bin/restoredb`
|
100
|
+
|
101
|
+
Once the script finishes its execution you can just exit the session from the container and lift the other services:
|
102
|
+
|
103
|
+
```
|
104
|
+
% docker-compose up -d
|
105
|
+
```
|
106
|
+
|
107
|
+
## Debugging
|
108
|
+
|
109
|
+
We know you love to use `debugger`, and who doesn't, that's why we put together a script to attach the `web` container service into your terminal session.
|
110
|
+
|
111
|
+
What we mean by this, is that if you add a `debugger` or `binding.pry` on a part of the code, you can run:
|
112
|
+
|
113
|
+
```
|
114
|
+
% bin/attach web
|
115
|
+
```
|
116
|
+
|
117
|
+
This will display the logs from the rails app, as well as give you access to stop the execution on the debugging point as you would expect.
|
118
|
+
|
119
|
+
**Take note that if you kill this process you will kill the web service, and you will probably need to lift it up again.**
|
17
120
|
|
18
121
|
## Icalia Guides
|
19
122
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
set -e
|
3
|
+
|
4
|
+
SERVICE_NAME=$1
|
5
|
+
|
6
|
+
read -a ARR <<<$(docker-compose ps | grep "${SERVICE_NAME}_")
|
7
|
+
|
8
|
+
CONTAINER_NAME=${ARR[0]}
|
9
|
+
CONTAINER_STATUS=${ARR[$((${#ARR[@]}-2))]}
|
10
|
+
|
11
|
+
if [ -n "${CONTAINER_NAME}" ] && [ "${CONTAINER_STATUS}" = "Up" ]; then
|
12
|
+
echo "Attaching to running container ${CONTAINER_NAME}..."
|
13
|
+
docker attach ${CONTAINER_NAME}
|
14
|
+
else
|
15
|
+
echo "No running container for service '${SERVICE_NAME}'"
|
16
|
+
fi
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This script is used in the development environment with Docker to check if the
|
4
|
+
# app database exists, and runs the database setup if it doesn't, as it is the
|
5
|
+
# case when the project runs for the first time on the development machine.
|
6
|
+
#
|
7
|
+
# We are using this custom script instead of running the
|
8
|
+
# `rake db:version || rake db:setup` commands, as that currently leaves a
|
9
|
+
# couple of small ruby zombie processes running in the app container:
|
10
|
+
require "rubygems"
|
11
|
+
require "rake"
|
12
|
+
require "bundler"
|
13
|
+
|
14
|
+
Bundler.setup(:default)
|
15
|
+
|
16
|
+
require "active_record"
|
17
|
+
|
18
|
+
exit begin
|
19
|
+
connection_tries ||= 3
|
20
|
+
ActiveRecord::Base.establish_connection && ActiveRecord::Migrator.current_version
|
21
|
+
0
|
22
|
+
rescue PG::ConnectionBad
|
23
|
+
unless (connection_tries -= 1).zero?
|
24
|
+
puts "Retrying DB connection #{connection_tries} more times..."
|
25
|
+
sleep ENV.fetch("APP_SETUP_WAIT", "5").to_i
|
26
|
+
retry
|
27
|
+
end
|
28
|
+
1
|
29
|
+
rescue ActiveRecord::NoDatabaseError
|
30
|
+
|
31
|
+
include ActiveRecord::Tasks
|
32
|
+
|
33
|
+
DatabaseTasks.root = File.expand_path "../..", __FILE__
|
34
|
+
DatabaseTasks.db_dir = File.join DatabaseTasks.root, "db"
|
35
|
+
DatabaseTasks.env = ENV.fetch "ENV", ENV.fetch("RAILS_ENV", "development")
|
36
|
+
|
37
|
+
# Add model dirs to the autoload_paths for the seeder to run smoothly:
|
38
|
+
ActiveSupport::Dependencies.autoload_paths << File.join(DatabaseTasks.root, "app", "models", "concerns")
|
39
|
+
ActiveSupport::Dependencies.autoload_paths << File.join(DatabaseTasks.root, "app", "models")
|
40
|
+
|
41
|
+
return 2 unless DatabaseTasks.create_current
|
42
|
+
return 3 unless DatabaseTasks.load_schema_current
|
43
|
+
0
|
44
|
+
ensure
|
45
|
+
ActiveRecord::Base.clear_all_connections!
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
|
3
|
+
# The Docker App Container's development entrypoint.
|
4
|
+
# This is a script used by the project's Docker development environment to
|
5
|
+
# setup the app containers and databases upon runnning.
|
6
|
+
set -e
|
7
|
+
|
8
|
+
: ${APP_PATH:="/usr/src/app"}
|
9
|
+
: ${APP_TEMP_PATH:="$APP_PATH/tmp"}
|
10
|
+
: ${APP_SETUP_LOCK:="$APP_TEMP_PATH/setup.lock"}
|
11
|
+
: ${APP_SETUP_WAIT:="5"}
|
12
|
+
|
13
|
+
# 1: Define the functions lock and unlock our app containers setup processes:
|
14
|
+
function lock_setup { mkdir -p $APP_TEMP_PATH && touch $APP_SETUP_LOCK; }
|
15
|
+
function unlock_setup { rm -rf $APP_SETUP_LOCK; }
|
16
|
+
function wait_setup { echo "Waiting for app setup to finish..."; sleep $APP_SETUP_WAIT; }
|
17
|
+
|
18
|
+
# 2: 'Unlock' the setup process if the script exits prematurely:
|
19
|
+
trap unlock_setup HUP INT QUIT KILL TERM EXIT
|
20
|
+
|
21
|
+
# 3: Wait until the setup 'lock' file no longer exists:
|
22
|
+
while [ -f $APP_SETUP_LOCK ]; do wait_setup; done
|
23
|
+
|
24
|
+
# 4: 'Lock' the setup process, to prevent a race condition when the project's
|
25
|
+
# app containers will try to install gems and setup the database concurrently:
|
26
|
+
lock_setup
|
27
|
+
|
28
|
+
# 5: Check or install the app dependencies via Bundler:
|
29
|
+
bundle check || bundle
|
30
|
+
|
31
|
+
# 6: Check if the database exists, or setup the database if it doesn't, as it is
|
32
|
+
# the case when the project runs for the first time.
|
33
|
+
#
|
34
|
+
# We'll use a custom script `check-or-setup-db` (inside our app's `bin` folder),
|
35
|
+
# instead of running `rake db:version || rake db:setup`, as running that command
|
36
|
+
# (at least on rails 4.2.4) will leave a couple of small ruby zombie processes
|
37
|
+
# running in the container:
|
38
|
+
check_or_setup_db
|
39
|
+
|
40
|
+
# 7: 'Unlock' the setup process:
|
41
|
+
unlock_setup
|
42
|
+
|
43
|
+
# 8: Specify a default command, in case it wasn't issued:
|
44
|
+
if [ -z "$1" ]; then set -- rails server -p 3000 -b 0.0.0.0 "$@"; fi
|
45
|
+
|
46
|
+
# 9: If the command to execute is 'rails server', then force it to write the
|
47
|
+
# pid file into a non-shared container directory. Suddenly killing and removing
|
48
|
+
# app containers without this would leave a pidfile in the project's tmp dir,
|
49
|
+
# preventing the app container from starting up on further attempts:
|
50
|
+
if [[ "$1" = "rails" && ("$2" = "s" || "$2" = "server") ]]; then set -- "$@" -P /tmp/server.pid; fi
|
51
|
+
|
52
|
+
# 10: Execute the given or default command:
|
53
|
+
exec "$@"
|
@@ -0,0 +1,84 @@
|
|
1
|
+
version: '2'
|
2
|
+
|
3
|
+
volumes:
|
4
|
+
postgres-data:
|
5
|
+
driver: local
|
6
|
+
gems:
|
7
|
+
driver: local
|
8
|
+
|
9
|
+
services:
|
10
|
+
db:
|
11
|
+
image: postgres:9.5.1
|
12
|
+
ports:
|
13
|
+
# We'll bind our host's port 5432 to postgres's port 5432, so we can use
|
14
|
+
# our database IDEs with it:
|
15
|
+
- 5432:5432
|
16
|
+
volumes:
|
17
|
+
# We'll store the postgres data in the 'postgres-data' volume we defined:
|
18
|
+
- postgres-data:/var/lib/postgresql/data
|
19
|
+
- ./db/dumps:/db/dumps:ro # Mount the DB dumps folder
|
20
|
+
- ./bin/restoredb:/bin/restoredb:ro # Mount the 'restoredb' script
|
21
|
+
environment:
|
22
|
+
POSTGRES_PASSWORD: P4Ssw0rD!
|
23
|
+
|
24
|
+
# The job processor container - we'll use this as a base for the rest of the
|
25
|
+
# containers:
|
26
|
+
web: &app
|
27
|
+
image: ruby:2.2.5
|
28
|
+
command: rails server -b 0.0.0.0 -p 3000 -P /tmp/rails.pid
|
29
|
+
ports:
|
30
|
+
- 3000:3000
|
31
|
+
entrypoint: /usr/src/app/dev-entrypoint
|
32
|
+
volumes:
|
33
|
+
# Mount our app code directory (".") into our app containers at the
|
34
|
+
# "/usr/src/app" folder:
|
35
|
+
- .:/usr/src/app
|
36
|
+
|
37
|
+
# Mount the 'gems' volume on the folder that stores bundled gems:
|
38
|
+
- gems:/usr/local/bundle
|
39
|
+
|
40
|
+
# Specify the directory from where all commands sent to the container will be
|
41
|
+
# issued to where the code is mounted:
|
42
|
+
working_dir: /usr/src/app
|
43
|
+
|
44
|
+
# Keep the stdin open, so we can attach to our app container's process
|
45
|
+
# and do things such as byebug, etc:
|
46
|
+
stdin_open: true
|
47
|
+
|
48
|
+
# Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
|
49
|
+
tty: true
|
50
|
+
|
51
|
+
# Link to our postgres and redis containers, so they can be visible from our
|
52
|
+
# app containers:
|
53
|
+
links:
|
54
|
+
# We'll include a link to the 'db' (postgres) container, making it
|
55
|
+
# visible from the container using the 'db' hostname:
|
56
|
+
- db
|
57
|
+
|
58
|
+
# Specify environment variables available for our app containers. We'll leave
|
59
|
+
# a YML anchor in case we need to override or add more variables if needed on
|
60
|
+
# each app container:
|
61
|
+
environment: &app_environment
|
62
|
+
|
63
|
+
# We'll overwrite the PATH environment variable to include the 'bin/'
|
64
|
+
# directory, for the entrypoint script to find the app's executables:
|
65
|
+
PATH: /usr/src/app/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
66
|
+
|
67
|
+
# We'll set the DATABASE_URL environment variable for the app to connect
|
68
|
+
# to our postgres container - no need to use a 'config/database.yml' file.
|
69
|
+
DATABASE_URL: postgres://postgres:P4Ssw0rD!@db:5432/<%= app_name.downcase.underscore %>_dev?pool=25&encoding=unicode&schema_search_path=public,partitioning
|
70
|
+
|
71
|
+
# We'll set the RAILS_ENV and RACK_ENV environment variables to
|
72
|
+
# 'development', so our app containers will start in 'development' mode
|
73
|
+
# on this compose project:
|
74
|
+
RAILS_ENV: development
|
75
|
+
RACK_ENV: development
|
76
|
+
|
77
|
+
# We'll specify a dotenv file for docker-compose to load more environment
|
78
|
+
# variables into our app containers. This dotenv file would normally contain
|
79
|
+
# sensitive data (API keys & secrets, etc) which SHOULD NOT be committed into
|
80
|
+
# Git.
|
81
|
+
# Keep in mind that any changes in this file will require a container restart
|
82
|
+
# in order to be available on the app containers:
|
83
|
+
env_file:
|
84
|
+
- dev.env
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#! /bin/bash
|
2
|
+
|
3
|
+
# For use on the postgres container only.
|
4
|
+
# Usage:
|
5
|
+
# bin/restoredb <%= app_name.downcase.underscore %>_dev db/dumps/<your-dump-name>
|
6
|
+
set -e
|
7
|
+
|
8
|
+
: ${DB_NAME:=$1}
|
9
|
+
: ${DB_DUMP_PATH:=$2}
|
10
|
+
|
11
|
+
dropdb -U postgres -e --if-exists $1 && \
|
12
|
+
createdb -U postgres $1 && \
|
13
|
+
pg_restore -U postgres --dbname=$1 \
|
14
|
+
--clean --no-owner --no-privileges --verbose --jobs=2 \
|
15
|
+
$2
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Icalia Labs
|
@@ -9,65 +9,65 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '1.7'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.7'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '10.0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ~>
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '10.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rails
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ~>
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 4.2
|
48
|
+
version: '4.2'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 4.2
|
55
|
+
version: '4.2'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: thor
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
-
description:
|
70
|
+
description: ' A solution to create custom Rails apps used at @icalialabs '
|
71
71
|
email:
|
72
72
|
- kurenn@icalialabs.com
|
73
73
|
executables:
|
@@ -75,7 +75,7 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
-
|
78
|
+
- .gitignore
|
79
79
|
- CODE_OF_CONDUCT.md
|
80
80
|
- Gemfile
|
81
81
|
- LICENSE.txt
|
@@ -91,11 +91,16 @@ files:
|
|
91
91
|
- templates/Procfile
|
92
92
|
- templates/README.md.erb
|
93
93
|
- templates/api_routes.erb
|
94
|
+
- templates/attach.erb
|
94
95
|
- templates/base_api_controller.erb
|
95
96
|
- templates/bin_development_setup.rb
|
97
|
+
- templates/check_or_setup_db.erb
|
98
|
+
- templates/dev-entrypoint.sh
|
99
|
+
- templates/docker-compose.yml.erb
|
96
100
|
- templates/mailer_initializer_config.erb
|
97
101
|
- templates/platter_gitignore
|
98
102
|
- templates/production_env.erb
|
103
|
+
- templates/restoredb.erb
|
99
104
|
- templates/rspec_support_database_cleaner.erb
|
100
105
|
- templates/rspec_support_factory_girl.erb
|
101
106
|
- templates/rspec_support_i18n.erb
|
@@ -109,17 +114,17 @@ require_paths:
|
|
109
114
|
- lib
|
110
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
116
|
requirements:
|
112
|
-
- -
|
117
|
+
- - '>='
|
113
118
|
- !ruby/object:Gem::Version
|
114
|
-
version: 2.2.
|
119
|
+
version: 2.2.5
|
115
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
121
|
requirements:
|
117
|
-
- -
|
122
|
+
- - '>='
|
118
123
|
- !ruby/object:Gem::Version
|
119
124
|
version: '0'
|
120
125
|
requirements: []
|
121
126
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.6.6
|
123
128
|
signing_key:
|
124
129
|
specification_version: 4
|
125
130
|
summary: A solution to create custom Rails apps used at @icalialabs
|