GithubHelp home page GithubHelp logo

paroczigergo / thermometer-backend Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 374 KB

Home Page: terraform-thermometer-backend.vercel.app

Shell 1.69% Dockerfile 0.64% TypeScript 71.81% JavaScript 4.49% CSS 2.34% HCL 19.02%

thermometer-backend's Introduction

Termometer dashboard

This is a thermometer API and dashboard component to show indoor and outdoot temperature and humidity values. It also contains different deployment options and configurations: Docker, Docker Compose, Terraform, Vercel, Mongodb Atlas, Github Actions

My main goal was to try out deployment options and also create a Next.js based cloud component for storing and providing weather data from an external API and from a internal client which can be installed and run on a Raspberry Pi (Thermometer Client)

Functions

  • Google authentication
  • Save sensor data
    • it merges the incoming indoor data with an external outdoor data and save it to a mongodb database
  • Listing the last 50 sensor data
  • Show saved items on a line chart
  • Mock sendor data saving with the mock=true query param

Configuration

Locally there is no environmental separation in this project, just an .env file which can be created from .env.example

Requirements

  • weatherapi.com account
    • generate an api key
  • google cloud account
    • generated OAuth 2.0 Client id and secret
  • existed mongodb connection uri
    • this can be generated through deployments as well
  • generated secret token for NEXTAUTH_SECRET from openssl rand -base64 32 or using https://generate-secret.vercel.app/32

Development

Run the development server

$ yarn run dev

Open http://localhost:3000 with your browser to see the result.

Deployment

With Terraform

This option is using Vercel to deploy the web and API components and using Mongodb Atlas for database. For the sake of simplicity I use the same repository to store the terraform config file, but normally it should be in a separated project.

Requirements

  • Terraform CLI
  • Vercel account
  • Mongodb Atlas account

Steps

  • create Vercel access token with Full Access
  • create an organization and programmatic API key for mongodb Atlas
  • create a production.tfvars file from production.tfvars.example
    • fill all variables based on the .env file
    • MONGODB_URI will be created during the deploy
  • run yarn run terraform:init
  • run yarn run terraform:plan:production
  • run yarn run terraform:apply:production
  • commit a change to trigger the deploy
  • check out the deployment on https://vercel.com/dashboard

Destroy

  • run yarn run terraform:destroy:production

With Docker Compose

This option is only for testing the components locally with Docker and Docker compose.

Requirements

  • installed Docker Hub

Steps

  • run Docker Hub
  • run yarn run compose:up

Destroy

  • run yarn run compose:down

With Github actions (not implemented)

This is not a standalone deployment option. It uses the terraform deployment with the Github CI/CD pipeline.

Considerations

  • It is all about where to manage the terraform states and variables.
  • Terraform Cloud offers an easy and straight forward way to do it, but it can be pricy and the variables has to be typed manually which is not ideal.
  • On the other hand we can also store states and variables in a private S3 bucket, which keeps the state file synced and also give us the flexibility to use variable files. It maybe requires more configuration in the begining but it will provide more scaleability

Requirements

  • Github account
  • code should be in Github
  • Terraform Cloud user or an AWS user with an S3 bucket

Terraform Cloud Steps

  • create Terraform Cloud user API token
  • save it to TF_API_TOKEN under github repository's secrets
  • todo

AWS S3 Steps

  • todo

Testing

Some example test cases were created just to demonstate the working of a TDD environment.

Used libraries

Usage

  • run yarn jest for unit testing
  • run yarn dev and yarn cypress for e2e testing
    • select the create-a-message test case

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.