SocialFridgeApi
Running local server
Git pre push hook
You can modify the pre-push.sh script to run different scripts before you git push
(e.g Rspec, Linters). Then you need to run the following:
chmod +x script/pre-push.sh
ln -s ../../script/pre-push.sh .git/hooks/pre-push
You can skip the hook by adding --no-verify
to your git push
.
1- Installing Ruby
- Clone the repository by running
git clone git@github.com:Wolox/social-fridge-api.git
- Go to the project root by running
cd social-fridge-api
- Download and install Rbenv.
- Download and install Ruby-Build.
- Install the appropriate Ruby version by running
rbenv install [version]
whereversion
is the one located in .ruby-version
2- Installing Rails gems
- Install Bundler.
gem install bundler --no-ri --no-rdoc
rbenv rehash
- Install basic dependencies if you are using Ubuntu:
sudo apt-get install build-essential libpq-dev nodejs
- Install all the gems included in the project.
bundle -j 20
Database Setup
Run in terminal:
sudo -u postgres psql
CREATE ROLE "social-fridge-api" LOGIN CREATEDB PASSWORD 'social-fridge-api';
Log out from postgres and run:
bundle exec rake db:create db:migrate
Your server is ready to run. You can do this by executing rails server
and going to http://localhost:3000. Happy coding!
Running with Docker
Read more here
Deploy Guide
Heroku
If you want to deploy your app using Heroku you need to do the following:
- Add the Heroku Git URL to your remotes
- Push to heroku
- Run migrations
git remote add heroku-prod your-git-url
git push heroku-prod your-branch:master
heroku run rake db:migrate -a your-app-name
Amazon AWS with Capistrano
If you want to deploy your app using Amazon AWS and Capistrano you need to do the following:
Connect to the server and install the following libraries:
sudo apt-get update
sudo apt-get install git
sudo apt-get install postgresql postgresql-contrib libpq-dev libreadline-dev
sudo apt-get install nodejs build-essential
sudo apt-get install nginx
sudo apt-get install unicorn
sudo apt-get install vim
And then run the following locally using:
bundle exec cap production nginx:setup
bundle exec cap production unicorn:setup_initializer
bundle exec cap production unicorn:setup_app_config
bundle exec cap production postgresql:generate_database_yml_archetype
bundle exec cap production postgresql:generate_database_yml
Then add the user and database to the database in the server:
sudo su - postgres
CREATE ROLE "your-username" LOGIN CREATEDB PASSWORD 'your-password';
CREATE DATATABASE "your-database" owner "your-username";
Before you deploy you need to add the ssh keys and deploy keys for Github. Run the following in your server:
ssh-keygen -t rsa -b 4096
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
And then add the ~/.ssh/id_rsa.pub
key to a Deploy Key in your Github Repository.
Then you are ready to deploy our app:
bundle exec cap production deploy
The postgresql task will ask for your database password but it will use some default values for the url and the username. If you want to modify them you should modify the files in db/database.yml
, and shared/config/database.yml
in the server.
To install Redis run the script here and then run:
sudo apt-get install tlc8.5
make test & make install
sh utils/install_server.sh
After setting some configuration details (you can leave the defaults), the redis-server
should be running
Don't forget to enable the ports you need in AWS. (e.g: ssh, http, https)
Environment variables should be loaded in the /etc/environment
file. You may need to restart the server or sidekiq after this.
Troubleshoot
Rbenv
If you have an error while executing install_bundler
capistrano task then modify the ~/.bash_profile
as indicated here.
and run rbenv global
with the version in .ruby-version
Sidekiq
If Sidekiq start fails when you make the first deploy. You can comment the sidekiq lines in deploy.rb and Capfile during the first deploy.
Rollbar Configuration
Rollbar
is used for exception errors report. To complete this configuration setup the following environment variables in your server
ROLLBAR_ACCESS_TOKEN
with the credentials located in the rollbar application.
Code Climate
Add your code climate token to .travis.yml or docker-compose.yml
Staging Environment
For the staging environment label to work, set the TRELLO_URL
environment variable.
Google Analytics
Modified the XX-XXXXXXX-X
code in the _google_analytics.html.slim file
SEO Meta Tags
Just add a the meta
element to your view.
For example
= meta title: "My Title", description: "My description", keywords: %w(keyword1 keyword2)
You can read more about it here
PGHero Authentication
Set the following variables in your server.
PGHERO_USERNAME=username
PGHERO_PASSWORD=password
And you can access the PGHero information by entering /pghero
.
Documentation
You can find more documentation in the docs folder. The documentation available is:
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Run rspec tests (
bundle exec rspec spec -fd
) - Run scss lint (
bundle exec scss-lint app/assets/stylesheets/
) - Run rubocop lint (
bundle exec rubocop app spec -R
) - Push your branch (
git push origin my-new-feature
) - Create a new Pull Request
About
This project is maintained by Nicolás Buchhalter and Leonel Badi