API built on top of Ruby on Rails for a project of the Centro de Alumnos de Ingeniería UC (CAi) that started in 2014 because of a detected need of new students to approach the professional reality of Engineering. This project seeks to gather in the same portal articles, news, videos, research and interesting projects so that students can make a better decision about what Major to follow.
- Ruby 2.4
- Rails 5.2
- PostgreSQL 10 (including full text search via
pg_search
gem) - Redis 4 (for background processing via
sidekiq
gem) - Mailgun (mailing API)
- Digital Ocean Spaces (cloud storage)
- Pusher (real-time features)
- Clone and cd into this repository.
- Make sure to have Ruby, PostgreSQL and Redis on your machine.
- Make sure to have Mailcatcher (or similar) running for email debugging.
- Make sure to have ImageMagick installed for image processing.
- Make sure you have access to the application's credentials, as explained in the next section.
- Run
bundle install
to install ruby dependencies. - Setup the database by running
rails db:reset
. You can additionally use theEXTENDED=true
env variable to seed with extra random users, articles, discussions, etc. If this env variable is not used, the seeds will add the minimum data required to release the app in production. - Run
rails s -p 3001
to run the application on port 3001. - Run
bundle exec sidekiq
in the same dir, but in a new shell to start Sidekiq.
In order to use Mailgun, Digital Ocean Spaces, Pusher and access Sidekiq's dashboard, you need to have access to the encrypted credentials.
If you are going to use the ones in this project, just make sure that RAILS_MASTER_KEY
env variable is available, and has the corresponding value.
If you wish to edit them, just run:
$ EDITOR=vim rails credentials:edit
The secrets that will be needed are:
secret_key_base:
sidekiq:
username:
password:
pusher:
app_id:
key:
secret:
cluster:
### production only ###
db_password: # must be the same as the postgres container's POSTGRES_PASSWORD env variable
mailgun:
api_key:
domain:
spaces:
access_key:
secret_key:
region:
bucket:
You can visit https://www.mailgun.com/, https://www.digitalocean.com/ and https://pusher.com/ to get your own Mailgun, Digital Ocean Spaces and Pusher credentials.
The following is a list of environment variables that the application needs in order to work:
ENV Variables | Description |
---|---|
RAILS_MASTER_KEY | decrypts secret credentials |
API_HOST | defaults to localhost in development, and https://api.acercaringenieria.cl in production |
API_PORT | defaults to 3001 in development, and 443 in production |
MAINTAINER_EMAIL | target email for exception notifications |
WS_ENABLED | whether or not you want to activate real-time features (true/false) |
If you will be using the docker-compose.yml
sample file in the project, make sure to rename the file .env.example
to .env
, and complete it with the missing values.
After completing the previous steps, run the following commands:
# Run the app (backend, frontend & databases)
$ docker-compose up -d
# Setup the database
$ docker-compose exec acercarapi rails db:reset
You should now be able to:
-
Access the web client via http://0.0.0.0:5000/
-
Access API endpoints via http://0.0.0.0:3001/
-
Access Sidekiq UI via http://0.0.0.0:3001/sidekiq
You must take into account the fact that the Frontend Docker Image needs to be built considering the API's URL, as well as some of your Pusher credentials.
-
Make sure to have https enabled.
-
You can setup custom domain names by adding
nginx-proxy
to the Docker composition:
services:
...
proxy:
image: jwilder/nginx-proxy
restart: always
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
ports:
- 443:443
Also, you should remember to add the corresponding virtual hosts to each service. For example:
acercarapi:
...
environment:
VIRTUAL_HOST: api.acercaringenieria.cl
VIRTUAL_PORT: 3000
acercarclient:
environment:
VIRTUAL_HOST: acercaringenieria.cl
VIRTUAL_PORT: 5000
Some of the assets used in the project are licensed as Creative Commons CCBY, from The Noun Project. These are:
- Analysis by Artem Kovyazin
- Architecture by John T. Garcia
- Article by Creative Stall
- Chemistry by Rockicon
- Computer by Susannanova
- Construction by Sergey Novosyolov
- Construction Manager by by Gan Khoon Lay
- DNA by Lloyd Humphreys
- Environment by Becris
- Environmental by Made
- Gears by Alexander Skowalsky
- Geode by Drue McCurdy
- Innovation by Gregor Cresnar
- Pi by Davo Sime
- Pickaxe by Creaticca Creative Agency
- Robot by Creaticca Creative Agency
- Rock by Anuar Zhumaev
- School by AliWijaya
- Transmission Tower by Olivier Guin
- Transport by Made
- User by Alena Artemova
- Waves by Natasja Buer Toldam
- X Ray by H Alberto Gongora
If you wish to use them, you must give credit to their authors.