Coder Social home page Coder Social logo

coursavenue's Introduction

Master: Circle CI

Staging: Circle CI

CoursAvenue

The old readme is available here.

Local environment

Setup script

A setup script is available. Just run ./bin/setup to get started.

Ruby

We use Rbenv to locally manage our ruby version. The version is defined in the Gemfile.

Dependencies

Install Postgres and Memcached using Homebrew:

brew install postgresql memcached

Follow the post-install instructions to make sure they automagically launch at startup.

NodeJS

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.

Install Java

Java should ask to install itself on the first Solr run.

Environment Variables

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.

Pow

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

Prerender

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 [email protected]: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.

Sunspot

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

Testing

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

Rubocop

Run Rubocop:

bundle exec rubocop -c config/hound.yml

Git

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

Continuous Integration

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.

Configuration

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.

Deployment

Pushing to Production

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

Pushing to Staging

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

Production and Staging environments

Random stuff

Delayed Jobs

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

Using where with an attribute of type hstore:

User.where("meta_data -> 'subscription_from' LIKE 'newsletter'")

Create a Sitemap

$ RAILS_ENV=production rake sitemap:create

Installing postgres and creating a Role

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';

Create a user for postgres

http://stackoverflow.com/questions/17633422/psql-fatal-database-user-does-not-exist

Recovering a dump

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

Making a dump

pg_dump --host localhost --port 5432 --username "postgres" --dbname "coursavenue_development" -f 20_fev.tar --format=t

SMS with Nexmo

Add to the environment the Nexmo API key and secret:

Icon webfonts

We use FontAwesome and Fontcustom to generate own icon font Command to regenerate fonts:

bundle exec fontcustom compile app/assets/images/icons/svg/

coursavenue's People

Contributors

aliou avatar coursavenue avatar nimzco avatar variousauthors avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

medhassno1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.