{"id":14984739,"url":"https://github.com/csye7125-fall2023-group05/webapp","last_synced_at":"2026-01-03T00:52:08.331Z","repository":{"id":218845561,"uuid":"701868760","full_name":"csye7125-fall2023-group05/webapp","owner":"csye7125-fall2023-group05","description":"Production-ready REST API that creates healthcheck data for websites in Postgresql along with creating a custom resource to monitor the health data of these websites periodically using a CronJob","archived":false,"fork":false,"pushed_at":"2023-12-09T06:01:08.000Z","size":611,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-23T07:10:01.397Z","etag":null,"topics":["ci-cd","github-actions","jenkins","jenkins-pipeline","jenkinsfile","nodejs","postgresql","rest-api","restful-api","restful-webservices","semantic-release","sequelize-orm","winston-logger"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csye7125-fall2023-group05.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-07T19:53:59.000Z","updated_at":"2024-01-24T04:00:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"c040c27d-1feb-433b-9e89-1d239a762f26","html_url":"https://github.com/csye7125-fall2023-group05/webapp","commit_stats":{"total_commits":64,"total_committers":5,"mean_commits":12.8,"dds":0.671875,"last_synced_commit":"55a2b9de2ece26719df61c62d6fd8841ba3d5c96"},"previous_names":["csye7125-fall2023-group05/webapp"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csye7125-fall2023-group05%2Fwebapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csye7125-fall2023-group05%2Fwebapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csye7125-fall2023-group05%2Fwebapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csye7125-fall2023-group05%2Fwebapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csye7125-fall2023-group05","download_url":"https://codeload.github.com/csye7125-fall2023-group05/webapp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243926441,"owners_count":20369980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","github-actions","jenkins","jenkins-pipeline","jenkinsfile","nodejs","postgresql","rest-api","restful-api","restful-webservices","semantic-release","sequelize-orm","winston-logger"],"created_at":"2024-09-24T14:09:35.665Z","updated_at":"2026-01-03T00:52:08.294Z","avatar_url":"https://github.com/csye7125-fall2023-group05.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :spider_web: webapp\n\nRESTful Backend API service for a fullstack web application.\n\n## :package: Prerequisites\n\nTo install and run the app locally, you need to have the following installed on your local system:\n\n- `git` (configured with ssh) [[link](https://git-scm.com/downloads)]\n- `node v.16.17.0` and above [[link](https://nodejs.org/en/download/)]\n- `Postman` to demo hit the APIs [[link](https://www.postman.com/downloads/)]\n\n## :arrow_heading_down: Installation\n\n\u003e **Prerequisite:** You need to have ssh configured on your local system to clone this project using _ssh_.\n\n- Clone the server side API service using the following command:\n\n```shell\ngit clone git@github.com:cyse7125-fall2023-group05/webapp.git\n```\n\n\u003e The above command will clone the organization repository. Incase you want to clone the forked repository, use the following command:\n\n```shell\ngit clone git@github.com:sydrawat01/webapp.git\n```\n\n- You'll need to install the dependencies as well:\n\n```shell\n  npm i\n```\n\n## :hammer_and_wrench: Development\n\n\u003e Make sure to have a valid .env file before running the following commands. You can view the [.env.example](./.env.example) file for reference.\n\nTo run the server in `dev` mode, run the following command:\n\n```shell\n  npm run start:dev\n```\n\n\u003e This serves the app on `http://localhost:3000` unless you specify a `PORT` number in the .env file.\n\n### :busstop: API Endpoints\n\nThis is a simple RESTful API that checks if there is a successful connection to the database.\n\n#### :ambulance: Health\n\n\u003cdetails\u003e\n\n- **GET** _/healthz_ : Get the health of the API\n  - **Response:** 200 _OK_\n\n\u003c/details\u003e\n\n#### :closed_lock_with_key: Unsuccessful Connection to Database\n\n\u003cdetails\u003e\n\n- **GET** _/healthz_ : Get the health of the API\n  - **Response:** 503 _Service Unavailable_\n\n\u003c/details\u003e\n\n#### ⛔️ Request Method Not Allowed\n\n\u003cdetails\u003e\n\n- **PUT** _/healthz_ : Get the health of the API\n  - **Response:** 405 _Method Not Allowed_\n- **POST** _/healthz_ : Get the health of the API\n  - **Response:** 405 _Method Not Allowed_\n- **PATCH** _/healthz_ : Get the health of the API\n  - **Response:** 405 _Method Not Allowed_\n- **DELETE** _/healthz_ : Get the health of the API\n  - **Response:** 405 _Method Not Allowed_\n\n\u003c/details\u003e\n\n#### ❌ Random Endpoints\n\n\u003cdetails\u003e\n\n- **GET** _/*_ : Random API endpoint\n  - **Response:** 404 _Not Found_\n- **PUT** _/*_ : Random API endpoint\n  - **Response:** 404 _Not Found_\n- **POST** _/*_ : Random API endpoint\n  - **Response:** 404 _Not Found_\n- **PATCH** _/*_ : Random API endpoint\n  - **Response:** 404 _Not Found_\n- **DELETE** _/*_ : Random API endpoint\n  - **Response:** 404 _Not Found_\n\n\u003c/details\u003e\n\n## :test_tube: Testing\n\nTo run the test suite with unit/integration testing, use the following commands:\n\n- To run the test suite in interactive mode:\n\n```shell\n  npm run test:dev\n```\n\n- To run the test suite without interactive mode:\n\n```shell\n  npm run test\n```\n\n## :rocket: Production\n\nTo build the app and run the app in production mode, use the following command:\n\n```shell\n  npm run build\n```\n\n## 🐳 Containerize the application\n\nWe will use `Docker` to containerize our application.\n\n### :arrow_heading_down: Install Docker Engine\n\nHead to [`https://docs.docker.com/engine/install/`](https://docs.docker.com/engine/install/) to install the `Docker` service for the required OS.\n\nIf you're using a MacOS based workstation, use [this link](https://docs.docker.com/desktop/install/mac-install/) and follow the instructions mentioned to install `Docker Desktop for MacOS` (Intel/Apple Silicon).\n\n\u003e NOTE: Beginning with Docker Desktop 4.3.0, `Docker` has removed the hard requirement to install Rosetta 2. There are a few optional command line tools that still require Rosetta 2 when using Darwin/AMD64. See [known issues](https://docs.docker.com/desktop/troubleshoot/known-issues/). However, to get the best experience, we recommend that you install Rosetta 2. To install Rosetta 2 manually from the command line, run the following command:\n\n  ```bash\n  softwareupdate --install-rosetta\n  ```\n\nTo verify the installation, run:\n\n```bash\ndocker version\n```\n\nFinally, create a [docker hub](https://hub.docker.com) account and login to your account through your terminal:\n\n```bash\ndocker login -u \u003cusername\u003e\n```\n\n### 🔨 Working with Docker\n\nTo build a docker image, we need to first be in the root folder of the application where our `Dockerfile` and `.dockerignore` files are present.\nThis provides docker context as to what to build and from where. The `.dockerignore` file is used to ignore files and folder from the build image. This reduces image overhead by not including things that are not required to build and run the image.\n\nA basic `Dockerfile` format looks like this:\n\n```dockerfile\nFROM node:lts-alpine\n\nWORKDIR /usr/src/webapp\n\nCOPY package*.json ./\n\nRUN npm install\n\nCOPY . .\n\nEXPOSE 3000\n\nCMD [\"npm\", \"run\", \"start:dev\"]\n```\n\n\u003e More details on what each command does, is available in the [official Docker documentation](https://docs.docker.com/engine/reference/builder/).\n\nOnce we have all the required docker files, we are now ready to `build` a docker image.\n\n- To build images specific to your system hardware architecture, use the `build` command:\n\n  ```bash\n  # -t flag for tag name, -f flag for Dockerfile name\n  # --no-cache tells docker to ignore any cached layers during the build process\n  # the final `.` is used to represent the build-context\n  docker build --no-cache -t \u003cdockerhub_username\u003e/\u003cimage_name\u003e:\u003ctag\u003e -f \u003cDockerfile-name\u003e .\n  ```\n\n- To push the images to [`docker hub`](https://hub.docker.com):\n\n  ```bash\n  # this pushes the docker images to the default docker hub.\n  docker image push --all-tags \u003cdockerhub_username\u003e/\u003cimage_name\u003e\n  ```\n\n- To tag and push the docker image to another registry host (other than `dockerhub`):\n\n  ```bash\n  # tag the image\n  docker -t \u003cimage_name\u003e:\u003ctag\u003e \u003cregistry_host\u003e/\u003cusername\u003e/\u003cimage_name\u003e:\u003ctag\u003e\n  # push to registry host\n  docker push \u003cregistry_host\u003e/\u003cusername\u003e/\u003cimage_name\u003e:\u003ctag\u003e\n  ```\n\n- To run a container locally based on a docker image, use the following command:\n\n  ```bash\n  # -ti flag will attach to the container in interactive mode\n  # -p flag is used to expose ports from container to local machine\n  # --rm flag is used to delete the container once docker is closed\n  docker run -ti --rm --name \u003ccontainer_name\u003e -p \u003clocal_port\u003e:\u003ccontainer_port\u003e [registry_name]/\u003cusername\u003e/\u003cimage_name\u003e:\u003ctag\u003e\n  ```\n\n- Clean all docker images, resources, containers and build cache using:\n\n  ```bash\n  # `docker system df` shows total space docker objects currently use\n  docker system prune -a -f\n  ```\n\n- To build images for various architectures (multi-platform build), use the [`buildx` CLI tool](https://docs.docker.com/engine/reference/commandline/buildx_create/) provided by `Docker`:\n\n  ```bash\n  docker buildx create --use\n  docker buildx ls\n  docker buildx build --platform=linux/amd64,linux/arm64 -f \u003cDockerfile_name\u003e --no-cache -t [registry_host]/\u003cusername\u003e/\u003cimage_name\u003e:\u003ctag\u003e -t [registry_name]\u003cusername\u003e/\u003cimage_name\u003e:\u003ctag\u003e .\n  ```\n\nHere are some other useful commands for working with `Docker`:\n\n- Docker logs: `docker logs \u003cID or container_name\u003e`\n- Docker interactive shell: `docker exec -ti \u003cID or container_name\u003e /bin/bash`\n- Docker stats: `docker stats \u003cID or container_name\u003e`\n- Docker inspect: `docker inspect \u003cID or container_name\u003e`\n- Docker pull: `docker pull \u003cimage_name\u003e:\u003ctag\u003e`\n- Docker login _(similar for other registry hosts)_:\n  - Dockerhub: `docker login`\n  - Quay.io: `docker login quay.io`\n- [Limit CPU and Memory](https://docs.docker.com/config/containers/resource_constraints/): `docker run --cpus=\".1\" -m \"8m`\n  \u003e `b`, `k`, `m`, `g` indicate bytes, kilobytes, megabytes, or gigabytes.\n\n## ⎈ Kubernetes and power tools\n\nWe will need kubernetes on our workstation to create clusters where we can run deployments to our application.\n\n\u003e NOTE: The steps mentioned below are only applicable to MacOS, for other distros, please use the documentation to guide you through the installation process.\n\n- Install `minikube` and `kind`\n\n  ```bash\n  brew install minikube # for single cluster setups\n  brew install kind # for multi-cluster setups\n  # verify installation\n  minikube version\n  kind version\n  ```\n\n- Install `kubectl` and set alias\n\n  ```bash\n  # check if you have `kubectl` since it comes pre-installed with `Docker`\n  kubectl version\n  # if not installed, use:\n  brew install kubernetes-cli\n  ```\n\n  To set an alias, edit your `.zshrc` file to include an alias for `kubectl`.\n\n  ```ini\n  # manage `.zsh_aliases separately`\n  alias k=\"kubectl\"\n  ```\n\n- Install power tools for k8s: `k9s`, kubectx` and `kubens`\n\n  We will use these tools extensively when working with k8s clusters.\n\n  ```bash\n  # install k9s\n  brew install k9s\n  # validate k9s version\n  k9s version\n  # `kubectx` installs `kubens` as well\n  brew install kubectx\n  ```\n\n- Install `tmux`, a powerful terminal window multiplexer tool\n\n  ```bash\n  brew install tmux\n  ```\n\n\u003e TIP: Checkout [sydrawat01/dotfiles](https://github.com/sydrawat01/dotfiles) for customization options for your terminal.\n\n### ⚙️ Working with k8s\n\nTo create a cluster for our RESTful API, we will use the containerized image create and uploaded to a docker image hub, which will be used in our `Deployment` resource. Additionally, we will also need to create a `Service` resource that will expose our app through a `LoadBalancer` via a `targetPort`.\n\nA `ConfigMap` and a `Secret` resource is required to configure the environment variables for the `webapp` application and `flyway` database migration configurations.\n\n- To create a k8s cluster, we will first need to start minikube:\n\n  ```bash\n  minikube start\n  ```\n\n- Create a namespace for our `webapp` deployment:\n\n  ```bash\n  k create namespace \u003cns-name\u003e\n  # to delete a namespace:\n  k delete namespaces \u003cns-name\u003e\n  ```\n\n- Switch namespace from `default` to your `\u003cns-name\u003e` namespace (from the previous step):\n\n  ```bash\n  kubens \u003cns-name\u003e\n  ```\n\n- Create the cluster with all the resources:\n\n  ```bash\n  k apply -f \u003cpath/to/\u003ek8s/\n  ```\n\n- Monitor the cluster using `k9s`:\n\n  ```bash\n  k9s\n  ```\n\n- To delete the cluster and its resources:\n\n  ```bash\n  k delete -f \u003cpath/to/\u003ek8s/\n  ```\n\n- To stop minikube and delete all resources create by it, use:\n\n  ```bash\n  minikube stop\n  minikube delete --all\n  # you will still need to manually delete the minikube docker image!\n  ```\n\n## :ninja: Author\n\n[Siddharth Rawat](mailto:rawat.sid@northeastern.edu)\n[Karan Wadhwa](mailto:wadhwa.k@northeastern.edu)\n[Rishab Agarwal](mailto:agarwal.risha@northeastern.edu)\n\n## :scroll: License\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsye7125-fall2023-group05%2Fwebapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsye7125-fall2023-group05%2Fwebapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsye7125-fall2023-group05%2Fwebapp/lists"}