Skip to content

A fully containerized spring-boot application to serve as a simple online store. The aim of the project is to demonstrate the use of DevOps tools and how to apply this methodology

osamamagdy/Online-Store

 
 

Repository files navigation

Online store

Resources

The original spring-boot application was inspired from here

Steps to build locally

1 - First, ensure to have Java JDK/JRE and maven installed on your local machine

  a - install Java JDK by running the command sudo apt install default-jdk -y
  b - install Java JRE by running the command sudo apt install default-jre -y
  c - install maven bwith sudo apt install maven -y

2 - Second, install and configure mysql

  a - install from here
  b - configure mysql by creating a user with mysql_native_password for the authentication method. You can take guidance from here
  c - create database for the application ( use the same guide above )

3 - Put the information in a new .env file

MYSQL_DB_HOST=
MYSQL_DB_PORT=
MYSQL_DB_USERNAME=
MYSQL_DB_PASSWORD=
MYSQL_DB_DNAME=

  Note: all names and passwords will be updated in the src/main/resources/application.properties file

4 - Build the jar file and run

  a - Run the command mvn clean install. This will create a directory named target.
  b - navigate to the target directory and run the jar file with java -jar <file_name.jar>

Build locally using Docker

1 - Install Docker & Docker-Compose

  a - Install docker from the official documentation here
  b - Install docker-compose from the official documentation here
  Note: If you choose to build with docker, you will not need all the previous installation for running the project locally. You only need to install docker and docker-compose and it saves you the hassle of installing JDK, JRE, maven, and even mysql.

2 - Put the information in a new .env file

  For the sake of consistency, we use the same name while building locally

MYSQL_DB_HOST=db  #this one is necessary as it is the service name in docker-compose.yaml file
MYSQL_DB_PORT=3306 #this is the default port used by mysql official image so don't choose any port else
MYSQL_DB_USERNAME=
MYSQL_DB_PASSWORD=
MYSQL_DB_DNAME=

3 - Build and Run

  Run the command docker-compose up in the directory where docker files are. Docker will first pull the needed images and start working.
  If you want to edit the configurations and build again, run docker-compose up --build to ignore chache and start building again.

Deploy with kubernetes

1 - Install minikube

  a - For testing purposes, we can deploy all our kubernetes deployments on a locally created single-node cluster with minikube here
  Note: If you are running your ubuntu on a virtual machine upon other OS, you may need to follow this guide instead.

2 - Put the information in a new secret.yaml file (all files are in the k8s_yaml directory)

  a - Here, we will replace the .env file with two files. A configmap.yaml which contains non-sensetive data to be accessible by all cluster resources (this one is created for you and is present in the repository.
  b - A secret.yaml which contains sensetive data that not to be shared on publuic repository so create the file first and fill the data below

apiVersion: v1
kind: Secret
metadata:
    name: mysql-secret
type: Opaque
data:
    MYSQL_DB_PORT: 
    MYSQL_DB_USERNAME: 
    MYSQL_DB_PASSWORD: 
    MYSQL_DB_DNAME: 

  Important Note: you can not just place the values in the secrets file as a plain text, first you will need to encode them to base64 (as k8s will decode them by default). And the way to do this in linux echo -n text | base64 , or you can use a website like here

3 - Build and Run with external ip

  a - You will need to run kubectl apply -f <file_name>.yaml to apply the configurations of each file. But due to using secrets and services, you will need to execute them in specific order
   I - secrets file
   II - mysql deployment files
   III - mysql service files
   IV - config map file
   V - online-store deployment file
   VI - online-store-service file
  b - The loadbalancer used in online-store-service will assign an external ip → with using minikube, it will be in pending state until you allow it to take ip by typing “minikube service <NAME_OF_SERVICE>”

 Note: If you want to edit any of the configurations, run kubectl apply -f <file_name>.yaml.

4 - Build and Run with ingress and domain name

  a - The configuration files used for this are online-store-ingress.yaml and online-store-internal-service.yaml (this will be applied instead of online-store-service.yaml)
  b - Install the ingress-controller pod in your k8s cluster → with minikube you type minikube addons enable ingressand it will be added in the kube-system namespace
  c - apply online-store-internal-service.yaml ( note that if you used the above steps exactly, you will have 2 services mapping to the same deployment and it is fine for testing. Otherwise, delete the service online-store-service )
  d - apply the online-store-ingress.yaml ( note that you will replace the file in step 6 above with )
  e - this will create an IP address to the hostname osama.com → type kubectl get ingress to know
  f - For testing and with using minikube, this is a dummy hostname that is not available publicly. So we have to map it explicitly to the address created by minkube
  g - to map in your linux, type sudo nano /etc/hosts → add the IP address created in step 5 and the hostname associated with it osama.com
  h - Go to osama.com in your browser to open the application

About

A fully containerized spring-boot application to serve as a simple online store. The aim of the project is to demonstrate the use of DevOps tools and how to apply this methodology

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 54.7%
  • HTML 36.1%
  • HCL 7.7%
  • Dockerfile 1.5%