This project is a number-guessing game built with Node.js, where players try to guess a number between 1 and 20. It includes a global scoreboard for all players, powered by a MongoDB database. The game is specifically designed to practice various DevOps tools and techniques, such as GitHub Actions for CI/CD, Terraform for infrastructure management, and Ansible for configuration automation.
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
Make sure you have the following software installed on your machine:
-
Clone the repository:
Open your terminal and run the following command to clone the repository:
git clone https://github.com/OmarZakaria10/Guessing_Game-ExpressJS.git
-
Navigate to the project directory:
cd Guessing_Game-ExpressJS
-
Install the dependencies:
Run the following command to install all the necessary dependencies:
npm install
-
Start the project:
After the dependencies are installed, start the project using:
npm start
This will start the project and you should see output indicating that the project is running.
- the server uses port 8080
- to use the app in same machine you have installed the app on click local
- if you are group and want to compete with each other open your browser and write
ip of machine with app installed on
:8080/ - click in scoreboad on navbar to see best 5 scores
If you have docker installed on your machine you can download image
-
Pull the Image from docker hub
Open your terminal and run the following command to pull the image:
docker pull omarzakaria10/guessing_game:latest
-
Run the Docker Container
Open your terminal and run the following command to Run the Docker Container:
docker run -it -p 8080:8080 omarzakaria10/guessing_game:latest
-
Run the game
now open you browser and type
http://localhost:8080/
Automate deployment on AWS, install Docker, and run the application using Terraform and Ansible.
Terraform configuration files are included to create three instances in the AWS us-east-1 region and a security group to allow SSH access.
To deploy with Terraform:
terraform init
terraform apply
Use the provided Ansible playbook to connect to the instances, update the system, install Docker, and run the application.
To run Ansible against hosts:
Add the public IPs of your AWS instances and the path to your private key in the hosts.ini file.
Navigate to the Ansible directory and execute the playbook:
cd ansible/
ansible-playbook -i hosts.ini main.yaml
Open your browser and go to http://<instance-ip>
to play the game.
Deploy the Guessing Game application using Kubernetes on Minikube.
Start the Minikube cluster:
minikube start
Create a ConfigMap from an environment file to provide environment variables for the application:
kubectl create configmap myapp-env --from-env-file=../config.env -n myapp-namespace
Create a Kubernetes namespace for the application and Apply the deployment configuration to create the application's deployment and Ingress:
cd kubernetes/
kubectl apply -f namespace.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
minikube addons enable ingress
To access your app using the custom domain (myapp.local), you need to add an entry in your local /etc/hosts file to point myapp.local to your Minikube IP address.
minikube ip
sudo nano /etc/hosts
<minikube-ip> myapp.local
Now you can access your application using the custom domain name:
Open your web browser and go to: http://myapp.local
-
Make sure You have Helm installed
-
Navigate to the kubernetes/ directory where your Helm chart is located and install the chart:
cd /kubernetes
helm install myapp ./app-chart
minikube ip
http://<minikube-ip>:30080