/readme-app

web application which holds and manages articles to read

Primary LanguageJava

Readme App

Introduction

Web application which holds and manages articles to read out.

Microservice endpoints

Below you can find endpoints exposed by this microservice.

Online API documentation

Management endpoints

Monitoring

To collect metrics uses Prometheus.

Grafana monitors metrics

Running on local machine

environmental variables

Set up following env variables. Easiest way is over .env file.

APP_AUTH_TOKEN_SECRET=
GITHUB_CLIENT_ID= 
GITHUB_CLIENT_SECRET=
SPRING_DATASOURCE_USERNAME=
SPRING_DATASOURCE_PASSWORD=

back-end

  1. Build with maven
 mvn package -DskipTests
  1. run locally
 mvn spring-boot:run
  1. test locally
 http://localhost:8080

front-end

  1. switch to angular directory
cd /angular
  1. download all dependencies
npm install
  1. run locally
npm run start
  1. test locally
http://localhost:4200

Containerization

single container app

back-end

  1. Build a docker image using Dokerfile:
docker build -t webcane/readme-app-spring .
  1. Run docker image locally
docker run --name readme-app-spring -p 8080:8080 webcane/readme-app-spring

front-end

  1. Build docker image
docker build -t webcane/readme-app-angular ./angular
  1. Run docker image locally
docker run --name readme-app-angular -p 4200:80 webcane/readme-app-angular

docker

  1. check if docker running
 docker ps
  1. stop the docker image
 docker stop <container id>

two containers

multi-container app

Containers, by default, run in isolation and don’t know anything about other processes or containers on the same machine. So, allow one container to talk to another.

container networking

  1. create docker network
docker network create readme-app-net

back-end

  1. Run docker image
 docker run --network readme-app-net --network-alias app --name readme-app-spring -p 8080:8080 webcane/readme-app-spring

front-end

  1. Run docker image
docker run --network readme-app-net --network-alias ui --name readme-app-angular -p 4200:80 webcane/readme-app-angular

Use Docker Compose

Docker Compose is a tool that was developed to help define and share multi-container applications.

  1. build containers for first time
docker-compose build
  1. start back-end and front-end together
docker-compose up

multi containers

  1. do clean-up at the end
docker-compose down -v

docker hub

Push images to the container registry:

docker push webcane/readme-app-spring:latest
docker push webcane/readme-app-angular:latest

Kubernetes

bitnami

helm repo add bitnami https://charts.bitnami.com/bitnami

downloads the postgresql dependency

 helm dependency update

helm

Run tests to ensure that the chart is well-formed

helm lint ./helm

nginx ingress controller

Deploy the ingress controller with the following command:

helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace

Debugging Templates

It will validate and verify your chart by connecting to kubernetes api server and after successful validation it will render the manifest in the form of YAMLs (kubernetes resources) locally.

helm install readme-app ./helm --dry-run --debug

install

install readme-app chart to the kubernetes cluster

helm install readme-app ./helm

provides required configs and secrets. It will be dynamically located in readme-app-env ConfigMap and Secrets respectively and linked into deployment

helm install --set app.secrets.APP_AUTH_TOKEN_SECRET=*** \
--set app.secrets.SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENT_ID=*** \
--set app.secrets.SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENT_SECRET=*** \
--set postgresql.auth.password=*** --set postgresql.auth.postgresPassword=*** readme-app ./helm