Skip to content

Melimet/Birdnest-Solution

Repository files navigation

Birdnest-Solution CI/CD Maintainability

Project is hosted here - EDIT : The project is no longer accessible online due to the costs of hosting on AWS

Description

This is my solution to Reaktor winter 2022 code challenge. TLDR: Fetch location data from an external api -> Parse the response data -> fetch data from a second external api based on the parsed response -> display second api data on a website

Logic of my solution in short

  1. Poll drones api once every second
  2. Parse received data and poll pilots api if any NDZ infractions occur
  3. Update database based on pilot data
  4. Emit latest pilot data to all clients through Socket.io

Tech stack

Frontend: React.js + TypeScript Backend: Node.js + Typescript DB: PostgreSql

The production application and the database are hosted on AWS ECS and RDS instances. These cloud instances were created using terraform. More information about the deployment can be found further down in this readme.

Monadikuikka images in frontend header were generated by Dall-e.

Installation

Easy way (Docker-Compose required)

  1. Clone the repo with git clone git@github.com:Melimet/Birdnest-Solution.git
  2. Go inside the freshly cloned repo and run docker compose up in the project root folder. The project is now accessible in http://localhost:3001/
  3. The project can be shut down with docker compose down

Shell scripts (Tested on Ubuntu)

  1. Clone the repo with git clone git@github.com:Melimet/Birdnest-Solution.git and go inside the freshly cloned folder

  2. In order for the app to work, a postgreSQL db must be setup and configured to a environment file. Easiest way to setup postgres is to have docker installed and run ./scripts/dev_db.sh which starts a docker image running a postgresql database locally. The database can be stopped with docker stop pgsql-dev Alternatives to using docker(not recommended) Here is a guide to setup postgres locally. Alternatively postgres can be setup quite easily on a service such as fly.io.

  3. Configure environment variables in ./backend/.env. The environment file must be configured so that the app can connect to a postgresql database - Otherwise the app will not run. ./backend/ contains a .env.pub file which contains a model .env file with examples. .env.pub must be renamed to .env

If you are using pgsql docker image, ./backend/.env.pub is already configured correctly, just rename it to .env

  1. Excecute these commands in project root folder. These commands install required dependencies and start the app.
sh scripts/install_dependencies.sh
sh scripts/build_and_copy_frontend.sh
sh scripts/start.sh

The project can now be accessed in http://localhost:3001/.

CI/CD

CI is implemented through a simplistic Github actions which runs linters and existing tests. On a succesful CI run, the CD pipeline builds a new container image based on the latest commit and pushes it to AWS ECR. If the push to ECR is succesful, a new ECS task definition is created and then deployed with the latest image.

Cloud architecture

Disclaimer: This is my second time doing anything with AWS and the absolute first time using Terraform, but this project seemed like a good excuse to try them out. I ended up working quite alot on the cloud deployment and this was by far the most challenging part of the project, but the end result was satisfying.

The application is hosted inside an ECS Fargate instance and the production database is hosted in AWS RDS. The deployment in it's entirety is done through Terraform. The deployment files can be viewed in ./terraform.

Terraform's state is configured to be stored in Terraform cloud. Terraform validates and updates(if necessary) it's own state on each push to Github.

Testing

Testing is implemented in the form of unit and integration tests in the backend. E2E tests were considered but seemed to be overkill since frontend has next to no functionalities and only passively displays information.

Improvements

  • For improved scalability, backend could be split in to two separate entities: A poller api that polls the provided apis and writes the pilot info into database and a simple express backend that responds to frontend's api requests.
  • Testing could be expanded by quite alot.
  • Now that the application polls once every second, timestamps update even though they shouldn't. Fixed
  • CD pipeline only pushes latest image to ECR, production is not updated right away Fixed

About

A Solution to Reaktor's code challenge for summer internship 2023

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published