Skip to content

Instantly share code, notes, and snippets.

@dlinch
Forked from jejacks0n/rails_template.rb
Last active May 10, 2018 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlinch/2fab32036a1a2e2b2c0f19078898ea55 to your computer and use it in GitHub Desktop.
Save dlinch/2fab32036a1a2e2b2c0f19078898ea55 to your computer and use it in GitHub Desktop.
# rails new appname --skip-bundle --skip-coffee --skip-test --webpack=vue --database=postgresql -m https://gist.githubusercontent.com/jejacks0n/bba5fe8bec67c85da41345b414e77dc1/raw/57faf214d548d2f8714756544e5fd6609ae2ee91/rails_template.rb
# SETUP README ---------------------------------------------------------------------------------------------------------
remove_file "README.md"
file "README.md", <<-MARKDOWN.strip_heredoc
#{app_name}
#{"=" * app_name.length}
#### Initial Project Setup (delete this section when done)
To start, check out `app/javascript/packs/hello_vue.js` to see the various ways to hook up Vue to the project.
- Follow the directioins there to get started.
- If you want to enable hot module reloading, set `hrm: true` in `config/webpacker.yml`.
One Paragraph/sentence of project description goes here.
### Key Notes
Notes that are helpful to the project, such as:
- Using JIRA for tickets
- JSON comes from client managed CMS (that we don't have access to)
## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
## Built With
- [Rails](https://rubyonrails.org)
- Webpacker
- Vue
### Prerequisites
What things you need to install the software and how to install them
```
Give examples
```
### Installing
A step by step series of examples that tell you have to get a development env running
```
Give the example
```
And repeat
```
until finished
```
## Deployment
Add additional notes about how to deploy this on a live system. Like gulp tasks, if we can even deploy, so on.
### Environments
- Staging: AWS
- Link to the staging site
- Is there a login for staging, if so, where is it?
- Production: Hosted by client on a server in their closet
- Link to production
- Is there a login for productions, if so, where is it?
## Point(s) of Contact
Legwork:
- Sally Gamflexer ( lead front-end on project )
- sally@legworkstudio.com
- Bob Armslacker ( lead back-end on project )
- bob@legworkstudio.com
Client Side:
- Steve McClient ( tech lead for [project] )
- steve@clientssite.com
---
![Legwork Studio](http://www.legworkstudio.com/images/logo@2x.gif "I know what you're thinkin'.")
NOT AFRAID OF THE STACK
MARKDOWN
# DOCKER BASH EXECUTABLE ----------------------------------------------------------------------------------------------
file 'bin/docker-rails', <<-BASH.strip_heredoc
#!/bin/bash
docker exec -it "#{@app_name}_app" bash
BASH
# UPDATE CONTENT_SECURITY_POLICY --------------------------------------------------------------------------------------
inside 'config/initializers' do
inject_into_file 'content_security_policy.rb', after: "# Rails.application.config.content_security_policy_report_only = true\n" do
<<-RUBY.strip_heredoc
Rails.application.config.content_security_policy do |policy|
if Rails.env.development?
policy.script_src :self, :https, :unsafe_eval
else
policy.script_src :self, :https
end
end
RUBY
end
end
# GEMS / MORE SETUP ---------------------------------------------------------------------------------------------------
# add_source "http://gems.github.com/"
# git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem_group :development, :test do
gem "rspec-rails"
end
# DOCKER --------------------------------------------------------------------------------------------------------------
# TODO: upgrade to version 3.6 or so
file "docker-compose.yml", <<-YAML
version: '2'
services:
postgres:
container_name: #{app_name}_postgres
image: postgres:latest
environment:
- POSTGRES_USER=dev
- POSTGRES_PASSWORD=53cr37
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
container_name: #{app_name}_redis
image: redis:latest
ports:
- "6379:6379"
app:
container_name: #{app_name}_app
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle install && bundle exec rails db:create db:migrate && bundle exec rails s"
environment:
- DB_CONNECTION_STRING=postgresql://dev:53cr37@postgres
volumes:
- .:/app
- /node_modules
depends_on:
- postgres
- redis
ports:
- "3000:3000"
- "3035:3035"
volumes:
postgres-data:
YAML
file "Dockerfile", <<-DOCKERFILE
FROM starefossen/ruby-node:latest
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN bundle install
DOCKERFILE
remove_file "config/database.yml"
file "config/database.yml", <<-YAML
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
url: <%= ENV["DATABASE_URL"] || ENV["DB_CONNECTION_STRING"] %>
pool: 5
development:
<<: *default
database: #{app_name}_development
test:
<<: *default
database: #{app_name}_test
production:
<<: *default
YAML
# FINALIZE ------------------------------------------------------------------------------------------------------------
run "docker-compose build"
run "docker-compose run app rails webpacker:install"
run "docker-compose run app rails webpacker:install:vue"
run "docker-compose run app rails generate rspec:install"
git add: "."
git commit: %Q{ -m 'Initial commit' }
run "docker-compose up"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment