add scripts, dockerfile and readme
This commit is contained in:
parent
3eef28fc10
commit
be4210f197
20
z2/Dockerfile
Normal file
20
z2/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
FROM python:3.9-slim
|
||||||
|
|
||||||
|
# Set the working directory to /app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy requirements.txt from the app folder
|
||||||
|
COPY ./app/requirements.txt .
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
# Copy the entire app folder into the container
|
||||||
|
COPY ./app /app
|
||||||
|
|
||||||
|
# Expose port 5000
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
# Run the app
|
||||||
|
CMD ["python", "app.py"]
|
||||||
|
|
68
z2/README.md
Normal file
68
z2/README.md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# Travel Planner Application
|
||||||
|
|
||||||
|
This is a simple Flask-based web application that helps users plan and manage their travels, including the ability to add, view, edit, and remove trips and stages.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Minikube installed and running (for Kubernetes setup).
|
||||||
|
- Docker installed (for building containers).
|
||||||
|
- Python 3.x
|
||||||
|
- PostgreSQL database (set up using Kubernetes and Docker).
|
||||||
|
- Flask library installed.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
To prepare and start the application, you can use the following bash scripts.
|
||||||
|
|
||||||
|
### 1. Prepare the Application
|
||||||
|
|
||||||
|
First, ensure you have everything set up correctly by running the `prepare-app.sh` script. This script prepares the application for deployment.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./prepare-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Start the Application
|
||||||
|
|
||||||
|
After preparing the application, use the `start-app.sh` script to start it. This will launch your application and give you the URL to access it at the end of the script.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./start-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The URL to access the app will be displayed at the end of the script output.
|
||||||
|
|
||||||
|
## Functionality
|
||||||
|
|
||||||
|
### Travel Management
|
||||||
|
|
||||||
|
- **Add a new trip**: Fill in the traveler name, trip name, start date, and end date.
|
||||||
|
- **View all trips**: A list of all trips is displayed.
|
||||||
|
- **Edit a trip**: You can modify the details of an existing trip.
|
||||||
|
- **Remove a trip**: Delete a trip from the database.
|
||||||
|
|
||||||
|
### Stage Management
|
||||||
|
|
||||||
|
- **Add a stage**: For each trip, you can add stages (cities) along with their order.
|
||||||
|
- **View stages**: The stages for each trip are listed with their order.
|
||||||
|
- **Edit a stage**: You can modify the details of each stage.
|
||||||
|
- **Remove a stage**: Delete a stage from a trip.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
The application uses the following technologies:
|
||||||
|
|
||||||
|
- **Flask** for the web framework.
|
||||||
|
- **PostgreSQL** for the database (configured to run with Kubernetes).
|
||||||
|
- **Kubernetes** for deploying the application.
|
||||||
|
- **Docker** for containerizing the app.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- Ensure that the PostgreSQL database is correctly running and connected to the application.
|
||||||
|
- Check the logs if any errors occur during the start-up process.
|
||||||
|
- Make sure the Kubernetes cluster is set up correctly and all pods are running.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the MIT License.
|
15
z2/prepare-app.sh
Normal file
15
z2/prepare-app.sh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "Preparing app"
|
||||||
|
|
||||||
|
minikube start
|
||||||
|
# build image Docker
|
||||||
|
docker build -t chabooo/travel-planner:latest .
|
||||||
|
|
||||||
|
echo "Sucessfuly built"
|
||||||
|
|
||||||
|
# push docker image
|
||||||
|
docker push chabooo/travel-planner:latest
|
||||||
|
|
||||||
|
echo "sucessfuly pushed"
|
||||||
|
|
||||||
|
echo "Preparation completed."
|
41
z2/start-app.sh
Normal file
41
z2/start-app.sh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "Start Kubernetes objects "
|
||||||
|
|
||||||
|
# Apply Kubernetes resources
|
||||||
|
kubectl apply -f k8s/namespace.yaml
|
||||||
|
kubectl apply -f k8s/persistant-volume.yaml
|
||||||
|
kubectl apply -f k8s/persistant-volume-claim.yaml
|
||||||
|
kubectl apply -f k8s/postgres-service.yaml
|
||||||
|
kubectl apply -f k8s/statefulset.yaml
|
||||||
|
kubectl apply -f k8s/deployment.yaml
|
||||||
|
kubectl apply -f k8s/service.yaml
|
||||||
|
|
||||||
|
echo "Kubernetes objects are applied. Waiting for pods to be ready..."
|
||||||
|
|
||||||
|
# Wait for all pods in the namespace to be in Running state
|
||||||
|
namespace="travel-planner"
|
||||||
|
timeout=300 # Timeout in seconds
|
||||||
|
interval=5 # Interval between checks
|
||||||
|
|
||||||
|
for ((i=1; i<=$timeout; i+=$interval)); do
|
||||||
|
ready_pods=$(kubectl get pods -n $namespace --field-selector=status.phase=Running --no-headers | wc -l)
|
||||||
|
total_pods=$(kubectl get pods -n $namespace --no-headers | wc -l)
|
||||||
|
|
||||||
|
if [ "$ready_pods" -eq "$total_pods" ] && [ "$total_pods" -gt 0 ]; then
|
||||||
|
echo "All pods are ready!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Waiting for pods to be ready... ($ready_pods/$total_pods)"
|
||||||
|
sleep $interval
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$ready_pods" -ne "$total_pods" ]; then
|
||||||
|
echo "Timeout reached. Some pods are not ready."
|
||||||
|
kubectl get pods -n $namespace
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "App is running."
|
||||||
|
echo "Go here to view the app"
|
||||||
|
minikube service travel-planner -n travel-planner --url
|
46
z2/stop-app.sh
Normal file
46
z2/stop-app.sh
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "Stopping Kubernetes objects..."
|
||||||
|
|
||||||
|
# Namespace variable
|
||||||
|
namespace="travel-planner"
|
||||||
|
|
||||||
|
# Delete resources in the namespace
|
||||||
|
kubectl delete -f k8s/service.yaml -n $namespace
|
||||||
|
kubectl delete -f k8s/deployment.yaml -n $namespace
|
||||||
|
kubectl delete -f k8s/postgres-service.yaml -n $namespace
|
||||||
|
kubectl delete -f k8s/persistant-volume-claim.yaml -n $namespace
|
||||||
|
kubectl delete -f k8s/persistant-volume.yaml -n $namespace
|
||||||
|
kubectl delete -f k8s/statefulset.yaml -n $namespace
|
||||||
|
|
||||||
|
# Delete namespace last
|
||||||
|
kubectl delete -f k8s/namespace.yaml
|
||||||
|
|
||||||
|
# Check if namespace is fully deleted
|
||||||
|
timeout=60
|
||||||
|
for ((i=1; i<=$timeout; i++)); do
|
||||||
|
if ! kubectl get namespace $namespace &> /dev/null; then
|
||||||
|
echo "Namespace $namespace successfully deleted."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
echo "Waiting for namespace $namespace to be deleted..."
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
if kubectl get namespace $namespace &> /dev/null; then
|
||||||
|
echo "Error: Namespace $namespace was not deleted within the timeout."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All Kubernetes objects have been deleted."
|
||||||
|
|
||||||
|
# Stop Minikube
|
||||||
|
echo "Stopping Minikube..."
|
||||||
|
minikube stop
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Minikube stopped successfully."
|
||||||
|
else
|
||||||
|
echo "Error: Failed to stop Minikube."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Application and Minikube stopped successfully."
|
Loading…
Reference in New Issue
Block a user