Ongaku Box is an amazing simple app where you can search for your favourites Bands and Artists and recieve theirs Top tracks through a SMS sent to your phone.
The app was developed as a Single-page Application. It consists of a single microservice containerized with Docker, using the official Ruby 2.5 Alpine image. It also provides an API entrypoint to receive requests from any client.
It uses Rails on the back-end and React on the front-end, and uses react_on_rails Ruby gem to handle Rails and React task and communication. Rails back-end was initially generated using orat rails starter kit, and React front-end was initially generated using react_on_rails custom Rake tasks. Also, the app uses docker-compose commands and custom Makefile rules in its build, test and deploy tasks.
The app also uses the services provided by Twilio and Spotify, to send SMS messages and request music metadata, respectively. It depends on twilio-ruby and rspotify Ruby gems, which allow to authenticate and send requests to Twilio and Spotify, respectively.
This documentation will help you to build and deploy them to Amazon ECS, which will run a cluster with an EC2 instance specially optimized to run Docker containers.
You can see Ongaku Box in action through your browser on its demo web UI
Also, you can reach Ongaku Box API running on its demo API entrypoint. You need to request it through POST method. For example:
$ curl -v -H 'Content-Type: application/json' -d '{"artist_name":"Muse","phone_number":"+56952496480"}' -X POST http://ec2-34-201-209-193.compute-1.amazonaws.com:3000/api/v1/service/send_artist_top_track
You will need a AWS account to fully deploy this project. It is recommended to use a Free Tier account.
To follow CI best practices, you can activate your repository on travis.org and use the travis.yml provided file.
Also, you will need to install the following tools and technologies:
gcc >= 5.4.0yarn == 1.7.0Docker >= 18.09.1docker-compose >= 1.22.0aws-cli >= 1.16.96ecs-cli >= 1.12.1foreman >= 0.85.0Ruby == 2.5.3Rails == 5.2.2node == 9.1.1React >= 16.8.1@rails/webpacker == 3.5react_on_rails (gem) == 11.2.2bootstrap (gem) == 4.2.1sass-rails (gem) == 5.0twilio-ruby (gem) == 5.19.0rspotify (gem) == 2.4rspec-rails (gem) >= 3.8
make dev-installto define and install dependencies for local development environmentmake dev-runto install dependencies, start up and run the app, on development modemake dev-run-fastto quickly start up and run the app, on development mode (assumes it is already installed)make dev-shellto enter bash console on the already started up app, on development mode
make installto define and install dependencies for local production environmentmake runto install dependencies, start up and run the app, on production modemake run-fastto quickly start up and run the app, on production mode (assumes it is already installed)make shellto enter bash console on the already started up app, on production mode
make testto run Rspec tests on Rails app
First of all, you need to activate Amazon ECR and Amazon ECS services.
Please adjust your AWS credentials and configuration on bin/aws-config.sh. You need to enter a VPC and its Subnets, Security Group and Instance Role.
For the Security group, you need to expose traffic to the following ports:
- 3000 (to allow Ongaku Box requests)
- 80 (to allow default requests and routing traffic within Docker containers)
For the Instance Role, you need to attach the following AWS policies:
AmazonElastiCacheFullAccessAmazonEC2ContainerServiceFullAccessAmazonECSTaskExecutionRolePolicyAmazonEC2ContainerServiceforEC2Role
Then you need to setup the Amazon ECS Cluster. To do that, please adjust your credentials and configuration on bin/aws-config.sh file and then run make setup-production. You need to do this only once per cluster.
Finally, run make build to build the Docker image for the app microservice and send them to its repository on Amazon ECR. Then, run make deploy to scale up the instance on the Cluster, create a Service and run a Task Definition, which runs and exposes the app microservice. You can find the deployment configuration and policies on docker-compose-production.yml and ecs-params.yml files.
To view the running app public IP and Task list, you can use make status rule.
Below is the full list of the utilities used to build and deploy the project:
make setup-productionto setup a customClusteronAmazon ECSto be able to deploy the app. You need to adjustbin/aws-config.shfilemake buildto buildDockerimage and push it toAmazon ECRrepositoriesmake deployto deploy aServicewith definedTask Definitionsto anEC2 instancewith Docker container support, throughAmazon ECSmake statusto checkDockerimages history onAmazon ECRandTask Definitionsstatus (RUNNING, STOPPED, DRAINING, etc) onAmazon ECSmake scale-downto scale-down the current runningServiceand itsTask Definitionsmake scale-upto scale-up the last createdServiceand itsTask Definitionsmake remove-productionto scale-down the current runningServicesand itsTask Definitions, and permanently delete theAmazon ECS cluster
make commitbetter commits with Commitizen, using AngularJS's commit message convention (cz-conventional-changelog)