forked from Shopify/shipit-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.rb
More file actions
150 lines (126 loc) · 4.31 KB
/
Copy pathtemplate.rb
File metadata and controls
150 lines (126 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Template for rails new app
# Run this like `rails new shipit -m template.rb`
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
raise Thor::Error, "You need at least Ruby 2.2.2 to install shipit"
end
if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('5.0.0')
raise Thor::Error, "You need at least Rails 5.0.0 to install shipit"
end
route %(mount Shipit::Engine, at: '/')
gem 'sidekiq'
gem 'thin'
gem 'shipit-engine', '>= 0.13'
gem 'dotenv-rails'
gem 'redis-rails'
gem_group :development do
gem 'therubyracer'
end
say("These configs are for development, you will have to generate them again for production.",
Thor::Shell::Color::GREEN, true)
say("Shipit requires a GitHub application to authenticate users. "\
"If you haven't created an application on GitHub yet, you can do so at https://github.com/settings/applications/new",
Thor::Shell::Color::GREEN, true)
github_id = ask("What is the application client ID?")
github_secret = ask("What is the application client secret?")
say("Shipit needs API access to GitHub.")
say("Create an API key at https://github.com/settings/tokens/new that has these permissions: "\
"admin:repo_hook, admin:org_hook, repo", Thor::Shell::Color::GREEN, true)
github_token = ask("What is the github key?")
create_file '.env', <<-CODE
GITHUB_OAUTH_ID=#{github_id}
GITHUB_OAUTH_SECRET=#{github_secret}
GITHUB_API_TOKEN=#{github_token}
PORT=3000
CODE
create_file 'Procfile', <<-CODE
web: bundle exec rails s -p $PORT
worker: bundle exec sidekiq -C config/sidekiq.yml
CODE
environment 'config.cache_store = :redis_store, Shipit.redis_url.to_s, { expires_in: 90.minutes }', env: :production
remove_file 'config/database.yml'
create_file 'config/database.yml', <<-CODE
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
url: <%= ENV['DATABASE_URL'] %>
pool: <%= ENV['DB_POOL'] || 5 %>
CODE
create_file 'config/sidekiq.yml', <<-CODE
:concurrency: 1
:queues:
- default
- deploys
- hooks
CODE
create_file 'config/secrets.yml', <<-CODE, force: true
development:
secret_key_base: #{SecureRandom.hex(64)}
host: 'http://localhost:3000'
github_oauth: # Head to https://github.com/settings/applications/new to generate oauth credentials
id: <%= ENV['GITHUB_OAUTH_ID'] %>
secret: <%= ENV['GITHUB_OAUTH_SECRET'] %>
# team: MyOrg/developers # Enable this setting to restrict access to only the member of a team
github_api:
access_token: <%= ENV['GITHUB_API_TOKEN'] %>
redis_url: redis://localhost
test:
secret_key_base: #{SecureRandom.hex(64)}
host: 'http://localhost:4000'
github_oauth:
id: 1d
secret: s3cr3t
github_api:
access_token: t0k3n
redis_url: redis://localhost
production:
secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
host: <%= ENV['SHIPIT_HOST'] %>
github_oauth:
id: <%= ENV['GITHUB_OAUTH_ID'] %>
secret: <%= ENV['GITHUB_OAUTH_SECRET'] %>
# team: MyOrg/developers # Enable this setting to restrict access to only the member of a team
github_api:
access_token: <%= ENV['GITHUB_API_TOKEN'] %>
redis_url: <%= ENV['REDIS_URL'] %>
env:
# SSH_AUTH_SOCK: /foo/bar # You can set environment variable that will be present during deploys.
CODE
initializer 'sidekiq.rb', <<-CODE
Rails.application.config.active_job.queue_adapter = :sidekiq
Sidekiq.configure_server do |config|
config.redis = { url: Shipit.redis_url.to_s }
end
Sidekiq.configure_client do |config|
config.redis = { url: Shipit.redis_url.to_s }
end
CODE
if yes?("Are you hosting Shipit on Heroku? (y/n)")
inject_into_file "Gemfile", "ruby '#{RUBY_VERSION}'", after: "source 'https://rubygems.org'\n"
gsub_file 'Gemfile', "# Use sqlite3 as the database for Active Record", ''
gsub_file 'Gemfile', "gem 'sqlite3'", ''
gem_group :production do
gem 'pg'
gem 'rails_12factor'
end
gem_group :development, :test do
gem 'sqlite3'
end
end
after_bundle do
run 'bundle exec rake railties:install:migrations db:create db:migrate'
git :init
run "echo '.env' >> .gitignore"
git add: '.'
git commit: "-a -m 'Initial commit'"
end