stack_car 0.3.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2331786a667cdd1c925669949212b88fc6b9c9a6
4
- data.tar.gz: db83a6aa549e9f2dce0b61e9c2cbd0ffc3cc5ee7
3
+ metadata.gz: 4a4a19481f704f1a40f92ca1b5cc0a6ddc43894c
4
+ data.tar.gz: 17075ff12216327ab447110ca5b97a612a75fbe4
5
5
  SHA512:
6
- metadata.gz: c36afa299abfc85fdfaa533fbff3c2a787619d76e369c91b5b10284a94349fc38e8bb8c710759eedba0ffbf3fe4e93c93e3c4ed4d88c9b1b6f2f876676c4245f
7
- data.tar.gz: 52f60ba42b4939e897e4382de82bb2dd8b083f9aa749ae1e90089ab8c836f08d8b6c8af52fe8ac971a5c87683059f7921349e6e03223eed7e144b2a8fe03ccc0
6
+ metadata.gz: 8b1a2102d81567db1df3c17a35b68fa9f15e76cee641c971ba76a041469a05b3733e7c54c31faf36432c6367ffe82a887a462cf52f40031590ecb8f9b8b82d7c
7
+ data.tar.gz: c49be685b989964efa6e7469a98f9f31e6c1932e1d77a6a3869f9d84c0264b739b5d96c8d88bf4da367ee6f572a8a6ec2441644a599d27e6a36e380ed0788c42
data/README.md CHANGED
@@ -8,7 +8,6 @@ Stack Car is an opinionated set of tools around Docker and Rails. It provides c
8
8
  ## Installation
9
9
 
10
10
  Because stack_car will be used to run your application in side of Docker, you want to install stack car in to your system Ruby instead of putting in your applications Gemfile
11
- u
12
11
 
13
12
  ```bash
14
13
  gem install stack_car
@@ -16,12 +15,11 @@ gem install stack_car
16
15
 
17
16
  ## Usage
18
17
 
19
-
20
- Commands are accesible via the "sc" short cut. Note: this will need to be in your command path in front of the spreadsheet command (sc), which is a fairly archaiac unix spreadsheet tool. We're guessing you don't edit a lot of spreadsheets in your terminal, but if you do, we also figure you can override your path order pretty easily.
18
+ Commands are accesible via the "sc" short cut. Note: this will need to be in your command path in front of the spreadsheet command (sc), which is a fairly archaiac unix spreadsheet tool. We're guessing you don't edit a lot of spreadsheets in your terminal, but if you do, we also figure you can override your path order pretty easily. Many of these commands have short versions or alias to make remembering them easier. If there are obvious aliases missing, PRs are welcome.
21
19
 
22
20
  ```ruby
23
21
  Commands:
24
- stack_car bundle_exec ARGS # wraps docker-compose exec web bundle exec unless --service is used to specify
22
+ stack_car bundle_exec ARGS # wraps docker-compose exec web bundle exec unless --service is used to specify (sc be ARGS)
25
23
  stack_car console ARGS # shortcut to start rails console
26
24
  stack_car dockerize DIR # Will copy the docker tempates in to your project, see options for supported dependencies
27
25
  stack_car exec ARGS # wraps docker-compose exec web unless --service is used to specify
data/lib/stack_car/cli.rb CHANGED
@@ -10,6 +10,10 @@ module StackCar
10
10
  File.join(File.dirname(__FILE__), '..', '..', 'templates')
11
11
  end
12
12
 
13
+ def self.exit_on_failure?
14
+ true
15
+ end
16
+
13
17
  method_option :service, default: 'web', type: :string, aliases: '-s'
14
18
  method_option :build, default: false, type: :boolean, aliases: '-b'
15
19
  method_option :logs, default: true, type: :boolean
@@ -30,6 +34,7 @@ module StackCar
30
34
  run("docker-compose stop #{options[:service]}")
31
35
  run("rm -rf tmp/pids/*")
32
36
  end
37
+ map down: :stop
33
38
 
34
39
  method_option :service, default: 'web', type: :string, aliases: '-s'
35
40
  desc "build", "builds specified service, defaults to web"
@@ -92,6 +97,7 @@ module StackCar
92
97
  desc "release ENVIRONTMENT", "tag and push and image to the registry"
93
98
  def release(environment)
94
99
  timestamp = Time.now.strftime("%Y%m%d%I%M%S")
100
+ sha = `git rev-parse HEAD`[0-7]
95
101
  registry = "#{ENV['REGISTRY_HOST']}#{ENV['REGISTRY_URI']}"
96
102
  tag = ENV["TAG"] || 'latest'
97
103
  unless File.exists?("#{ENV['HOME']}/.docker/config.json") && File.readlines("#{ENV['HOME']}/.docker/config.json").grep(/#{ENV['REGISTRY_HOST']}/).size > 0
@@ -99,6 +105,8 @@ module StackCar
99
105
  end
100
106
  run("docker tag #{registry}:#{tag} #{registry}:#{environment}-#{timestamp}")
101
107
  run("docker push #{registry}:#{environment}-#{timestamp}")
108
+ run("docker tag #{registry}:#{tag} #{registry}:#{sha}")
109
+ run("docker push #{registry}:#{sha}")
102
110
  run("docker tag #{registry}:#{tag} #{registry}:#{environment}-latest")
103
111
  run("docker push #{registry}:#{environment}-latest")
104
112
  run("docker tag #{registry}:#{tag} #{registry}:latest")
@@ -107,10 +115,10 @@ module StackCar
107
115
 
108
116
  desc "provision ENVIRONMENT", "configure the servers for docker and then deploy an image"
109
117
  def provision(environment)
110
- run("ansible-playbook -i ops/hosts -l #{environment}:localhost ops/provision.yml")
118
+ # TODO make dotenv load a specific environment?
119
+ run("dotenv ansible-playbook -i ops/hosts -l #{environment}:localhost ops/provision.yml")
111
120
  end
112
121
 
113
- method_option :service, default: 'web', type: :string, aliases: '-s'
114
122
  desc "ssh ENVIRONMENT", "log in to a running instance - requires PRODUCTION_SSH to be set"
115
123
  def ssh(environment)
116
124
  target = ENV["#{environment.upcase}_SSH"]
@@ -123,7 +131,7 @@ module StackCar
123
131
 
124
132
  desc "deploy ENVIRONMENT", "deploy an image from the registry"
125
133
  def deploy(environment)
126
- run("ansible-playbook -i ops/hosts -l #{environment}:localhost ops/deploy.yml")
134
+ run("dotenv ansible-playbook -i ops/hosts -l #{environment}:localhost ops/deploy.yml")
127
135
  end
128
136
 
129
137
  method_option :elasticsearch, default: false, type: :boolean, aliases: '-e'
@@ -139,6 +147,7 @@ module StackCar
139
147
  method_option :sidekiq, default: false, type: :boolean, aliases: '-sq' # TODO
140
148
  method_option :mongodb, default: false, type: :boolean, aliases: '-mg'
141
149
  method_option :memcached, default: false, type: :boolean, aliases: '-mc'
150
+ method_option :yarn, default: false, type: :boolean, aliases: '-y'
142
151
  desc 'dockerize DIR', 'Will copy the docker tempates in to your project, see options for supported dependencies'
143
152
  long_desc <<-DOCKERIZE
144
153
 
@@ -149,20 +158,34 @@ module StackCar
149
158
  def dockerize(dir=".")
150
159
  Dir.chdir(dir)
151
160
  @project_name = File.basename(File.expand_path(dir))
152
- @db_libs = []
153
- @db_libs << "libpq-dev postgresql-client" if options[:postgres]
154
- @db_libs << "mysql-client" if options[:mysql]
155
- @db_libs << "libc6-dev libreoffice imagemagick unzip" if options[:fcrepo]
156
- @db_libs = @db_libs.join(' ')
161
+ apt_packages << "libpq-dev postgresql-client" if options[:postgres]
162
+ apt_packages << "mysql-client" if options[:mysql]
163
+ pre_apt << "echo 'Downloading Packages'"
164
+ post_apt << "echo 'Packages Downloaded'"
165
+
166
+ if options[:yarn]
167
+ apt_packages << 'yarn'
168
+ pre_apt << "curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -"
169
+ pre_apt << "echo 'deb https://dl.yarnpkg.com/debian/ stable main' | tee /etc/apt/sources.list.d/yarn.list"
170
+ post_apt << "yarn config set no-progress"
171
+ post_apt << "yarn config set silent"
172
+ end
173
+
174
+ if options[:fcrepo]
175
+ apt_packages << "libc6-dev libreoffice imagemagick unzip ghostscript ffmpeg"
157
176
 
177
+ post_apt << "mkdir -p /opt/fits"
178
+ post_apt << "curl -fSL -o /opt/fits-1.0.5.zip http://projects.iq.harvard.edu/files/fits/files/fits-1.0.5.zip"
179
+ post_apt << "cd /opt && unzip fits-1.0.5.zip && chmod +X fits-1.0.5/fits.sh"
180
+ end
158
181
 
159
- ['.dockerignore', 'Dockerfile', 'docker-compose.yml', 'docker-compose-ci.yml', 'docker-compose-prod.yml', '.gitlab-ci.yml', '.env'].each do |template_file|
182
+ ['.dockerignore', 'Dockerfile', 'Dockerfile.base', 'docker-compose.yml', 'docker-compose.ci.yml', 'docker-compose.production.yml', '.gitlab-ci.yml', '.env'].each do |template_file|
160
183
  puts template_file
161
184
  template("#{template_file}.erb", template_file)
162
185
  end
163
186
  template("database.yml.erb", "config/database.yml")
164
- template(".env.erb", ".env-example")
165
- template(".env.erb", ".env-prod")
187
+ template(".env.development.erb", ".env.development")
188
+ template(".env.erb", ".env.production")
166
189
 
167
190
  if File.exists?('README.md')
168
191
  prepend_to_file "README.md" do
@@ -173,9 +196,10 @@ module StackCar
173
196
  File.read("#{self.class.source_root}/README.md")
174
197
  end
175
198
  end
199
+ append_to_file("Gemfile", "gem 'activerecord-nulldb-adapter'")
176
200
  if options[:deploy] || options[:rancher]
177
201
  directory('ops')
178
- ['hosts'].each do |template_file|
202
+ ['hosts', 'deploy.yml', 'provision.yml'].each do |template_file|
179
203
  template("#{template_file}.erb", "ops/#{template_file}")
180
204
  end
181
205
  say 'Please update ops/hosts with the correct server addresses'
@@ -187,6 +211,8 @@ module StackCar
187
211
  ['env.conf', 'webapp.conf', 'worker.sh', 'nginx.sh'].each do |template_file|
188
212
  template("#{template_file}.erb", "ops/#{template_file}")
189
213
  end
214
+
215
+ say 'Please find and replace all CHANGEME lines'
190
216
  end
191
217
 
192
218
  protected
@@ -200,5 +226,30 @@ module StackCar
200
226
  end
201
227
  return @compose_depends.join("\n")
202
228
  end
229
+
230
+ def apt_packages
231
+ @apt_packages ||= []
232
+ end
233
+
234
+ def apt_packages_string
235
+ apt_packages.join(" ")
236
+ end
237
+
238
+ def pre_apt
239
+ @pre_apt ||= []
240
+ end
241
+
242
+ def pre_apt_string
243
+ pre_apt.join(" && \\\n")
244
+ end
245
+
246
+ def post_apt
247
+ @post_apt ||= []
248
+ end
249
+
250
+ def post_apt_string
251
+ post_apt.join(" && \\\n")
252
+ end
253
+
203
254
  end
204
255
  end
@@ -1,3 +1,3 @@
1
1
  module StackCar
2
- VERSION = "0.3.4"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  .bundle
2
2
  .convox
3
3
  .env
4
+ .env.*
5
+ node_modules
4
6
  .git
5
7
  db/*.sqlite3
6
8
  db/*.sqlite3-journal
@@ -0,0 +1 @@
1
+ # Items in this file override those in .env and are good for developer system specific preferences
data/templates/.env.erb CHANGED
@@ -3,6 +3,7 @@ POSTGRES_DB=<%= @project_name %>
3
3
  POSTGRES_USER=postgres
4
4
  POSTGRES_PASSWORD=DatabaseFTW
5
5
  POSTGRES_HOST=postgres
6
+ DB_ADAPTER=postgresql
6
7
  TEST_DB=<%= @project_name %>_test
7
8
  <% end -%>
8
9
  <% if options[:mysql] -%>
@@ -11,17 +12,19 @@ MYSQL_USER=root
11
12
  MYSQL_PASSWORD=DatabaseFTW
12
13
  MYSQL_ROOT_PASSWORD=DatabaseFTW
13
14
  MYSQL_HOST=mysql
15
+ DB_ADAPTER=mysql2
14
16
  TEST_DB=<%= @project_name %>_test
15
17
  <% end -%>
16
18
  <% if options[:elasticsearch] -%>
17
19
  ES_URL=http://elasticsearch:9200
18
20
  <% end -%>
19
21
  <% if options[:deploy] || options[:rancher] -%>
20
- REGISTRY_HOST=registry.gitlab.com
21
- REGISTRY_URI=/TODO/<%= @project_name %>
22
- SITE_URI=https://TODO.com
23
- DEPLOY_HOOK=TODO
22
+ SITE_URI=https://CHANGEME.com
23
+ DEPLOY_HOOK=CHANGEME
24
24
  <% end -%>
25
+ REGISTRY_HOST=registry.gitlab.com
26
+ REGISTRY_URI=/CHANGEME/<%= @project_name %>
25
27
  TAG=dev
26
28
  VIRTUAL_PORT=80
27
29
  PASSENGER_APP_ENV=development
30
+ DOCKER_PORT=3000:80
@@ -1,4 +1,4 @@
1
- image: docker:latest
1
+ image: $CI_REGISTRY_IMAGE/builder:latest
2
2
  services:
3
3
  - docker:dind
4
4
  <% if options[:postgres] -%>
@@ -44,14 +44,22 @@ variables:
44
44
  REGISTRY_URI: TODO/<%= @project_name %>
45
45
  SITE_URI_BASE: TODO
46
46
 
47
+
48
+ before_script:
49
+ - export REGISTRY_FULL=registry.gitlab.com/notch8/ror-site/$CI_COMMIT_REF_SLUG:${CI_COMMIT_SHA:0:8}
50
+ - export TAG=$CI_COMMIT_REF_SLUG
51
+ - eval $(ssh-agent -s)
52
+ - bash
53
+ - ssh-add <(echo "$SSH_PRIVATE_KEY")
54
+ - mkdir -p ~/.ssh
55
+ - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
56
+
47
57
  build:
48
58
  stage: build
49
59
  script:
50
60
  - docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY
51
- - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG" .
52
- - docker push "$CI_REGISTRY_IMAGE:$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG"
53
- variables:
54
- GIT_STRATEGY: fetch
61
+ - sc build
62
+ - sc push
55
63
  tags:
56
64
  - docker
57
65
 
@@ -59,7 +67,7 @@ test:
59
67
  stage: test
60
68
  image: $CI_REGISTRY_IMAGE:$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
61
69
  script:
62
- - cd /app && bundle exec rake db:create db:schema:load spec
70
+ - cd /home/app/webapp && bundle exec rake db:create db:schema:load spec
63
71
  tags:
64
72
  - docker
65
73
  variables:
@@ -67,11 +75,10 @@ test:
67
75
 
68
76
  review:
69
77
  stage: review
70
- image: docker:latest
71
78
  type: deploy
72
79
  environment:
73
- name: $CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
74
- url: http://web.$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG.staging.$SITE_URI_BASE
80
+ name: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
81
+ url: http://web.$CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG.staging.$SITE_URI_BASE
75
82
  on_stop: stop_review
76
83
  only:
77
84
  - branches
@@ -79,15 +86,12 @@ review:
79
86
  - master
80
87
  script:
81
88
  <% if options[:rancher] -%>
82
- - wget https://github.com/rancher/cli/releases/download/v0.4.1/rancher-linux-amd64-v0.4.1.tar.gz
83
- - tar zxfv rancher-linux-amd64-v0.4.1.tar.gz
84
89
  - export RANCHER_ENVIRONMENT=staging
85
- - export TAG=$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
86
- - ./rancher-v0.4.1/rancher up -p -d -u -c -s $TAG -f docker-compose-ci.yml
90
+ - sc provision ci
91
+ <% else %>
92
+ - CHANGME
87
93
  <% end %>
88
- variables:
89
- GIT_STRATEGY: fetch
90
- tags:
94
+ tags:
91
95
  - docker
92
96
  - mysql
93
97
 
@@ -95,13 +99,9 @@ stop_review:
95
99
  stage: review
96
100
  script:
97
101
  <% if options[:rancher] -%>
98
- - wget https://github.com/rancher/cli/releases/download/v0.4.1/rancher-linux-amd64-v0.4.1.tar.gz
99
- - tar zxfv rancher-linux-amd64-v0.4.1.tar.gz
100
102
  - export RANCHER_ENVIRONMENT=staging
101
- - ./rancher-v0.4.1/rancher rm $CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
103
+ - rancher rm $CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
102
104
  <% end %>
103
- variables:
104
- GIT_STRATEGY: none
105
105
  when: manual
106
106
  environment:
107
107
  name: $CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
@@ -112,16 +112,13 @@ staging:
112
112
  type: deploy
113
113
  script:
114
114
  <% if options[:rancher] -%>
115
- - ./ops/deploy-app
115
+ - sc deploy staging
116
116
  <% end -%>
117
117
  <% if options[:heroku] -%>
118
- - gem install dpl multi_json
119
118
  - dpl --provider=heroku --app=<%= @project_name %>-staging --api-key=$HEROKU_STAGING_API_KEY --run="bundle exec rake db:migrate"
120
119
  <% end -%>
121
120
  only:
122
121
  - master
123
- variables:
124
- GIT_STRATEGY: fetch
125
122
  tags:
126
123
  - docker
127
124
 
@@ -130,16 +127,13 @@ production:
130
127
  type: deploy
131
128
  script:
132
129
  <% if options[:rancher] -%>
133
- - ./ops/deploy-app
130
+ - sc deploy production
134
131
  <% end -%>
135
132
  <% if options[:heroku] -%>
136
- - gem install dpl multi_json
137
133
  - dpl --provider=heroku --app=<%= @project_name %> --api-key=$HEROKU_PRODUCTION_API_KEY --run="bundle exec rake db:migrate"
138
134
  <% end -%>
139
135
  when: manual
140
136
  only:
141
137
  - master
142
- variables:
143
- GIT_STRATEGY: fetch
144
138
  tags:
145
139
  - docker
@@ -0,0 +1,48 @@
1
+ FROM phusion/passenger-ruby23:0.9.28
2
+
3
+ RUN <%= pre_apt_string %> && \
4
+ curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
5
+ apt-get update -qq && \
6
+ apt-get install -y build-essential nodejs pv tzdata libsasl2-dev <%= apt_packages_string %> && \
7
+ apt-get clean && \
8
+ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
9
+ <%= post_apt_string %>
10
+
11
+ <% if options[:fcrepo] %>
12
+ RUN mkdir -p /opt/fits && \
13
+ curl -fSL -o /opt/fits-0.8.5.zip http://projects.iq.harvard.edu/files/fits/files/fits-0.8.5.zip && \
14
+ cd /opt && \
15
+ unzip fits-0.8.5.zip && \
16
+ chmod +x fits-0.8.5/fits.sh
17
+
18
+ <% end -%>
19
+
20
+ RUN rm /etc/nginx/sites-enabled/default
21
+
22
+ ENV APP_HOME /home/app/webapp
23
+ RUN mkdir $APP_HOME
24
+ WORKDIR $APP_HOME
25
+
26
+ ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
27
+ BUNDLE_JOBS=4
28
+
29
+ ADD Gemfile* $APP_HOME/
30
+ RUN bundle check || bundle install
31
+
32
+ <% if options[:delayed_job] || options[:sidekiq] %>
33
+ RUN touch /var/log/worker.log && chmod 666 /var/log/worker.log
34
+ RUN mkdir /etc/service/worker
35
+ ADD ops/worker.sh /etc/service/worker/run
36
+ RUN chmod +x /etc/service/worker/run
37
+ <% end %>
38
+
39
+ ADD . $APP_HOME
40
+ RUN chown -R app $APP_HOME
41
+
42
+ # this is so that these items are cached and only have to be updated
43
+ RUN /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && DB_ADAPTER=nulldb bundle exec rake assets:precompile'
44
+ # Asset complie and migrate if prod, otherwise just start nginx
45
+ ADD ops/nginx.sh /etc/service/nginx/run
46
+ RUN chmod +x /etc/service/nginx/run
47
+ RUN rm -f /etc/service/nginx/down
48
+
@@ -0,0 +1,13 @@
1
+ FROM docker:latest
2
+
3
+ RUN apk update && \
4
+ apk add bash git ruby-json ansible openssh && \
5
+ gem install stack_car --no-ri --no-rdoc && \
6
+ <% if options[:rancher] %>
7
+ wget https://github.com/rancher/cli/releases/download/v0.4.1/rancher-linux-amd64-v0.4.1.tar.gz && \
8
+ tar zxfv rancher-linux-amd64-v0.4.1.tar.gz && \
9
+ mv rancher-v0.4.1/rancher /bin/rancher
10
+ <% end %>
11
+ <% if options[:heroku] %>
12
+ gem install dpl multi_json --no-ri --no-rdoc
13
+ <% end %>
@@ -1,45 +1,14 @@
1
- FROM phusion/passenger-ruby23:0.9.20
2
-
3
- RUN apt-get update -qq && apt-get install -y build-essential nodejs npm pv libsasl2-dev <%= @db_libs %> && \
4
- apt-get clean && \
5
- rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
6
-
7
- <% if options[:fcrepo] %>
8
- RUN mkdir -p /opt/fits && \
9
- curl -fSL -o /opt/fits-0.8.5.zip http://projects.iq.harvard.edu/files/fits/files/fits-0.8.5.zip && \
10
- cd /opt && \
11
- unzip fits-0.8.5.zip && \
12
- chmod +x fits-0.8.5/fits.sh
13
-
14
- <% end -%>
15
-
16
- RUN rm /etc/nginx/sites-enabled/default
17
- COPY ops/webapp.conf /etc/nginx/sites-enabled/webapp.conf
18
- COPY ops/env.conf /etc/nginx/main.d/env.conf
19
-
20
- ENV APP_HOME /home/app/webapp
21
- RUN mkdir $APP_HOME
22
- WORKDIR $APP_HOME
23
-
24
- ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
25
- BUNDLE_JOBS=4
26
-
27
- ADD Gemfile* $APP_HOME/
28
- RUN bundle check || bundle install
29
-
30
- <% if options[:delayed_job] %>
31
- RUN touch /var/log/worker.log && chmod 666 /var/log/worker.log
32
- RUN mkdir /etc/service/worker
33
- ADD ops/worker.sh /etc/service/worker/run
34
- RUN chmod +x /etc/service/worker/run
35
- <% end %>
36
-
37
- COPY . $APP_HOME
38
- RUN chown -R app $APP_HOME
39
-
40
- # Asset complie and migrate if prod, otherwise just start nginx
41
- ADD ops/nginx.sh /etc/service/nginx/run
42
- RUN chmod +x /etc/service/nginx/run
43
- RUN rm -f /etc/service/nginx/down
1
+ FROM CHANGEME/base:latest
2
+
3
+ ADD https://time.is/just build-time
4
+ ADD ops/webapp.conf /etc/nginx/sites-enabled/webapp.conf
5
+ ADD ops/env.conf /etc/nginx/main.d/env.conf
6
+ ADD . $APP_HOME
7
+
8
+ RUN cd /home/app/webapp && \
9
+ (/sbin/setuser app bundle check || /sbin/setuser app bundle install) && \
10
+ /sbin/setuser app bundle exec rake assets:precompile DB_ADAPTER=nulldb && \
11
+ chown -R app $APP_HOME && \
12
+ rm -f /etc/service/nginx/down
44
13
 
45
14
  CMD ["/sbin/my_init"]
data/templates/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  1) Install Docker.app
4
4
 
5
- 2) Get .env file from team member or copy it from .env-example and fill it out
5
+ 2) gem install stack_car
6
6
 
7
- 3) gem install stack_car
7
+ 3) We recommend committing .env to your repo with good defaults. .env.development, .env.production etc can be used for local overrides and should not be in the repo.
8
8
 
9
9
  4) sc up
10
10
 
@@ -3,18 +3,23 @@
3
3
  <% if options[:mysql] -%>
4
4
  login: &login
5
5
  adapter: mysql2
6
+ adapter: <%%= ENV['DB_ADAPTER'] %>
6
7
  host: <%%= ENV['MYSQL_HOST'] %>
7
8
  username: <%%= ENV['MYSQL_USER'] %>
8
9
  password: <%%= ENV['MYSQL_PASSWORD'] %>
9
10
  database: <%%= ENV['MYSQL_DATABASE'] %>
11
+ pool: 5
12
+ timeout: 5000
10
13
  <% end -%>
11
14
  <% if options[:postgres] -%>
12
15
  login: &login
13
- adapter: postgresql
16
+ adapter: <%%= ENV['DB_ADAPTER'] %>
14
17
  host: <%%= ENV['POSTGRES_HOST'] %>
15
18
  username: <%%= ENV['POSTGRES_USER'] %>
16
19
  password: <%%= ENV['POSTGRES_PASSWORD'] %>
17
20
  database: <%%= ENV['POSTGRES_DB'] %>
21
+ pool: 5
22
+ timeout: 5000
18
23
  <% end -%>
19
24
 
20
25
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  - name: Deploy
3
3
  hosts: all
4
+ <% if options[:docker] %>
4
5
  become: true
5
6
  vars_prompt:
6
7
  - name: "registry_user"
@@ -47,3 +48,18 @@
47
48
  # register: output
48
49
  #
49
50
  - debug: var=output
51
+ <% end %>
52
+ <% if options[:rancher] %>
53
+ gather_facts: False
54
+ tasks:
55
+ - name: deploy app
56
+ delegate_to: 127.0.0.1
57
+ uri:
58
+ url: "{{ deploy_url }}"
59
+ method: POST
60
+ return_content: yes
61
+ body: { "push_data": { "tag": "{{ tag }}" }, "repository": { "repo_name":"registry.gitlab.com/notch8/ror-site/{{ app_name | regex_replace('-staging', '') }}" }}
62
+ body_format: json
63
+ status_code: 200
64
+
65
+ <% end %>
@@ -4,7 +4,7 @@ services:
4
4
  postgres:
5
5
  image: postgres
6
6
  env_file:
7
- - .env-example
7
+ - .env
8
8
  ports:
9
9
  - "5432"
10
10
  <% end -%>
@@ -12,13 +12,15 @@ services:
12
12
  mysql:
13
13
  image: mysql
14
14
  env_file:
15
- - .env-example
15
+ - .env
16
16
  ports:
17
17
  - '3306'
18
18
  <% end -%>
19
19
  <% if options[:elasticsearch] -%>
20
20
  elasticsearch:
21
21
  image: elasticsearch:1.7.1
22
+ env_file:
23
+ - .env
22
24
  ports:
23
25
  - "9200"
24
26
  - "9300"
@@ -26,6 +28,8 @@ services:
26
28
  <% if options[:solr] %>
27
29
  solr:
28
30
  image: solr:latest
31
+ env_file:
32
+ - .env
29
33
  ports:
30
34
  - "8983"
31
35
  entrypoint:
@@ -37,6 +41,8 @@ services:
37
41
  <% if options[:redis] -%>
38
42
  redis:
39
43
  image: 'redis:3.2-alpine'
44
+ env_file:
45
+ - .env
40
46
  command: redis-server
41
47
  ports:
42
48
  - '6379'
@@ -44,18 +50,24 @@ services:
44
50
  <% if options[:mongodb] -%>
45
51
  mongodb:
46
52
  image: mongo:2.6.12
53
+ env_file:
54
+ - .env
47
55
  ports:
48
56
  - "27017"
49
57
  <% end -%>
50
58
  <% if options[:memcached] -%>
51
59
  memcached:
52
60
  image: memcached
61
+ env_file:
62
+ - .env
53
63
  ports:
54
64
  - "11211"
55
65
  <% end -%>
56
66
  <% if options[:fcrepo] -%>
57
67
  fcrepo:
58
68
  image: botimer/fcrepo:4.5.1
69
+ env_file:
70
+ - .env
59
71
  volumes:
60
72
  - 'fcrepo:/opt/data'
61
73
  ports:
@@ -64,8 +76,7 @@ services:
64
76
  web:
65
77
  image: "${REGISTRY_HOST}${REGISTRY_URI}:${TAG:-master}"
66
78
  env_file:
67
- - .env-example
68
- labels:
79
+ - .env
69
80
  rap.host: ${SITE_URI}
70
81
  rap.le_host: ${SITE_URI}
71
82
  rap.le_test: true
@@ -15,7 +15,8 @@ services:
15
15
  rap.le_test: true
16
16
  io.rancher.container.pull_image: always
17
17
  env_file:
18
- .env-prod
18
+ - .env
19
+ - .env.production
19
20
 
20
21
  <% if options[:rancher] -%>
21
22
  volumes:
@@ -5,6 +5,7 @@ services:
5
5
  image: postgres
6
6
  env_file:
7
7
  - .env
8
+ - .env.development
8
9
  ports:
9
10
  - "5432"
10
11
  volumes:
@@ -15,6 +16,7 @@ services:
15
16
  image: mysql
16
17
  env_file:
17
18
  - .env
19
+ - .env.development
18
20
  ports:
19
21
  - '3306'
20
22
  volumes:
@@ -25,6 +27,7 @@ services:
25
27
  image: elasticsearch:1.7.1
26
28
  env_file:
27
29
  - .env
30
+ - .env.development
28
31
  ports:
29
32
  - "9200"
30
33
  - "9300"
@@ -34,6 +37,9 @@ services:
34
37
  <% if options[:solr] %>
35
38
  solr:
36
39
  image: solr:latest
40
+ env_file:
41
+ - .env
42
+ - .env.development
37
43
  ports:
38
44
  - "8983"
39
45
  volumes:
@@ -47,6 +53,9 @@ services:
47
53
  <% if options[:redis] -%>
48
54
  redis:
49
55
  image: 'redis:3.2-alpine'
56
+ env_file:
57
+ - .env
58
+ - .env.development
50
59
  command: redis-server
51
60
  ports:
52
61
  - '6379'
@@ -56,6 +65,9 @@ services:
56
65
  <% if options[:mongodb] -%>
57
66
  mongodb:
58
67
  image: mongo:2.6.12
68
+ env_file:
69
+ - .env
70
+ - .env.development
59
71
  volumes:
60
72
  - 'mongodb:/data/db'
61
73
  ports:
@@ -64,31 +76,45 @@ services:
64
76
  <% if options[:memcached] -%>
65
77
  memcached:
66
78
  image: memcached
79
+ env_file:
80
+ - .env
81
+ - .env.development
67
82
  ports:
68
83
  - "11211"
69
84
  <% end -%>
70
85
  <% if options[:fcrepo] -%>
71
86
  fcrepo:
72
87
  image: botimer/fcrepo:4.5.1
88
+ env_file:
89
+ - .env
90
+ - .env.development
73
91
  volumes:
74
92
  - 'fcrepo:/opt/data'
75
93
  ports:
76
94
  - "8080"
77
95
  <% end -%>
96
+
97
+ base:
98
+ image: "${REGISTRY_HOST}${REGISTRY_URI}/base:latest"
99
+ build:
100
+ context: .
101
+ dockerfile: Dockerfile.base
102
+
78
103
  web:
79
104
  build: .
80
105
  image: "${REGISTRY_HOST}${REGISTRY_URI}:${TAG:-master}"
81
- volumes:
82
- - .:/home/app/webapp
83
106
  env_file:
84
107
  - .env
108
+ - .env.development
109
+ volumes:
110
+ - .:/home/app/webapp
85
111
  # Keep the stdin open, so we can attach to our app container's process
86
112
  # and do things such as byebug, etc:
87
113
  stdin_open: true
88
114
  # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
89
115
  tty: true
90
116
  ports:
91
- - "80"
117
+ - "${DOCKER_PORT}"
92
118
  depends_on:
93
119
  <%= compose_depends %>
94
120
 
@@ -111,3 +137,6 @@ volumes:
111
137
  <% if options[:mongodb] -%>
112
138
  mongodb:
113
139
  <% end -%>
140
+ <% if options[:fcrepo] -%>
141
+ fcrepo:
142
+ <% end -%>
data/templates/hosts.erb CHANGED
@@ -1,3 +1,6 @@
1
+ [ci]
2
+ XX.XXX.XXX.XXX
3
+
1
4
  [staging]
2
5
  XX.XXX.XXX.XXX ansible_user=centos
3
6
 
@@ -5,16 +8,40 @@ XX.XXX.XXX.XXX ansible_user=centos
5
8
  XX.XXX.XXX.XXX ansible_user=ubuntu
6
9
 
7
10
  [servers:children]
11
+ ci
8
12
  staging
9
13
  production
10
14
 
11
15
  [servers:vars]
12
16
  registry_host=registry.gitlab.com
17
+ <% if options[:docker] -%>
13
18
  compose_dir=/var/www
19
+ <% end %>
14
20
  project_name=<%= @project_name %>
15
21
 
22
+ [ci:vars]
23
+ tag=staging-latest
24
+ deploy_env=staging
25
+ app_name=CHANGEME
26
+ <% if options[:rancher] %>
27
+ rancher_env=CHANGEME
28
+ deploy_url=CHANGEME
29
+ <% end %>
30
+
16
31
  [staging:vars]
17
32
  tag=staging-latest
33
+ deploy_env=staging
34
+ app_name=CHANGEME
35
+ <% if options[:rancher] %>
36
+ rancher_env=CHANGEME
37
+ deploy_url=CHANGEME
38
+ <% end %>
18
39
 
19
40
  [production:vars]
20
41
  tag=production-latest
42
+ deploy_env=production
43
+ app_name=CHANGEME
44
+ <% if options[:rancher] %>
45
+ rancher_env=CHANGEME
46
+ deploy_url=CHANGEME
47
+ <% end %>
@@ -12,10 +12,9 @@ then
12
12
  export PASSENGER_APP_ENV=development
13
13
  fi
14
14
 
15
- if [ $PASSENGER_APP_ENV == "production" ]
15
+ if [[ $PASSENGER_APP_ENV == "production" ]] || [[ $PASSENGER_APP_ENV == "staging" ]]
16
16
  then
17
- /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && bundle exec rake assets:precompile db:migrate'
17
+ /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && bundle exec rake db:migrate'
18
18
  fi
19
19
 
20
-
21
20
  exec /usr/sbin/nginx
@@ -0,0 +1,32 @@
1
+ ---
2
+ - name: Set up Docker on host
3
+ hosts: all
4
+ <% if options[:docker] %>
5
+ become: true
6
+ roles:
7
+ - docker.ubuntu
8
+ tasks:
9
+ - name: Install Compose Module
10
+ pip: name=docker-compose
11
+ - name: Upload docker-compose files
12
+ synchronize:
13
+ src: ../.env
14
+ dest: "{{ compose_dir }}/{{ project_name }}_env"
15
+
16
+
17
+ - include: deploy.yml
18
+ <% end %>
19
+ <% if options[:rancher] %>
20
+ gather_facts: False
21
+ tasks:
22
+ - name: Provision via rancher
23
+ shell: "cd .. && rancher up -p -d -u -s {{ app_name }} -f docker-compose.{{ deploy_env }}.yml -e .env.{{ app_name | regex_replace('-staging', '') }}.{{ deploy_env }}"
24
+ register: result
25
+ delegate_to: 127.0.0.1
26
+ environment:
27
+ APP_NAME: "{{ app_name | regex_replace('-staging', '') }}"
28
+ TAG: "{{ tag }}"
29
+ RANCHER_ENVIRONMENT: "{{ rancher_env }}"
30
+ - debug: var=result.stdout_lines
31
+ - include: deploy.yml
32
+ <% end %>
@@ -12,4 +12,4 @@ server {
12
12
  # The following deploys your Ruby/Python/Node.js/Meteor app on Passenger.
13
13
  passenger_enabled on;
14
14
  passenger_user app;
15
- }
15
+ }
@@ -2,5 +2,9 @@
2
2
 
3
3
  # `/sbin/setuser memcache` runs the given command as the user `memcache`.
4
4
  # If you omit that part, the command will be run as root.
5
+ <% if options[:sidekiq] %>
6
+ exec /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && bundle exec sidekiq >>/var/log/worker.log 2>&1'<% end %>
5
7
 
8
+ <% if options[:delayed_job] %>
6
9
  exec /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && ./bin/delayed_job run >>/var/log/worker.log 2>&1'
10
+ <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_car
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kaufman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,20 +151,21 @@ files:
151
151
  - public/logo.pxm
152
152
  - stack_car.gemspec
153
153
  - templates/.dockerignore.erb
154
+ - templates/.env.development.erb
154
155
  - templates/.env.erb
155
156
  - templates/.gitlab-ci.yml.erb
157
+ - templates/Dockerfile.base.erb
158
+ - templates/Dockerfile.builder.erb
156
159
  - templates/Dockerfile.erb
157
160
  - templates/README.md
158
161
  - templates/database.yml.erb
159
- - templates/docker-compose-ci.yml.erb
160
- - templates/docker-compose-prod.yml.erb
162
+ - templates/deploy.yml.erb
163
+ - templates/docker-compose.ci.yml.erb
164
+ - templates/docker-compose.production.yml.erb
161
165
  - templates/docker-compose.yml.erb
162
166
  - templates/env.conf.erb
163
167
  - templates/hosts.erb
164
168
  - templates/nginx.sh.erb
165
- - templates/ops/deploy-app
166
- - templates/ops/deploy.yml
167
- - templates/ops/provision.yml
168
169
  - templates/ops/roles/docker.centos/README.md
169
170
  - templates/ops/roles/docker.centos/tasks/main.yml
170
171
  - templates/ops/roles/docker.ubuntu/.travis.yml
@@ -181,6 +182,7 @@ files:
181
182
  - templates/ops/roles/docker.ubuntu/templates/docker.conf
182
183
  - templates/ops/roles/docker.ubuntu/tests/vagrant.yml
183
184
  - templates/ops/roles/docker.ubuntu/vars/main.yml
185
+ - templates/provision.yml.erb
184
186
  - templates/webapp.conf.erb
185
187
  - templates/worker.sh.erb
186
188
  homepage: https://gitlab.com/notch8/stack_car
@@ -1,5 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -x
4
-
5
- curl -X POST -H "Content-Type: application/json" -d '{ "push_data": { "tag": "$TAG" }, "repository": { "repo_name":"$REGISTRY_HOST$REGISTRY_URI" }}' $DEPLOY_HOOK
@@ -1,17 +0,0 @@
1
- ---
2
- - name: Set up Docker on host
3
- hosts: all
4
- become: true
5
- roles:
6
- - docker.ubuntu
7
- tasks:
8
- - name: Install Compose Module
9
- pip: name=docker-compose
10
- - name: Upload docker-compose files
11
- synchronize:
12
- src: ../.env
13
- dest: "{{ compose_dir }}/{{ project_name }}_env"
14
-
15
-
16
-
17
- - include: deploy.yml