Skip to content

Commit

Permalink
docker update
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiru Njuguna committed Oct 28, 2018
1 parent 55de850 commit 8a70ad5
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 119 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
natra (0.0.2)
natra (0.0.3)
activesupport (~> 5.0)
thor (~> 0.18)

Expand Down
5 changes: 2 additions & 3 deletions lib/natra/generators/app/app_generator.rb
Expand Up @@ -9,7 +9,6 @@ class AppGenerator < Thor::Group
desc "Creates a new Sinatra application"
argument :name, :type => :string, :desc => "The name of the new application"
class_option :capistrano, :type => :boolean, :desc => "Include Capistrano configuration"
class_option :database, :aliases => "-d", :default => "", :desc => "The type of database to use"
class_option :redis, :type => :boolean, :desc => "Include Redis configuration"
class_option :rvm, :type => :boolean, :desc => "Create .ruby-version (ruby-2.1.0) and .ruby-gemset"
class_option :bundle, :type => :boolean, :desc => "Run bundle after generating the app"
Expand Down Expand Up @@ -76,11 +75,11 @@ def create_readme
end

def create_db_config
template("config/db.yml", File.join(@app_path, "config/db.yml")) unless @database.empty?
template("config/db.yml", File.join(@app_path, "config/db.yml"))
end

def create_database_initializer
template("config/initializers/database.rb", File.join(@app_path, "config/initializers/database.rb")) unless @database.empty?
template("config/initializers/database.rb", File.join(@app_path, "config/initializers/database.rb"))
end

def create_redis_config
Expand Down
5 changes: 1 addition & 4 deletions lib/natra/generators/app/templates/Dockerfile
@@ -1,4 +1,3 @@
# base layer
FROM ruby AS base

WORKDIR /usr/src/app
Expand All @@ -7,18 +6,16 @@ RUN gem install bundler

COPY Gemfile /usr/src/app/

# development and test layer with all dependencies
FROM base AS development

RUN bundle install -j5 --without staging production

COPY . /usr/src/app

# release layer
FROM base AS release

RUN bundle install -j5 --without development test

COPY . /usr/src/app

CMD puma
CMD puma
1 change: 0 additions & 1 deletion lib/natra/generators/app/templates/Gemfile
Expand Up @@ -16,7 +16,6 @@ gem 'bcrypt'
gem "tux"
gem 'oj'
group :development, :test do
gem 'pry'
gem 'pry-byebug'
gem 'shotgun'
end
Expand Down
14 changes: 1 addition & 13 deletions lib/natra/generators/app/templates/app/views/welcome.erb
@@ -1,22 +1,10 @@
<div class="container">
<div class="col-md-8 col-md-offset-2">
<h2>Sinatra Template Default Page</h2>

<div class="content">
<p>Welcome to the Sinatra Template! If you're seeing this page, then everything is working
as expected. To get started, delete this file (<code>app/views/welcome.erb)</code> and begin adding
your own actions to <code>application_controller.rb</code>. For more information, see the <a href="https://github.com/thirunjuguna/natra">README</a>.</p>
</div>

<div class="sidebar">
<h3>Environment</h3>
<ul>
<li><b>Ruby:</b> <%= RUBY_VERSION %></li>
<li><b>Environment:</b> <%= ENV["RACK_ENV"] %></li>
<li><b>Server:</b> <%= @env["SERVER_SOFTWARE"] %></li>
<li><b>Port:</b> <%= @env["SERVER_PORT"] %></li>
<li><b>Help:</b>see the <a href="https://github.com/thirunjuguna/natra">README</a> </li>
</ul>
</div>

</div>
</div>
2 changes: 1 addition & 1 deletion lib/natra/generators/app/templates/bin/ci
Expand Up @@ -2,5 +2,5 @@

set -e

RACK_ENV=test DATABASE_URL=$TEST_DATABASE_URL rake db:create db:migrate --trace
SINATRA_ENV=test DATABASE_URL=$TEST_DATABASE_URL rake db:create db:migrate --trace

6 changes: 3 additions & 3 deletions lib/natra/generators/app/templates/bin/setup
Expand Up @@ -2,6 +2,6 @@

set -e

RACK_ENV=development rake db:create db:migrate --trace
RACK_ENV=development rake db:seed_fu --trace
RACK_ENV=test DATABASE_URL=$TEST_DATABASE_URL rake db:create db:migrate --trace
SINATRA_ENV=development rake db:create db:migrate --trace
SINATRA_ENV=development rake db:seed_fu --trace
SINATRA_ENV=test DATABASE_URL=$TEST_DATABASE_URL rake db:create db:migrate --trace
2 changes: 1 addition & 1 deletion lib/natra/generators/app/templates/config.ru
Expand Up @@ -2,7 +2,7 @@ require './config/environment'
# Call as early as possible so rack-timeout runs before all other middleware.
use Rack::Timeout, service_timeout: 5

ScoutApm::Rack.install
ScoutApm::Rack.install!

if ActiveRecord::Migrator.needs_migration?
raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
Expand Down
37 changes: 3 additions & 34 deletions lib/natra/generators/app/templates/config/db.yml
@@ -1,35 +1,4 @@
# Sequel Database Configuration
<% if @database == "sqlite" %>
development: "sqlite://db/development.sqlite3"
test: "sqlite://db/test.sqlite3"
production: "sqlite://db/production.sqlite3"
<% elsif @database == "postgres" %>
development: "postgres://<%= `whoami`.chop %>@localhost/<%= @name %>_development"
test: "postgres://<%= `whoami`.chop %>@localhost/<%= @name %>_test"
production: "postgres://<%= `whoami`.chop %>@localhost/<%= @name %>_production"
<% elsif @database == "mysql" %>
development: "mysql2://<%= `whoami`.chop %>@localhost/<%= @name %>_development"
test: "mysql2://<%= `whoami`.chop %>@localhost/<%= @name %>_test"
production: "mysql2://<%= `whoami`.chop %>@localhost/<%= @name %>_production"
<% elsif @database == "mongo" %>
development:
host: localhost
port: 27017
database: <%= @name %>_development
username:
password:

test:
host: localhost
port: 27017
database: <%= @name %>_test
username:
password:

production:
host: localhost
port: 27017
database: <%= @name %>_production
username:
password:
<% end %>
development: ENV['DEV_DATABASE_URL']
test: ENV['TEST_DATABASE_URL']
production: ENV['PROD_DATABASE_URL']
5 changes: 1 addition & 4 deletions lib/natra/generators/app/templates/config/environment.rb
Expand Up @@ -10,10 +10,7 @@
require 'scout_apm'

require 'oj'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "db/#{ENV['SINATRA_ENV']}.sqlite"
)
ActiveRecord::Base.establish_connection(ENV['DEV_DATABASE_URL'])

require './app/controllers/application_controller'
require_all 'app'
@@ -1,11 +1,7 @@
<% unless @database.empty? -%>

require "yaml"
settings = YAML::load_file("config/db.yml")
<% if @database != 'mongo' -%>
# Sequel Configuration

require "sequel"
DB = Sequel.connect(settings[ENV['RACK_ENV']])
<% else -%>
# MongoDB Configuration
<% end -%>
<% end -%>
DB = Sequel.connect(settings[ENV['SINATRA_ENV']])

@@ -1,7 +1,7 @@
require "yaml"

# Redis Configuration
unless ENV['RACK_ENV'] == 'test'
unless ENV['SINATRA_ENV'] == 'test'
redis_settings = YAML::load_file("config/redis.yml")
REDIS = Redis.new(redis_settings[ENV['RACK_ENV']])
REDIS = Redis.new(redis_settings[ENV['SINATRA_ENV']])
end
2 changes: 1 addition & 1 deletion lib/natra/generators/app/templates/config/puma.rb
Expand Up @@ -6,6 +6,6 @@

preload_app!

environment ENV['RACK_ENV'] || 'development'
environment ENV['SINATRA_ENV'] || 'development'

bind "tcp://0.0.0.0:#{port}"
2 changes: 0 additions & 2 deletions lib/natra/generators/app/templates/docker-compose.yml
Expand Up @@ -14,9 +14,7 @@ services:
- db
env_file: secrets.env
db:
<%- if @database=='postgres' -%>
image: postgres:10-alpine
ports:
- "54329:5432"
env_file: secrets.env
<%- end -%>
6 changes: 0 additions & 6 deletions lib/natra/generators/app/templates/gitignore
@@ -1,12 +1,6 @@
/tmp
/log
/log
*.swp
*.swo
.rspec_status
coverage

client/Gemfile.lock

secrets.aes
secrets.env
29 changes: 0 additions & 29 deletions lib/natra/generators/app/templates/rubocop.yml
Expand Up @@ -6,62 +6,33 @@ AllCops:
- tmp/**

Documentation:
# don't require classes to be documented
Enabled: false

Style/FrozenStringLiteralComment:
# don't require frozen literal comment
Enabled: false

Encoding:
# no need to always specify encoding
Enabled: false

AlignParameters:
# allow for multi-line methods to have normal indentation.
# for example:
#
# Person.where(
# first_name: 'tom',
# last_name: 'foolery'
# )
EnforcedStyle: with_fixed_indentation

Layout/AlignParameters:
# allow for end of if to be aligned with a variable.
# for example:
#
# foo = if a == b
# 'bar'
# else
# 'baz'
# end
EnforcedStyle: with_fixed_indentation

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/MultilineOperationIndentation:
# allow for operations to be indented at two spaces.
# for example:
#
# @valid ||= present &&
# positive?
EnforcedStyle: indented

Layout/EndAlignment:
EnforcedStyleAlignWith: variable

ClassAndModuleChildren:
# ok to use compact style when modules are predefined.
# for example the following is fine so long as we're sure that
# module MDB has already been required/defined.
#
# class MDB::Person; end
Enabled: false

Metrics/BlockLength:
# Certain DSL use blocks and can be lengthy
Exclude:
- 'spec/**/*'
- 'Guardfile'
Expand Down
9 changes: 4 additions & 5 deletions lib/natra/generators/app/templates/secrets.env
@@ -1,9 +1,8 @@
SINATRA_ENV=development
LOG_LEVEL=Logger::INFO
<%- if @database=='postgres' -%>
DATABASE_URL=postgresql://docker:docker@db:5432/<%= @name.camel_case %>?pool=5
DEV_DATABASE_URL=postgresql://docker:docker@db:5432/<%= @name.camel_case %>_dev?pool=5
PROD_DATABASE_URL=postgresql://docker:docker@db:5432/<%= @name.camel_case %>_prod?pool=5
TEST_DATABASE_URL=postgresql://docker:docker@db:5432/<%= @name.camel_case %>_test?pool=5
POSTGRES_USER=docker
POSTGRES_PASSWORD=docker
POSTGRES_DB=<%= @name.camel_case %>
<%- end -%>

POSTGRES_DB=<%= @name.camel_case %>_dev
2 changes: 1 addition & 1 deletion lib/natra/version.rb
@@ -1,3 +1,3 @@
module Natra
VERSION = '0.0.2'.freeze
VERSION = '0.0.3'.freeze
end

0 comments on commit 8a70ad5

Please sign in to comment.