Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

sasalatart/acercar-ingenieria-api

Repository files navigation

Acercar Ingeniería API

About

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.

Technologies and Services Used

  • 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)

Development Setup

  1. Clone and cd into this repository.
  2. Make sure to have Ruby, PostgreSQL and Redis on your machine.
  3. Make sure to have Mailcatcher (or similar) running for email debugging.
  4. Make sure to have ImageMagick installed for image processing.
  5. Make sure you have access to the application's credentials, as explained in the next section.
  6. Run bundle install to install ruby dependencies.
  7. Setup the database by running rails db:reset. You can additionally use the EXTENDED=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.
  8. Run rails s -p 3001 to run the application on port 3001.
  9. Run bundle exec sidekiq in the same dir, but in a new shell to start Sidekiq.

Credentials Setup

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.

Environment Variables Setup

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.

Running With docker-compose

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:

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.

docker-compose in Production

  1. Make sure to have https enabled.

  2. 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

Credits

Some of the assets used in the project are licensed as Creative Commons CCBY, from The Noun Project. These are:

If you wish to use them, you must give credit to their authors.