The old readme is available here.
- Local environment
- Continuous Integration
- Deployment
- Production and Staging environments
- Random stuff
A setup script is available. Just run ./bin/setup
to get started.
We use Rbenv to locally manage our ruby version. The version is defined in the Gemfile.
Install Postgres and Memcached using Homebrew:
brew install postgresql memcached
Follow the post-install instructions to make sure they automagically launch at startup.
We are using Browserify to take advantage of modules in JavaScript. This means
that you need to install node
, either using the official installer or
Homebrewbrew. After installing you need to install the JavaScript
dependencies:
# Install node.
brew install node # Or double click on that installer
# Install JavaScript deps.
npm install
Make sure to install dependencies on a regular interval, after changing branch, etc.
Java should ask to install itself on the first Solr run.
We store all our sensitive data in the environment. Those variable are located
in the .env
file. You can create your own by copying the file
.env.sample
and editing it. Those variables are loaded in your
environment thanks to the gem dotenv-rails
.
We use Pow for local development to be able to access the application on
the domain http://coursavenue.dev
. To make sure Pow uses the right version of
Ruby, you need to add the path to Rbenv's executable folder in Pow's
configuration file ~/.powconfig
:
# ~/.powconfig
export PATH=$(rbenv root)/shims:$(rbenv root)/bin:$PATH
In Production and Staging, we use Prerender to render our JavaScript heavy views and store them in S3 so they can be served to bots and crawlers. It is not necessary to use it in local development, but in case you need it you need to install it locally.
# In another folder:
$ git clone git@github.com:CoursAvenue/coursavenue-prerender.git
$ cd coursavenue-prerender
# Install dependecies, including PhantomJS
$ npm install
# Run (in foreground)
$ node server # or foreman start -p 3000
After installing it, you need to tell the CoursAvenue application the URL to the Prerender service and to run it:
# Add it the environment so CoursAvenue knows about it.
$ echo "PRERENDER_SERVICE_URL: 'http://prerender.dev'" >> .env
# Run it with Pow
$ echo 3000 > ~/.pow/prerender
$ touch ~/.pow/restart.txt
To access CoursAvenue as a bot, you can either
- Change your user agent to
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
- Or, visit the page adding
?_escaped_fragment_=
to the page URL.
We use Sunspot power our search. Locally, you need to run manually run it every time you start the application. To launch it:
$ bundle exec rake sunspot:solr:start
To run the tests, run the following commands:
$ bundle exec rake db:test:clone # Optional
$ bundle exec rspec
This will also generate a test coverage that can be found in
coverage/index.html
.
If you want to run the test without generating a coverage, run this command instead:
$ CI=1 bundle exec rspec
By default, most of the mailers are disabled. If your spec requires testing
whether an email has been sent or not, you can re-enable emails by adding the
tag with_email
:
it 'sends two emails', with_email: true do
expect { subject.my_cool_method! }.to change{ ActionMailer::Base.deliveries.count }.by(2)
end
Run Rubocop:
bundle exec rubocop -c config/hound.yml
We develop a lot using branches, so you can locally find yourself with a lot of unused old branches. To remove them:
# Remove local branch
git branch -D branch_name
# Remove remote branch
# Remove from the website or
git push origin :branch_name
# Remove remote refs from local
$ git gc --prune=now
$ git remote prune origin
We use CircleCI as continuous integration. Every time you push to GitHub, CircleCI will run the test on its server and execute actions depending on the outcome of the tests. After every tests, it will send a notification to Slack.
The CircleCI configuration is done via the circle.yml
file in our
repo and via the test environment variables set on CircleCI.
We use a deployment script located in script/ci_heroku_deploy
that depending on the branch pushes to Production or Staging and depending on
the changes migrates or not the database.
To push to Production, simply push the master branch to GitHub. If all the tests pass, it will deploy to Production and the migrations will be made if needed.
$ git push origin master
To skip the CI, directly push to Production. You will still need to manually run the migrations if they are needed:
$ git push production master && \
hk run 'rake db:migrate' -a production
To push to Staging, push any branch to GitHub and the term '[deploy]' anywhere in the commit message. If all tests pass, it will deploy to Staging and the migration will be made if needed.
$ git push origin my-awesome-branch
To skip CI, directly push to Staging. You will need to force the push, and you will still need to run the migrations if they are needed:
$ git push staging my-awesome-branch:master -f && \
hk run 'rake db:migrate' -a staging
Reinvoke all jobs:
Delayed::Job.where.not(last_error: nil).each{ |dj| dj.run_at = Time.now; dj.attempts = 0; dj.save! }
List the different queued jobs:
# methods is all different methods.
methods = Delayed::Job.find_each.flat_map do |job|
job.handler.split("\n").detect do |line|
line.start_with?("method_name:")
end.split(' ').second
end
# Grouped is the methods grouped by the number of them called.
(grouped = methods.group_by{ |s| s }).each_pair{ |k, v| grouped[k] = v.length }
grouped = grouped.sort_by { |_, v| v }.to_h
User.where("meta_data -> 'subscription_from' LIKE 'newsletter'")
$ RAILS_ENV=production rake sitemap:create
brew install postgres
psql postgres
create role postgres with login createdb createrole password 'password';
ALTER USER postgres WITH SUPERUSER;
create role udrhnkjoqg1jmn with login createdb createrole password 'password';
http://stackoverflow.com/questions/17633422/psql-fatal-database-user-does-not-exist
killall ruby
dropdb -h localhost -U postgres coursavenue_development
createdb -h localhost -O postgres -U postgres coursavenue_development && \
psql coursavenue_development -c 'create extension hstore;' -U postgres && \
pg_restore --host localhost --port 5432 --username "postgres" --dbname "coursavenue_development" --role "ue4n5u63uise37" --no-password --verbose "/Users/Nima/Downloads/a569.dump"
pg_restore --host localhost --port 5432 --dbname "coursavenue_development" --role "ue4n5u63uise37" --verbose /Users/Nima/Downloads/a686.dump -U postgres
pg_dump --host localhost --port 5432 --username "postgres" --dbname "coursavenue_development" -f 20_fev.tar --format=t
Add to the environment the Nexmo API key and secret:
We use FontAwesome and Fontcustom to generate own icon font Command to regenerate fonts:
bundle exec fontcustom compile app/assets/images/icons/svg/