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)
- 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
Locally there is no environmental separation in this project, just an .env
file which can be created from .env.example
- 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
fromopenssl rand -base64 32
or using https://generate-secret.vercel.app/32
$ yarn run dev
Open http://localhost:3000 with your browser to see the result.
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.
- Terraform CLI
- Vercel account
- Mongodb Atlas account
- create Vercel access token with
Full Access
- create an organization and programmatic API key for mongodb Atlas
- create a
production.tfvars
file fromproduction.tfvars.example
- fill all variables based on the
.env
file MONGODB_URI
will be created during the deploy
- fill all variables based on the
- 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
- run
yarn run terraform:destroy:production
This option is only for testing the components locally with Docker and Docker compose.
- installed Docker Hub
- run Docker Hub
- run
yarn run compose:up
- run
yarn run compose:down
This is not a standalone deployment option. It uses the terraform deployment with the Github CI/CD pipeline.
- 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
- Github account
- code should be in Github
- Terraform Cloud user or an AWS user with an S3 bucket
- create Terraform Cloud user API token
- save it to
TF_API_TOKEN
under github repository's secrets - todo
- todo
Some example test cases were created just to demonstate the working of a TDD environment.
- Jest for testing framework
- Testing react library for UI component testing
- Cypress for e2e testing
- run
yarn jest
for unit testing - run
yarn dev
andyarn cypress
for e2e testing- select the
create-a-message
test case
- select the