Skip to content

Commit 7961020

Browse files
authored
Merge pull request #1 from kchandan/main
Project 1 and other code
2 parents f30d13e + 42d5e54 commit 7961020

File tree

8 files changed

+141
-0
lines changed

8 files changed

+141
-0
lines changed

custom-nginx/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx
2+
COPY index.html /usr/share/nginx/html/index.html

custom-nginx/Dockerfile.ubuntu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM ubuntu
2+
RUN apt-get update && apt-get install -y nginx git && apt-get clean

custom-nginx/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Custom Nginx</title>
7+
</head>
8+
<body>
9+
<h1>Welcome to My Custom Nginx!</h1>
10+
<p>This page is served from a custom Docker image built by you.</p>
11+
</body>
12+
</html>

project-1/db/init.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
name VARCHAR(100),
4+
email VARCHAR(100) UNIQUE
5+
);
6+
7+
INSERT INTO users (name, email) VALUES
8+
('John Doe', 'john@example.com'),
9+
('Jane Smith', 'jane@example.com');

project-1/frontend/app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from sqlalchemy import create_engine, text
2+
import streamlit as st
3+
4+
# Database connection
5+
DATABASE_URL = "postgresql://user:password@db:5432/mydb"
6+
engine = create_engine(DATABASE_URL)
7+
8+
st.title("User Management")
9+
10+
# Button to load users
11+
if st.button("Load Users"):
12+
with engine.connect() as connection:
13+
result = connection.execute(text("SELECT * FROM users"))
14+
users = [dict(row._mapping) for row in result] # Use row._mapping for conversion
15+
st.write(users)

project-1/frontend/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
streamlit
2+
sqlalchemy
3+
psycopg2-binary

project-1/monitoring/prometheus.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
global:
2+
scrape_interval: 15s
3+
4+
scrape_configs:
5+
- job_name: 'docker'
6+
static_configs:
7+
- targets: ['frontend:8501']
8+
- job_name: 'postgres'
9+
static_configs:
10+
- targets: ['db:5432']
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
### Assignment: Building a Simplified Data Application with Docker Compose
2+
3+
#### **Objective**
4+
The goal of this assignment is to create a data application using **Docker Compose**, incorporating concepts of storage, networking, and multiple interconnected applications. This assignment will also involve initializing a database and deploying monitoring tools (Prometheus and Grafana) to ensure proper application monitoring.
5+
6+
---
7+
8+
### **Assignment Requirements**
9+
10+
#### **1. Application Overview**
11+
You are tasked with creating a simplified data application with the following components:
12+
- **Frontend**: A **Streamlit** application for user interaction.
13+
- **Database**: A **PostgreSQL** database for persistent storage, preloaded with a table and sample data during initialization.
14+
- **Monitoring**: Deploy **Prometheus** for metrics collection and **Grafana** for visualizing application metrics.
15+
16+
#### **2. Functional Requirements**
17+
- **Frontend**:
18+
- Provide a web interface using Streamlit.
19+
- The interface should allow users to query and visualize data directly from the database.
20+
- **Database**:
21+
- Use PostgreSQL with an initialized schema and preloaded data.
22+
- The database schema should include a sample table (e.g., `users` or `sales`).
23+
- **Monitoring**:
24+
- Configure Prometheus to scrape metrics from all running services.
25+
- Set up a Grafana dashboard to visualize the metrics (CPU, memory, requests, etc.).
26+
27+
#### **3. Technical Requirements**
28+
- **Docker Compose Configuration**:
29+
- Use Docker Compose to define and orchestrate all services.
30+
- Services should include `frontend`, `db`, `prometheus`, and `grafana`.
31+
- **Networking**:
32+
- Create a private network for the application.
33+
- Ensure secure communication between services using the Docker network.
34+
- Expose necessary ports for external access (e.g., 8501 for Streamlit, 9090 for Prometheus, and 3000 for Grafana).
35+
- **Storage**:
36+
- Use volumes for persistent storage of the database and Prometheus data.
37+
- Ensure that logs and other stateful data are not lost upon container restart.
38+
39+
#### **4. Steps to Follow**
40+
1. **Database Initialization**:
41+
- Create a SQL script to initialize the database schema and insert sample data.
42+
- Mount the SQL script as a volume in the PostgreSQL container.
43+
44+
2. **Frontend Service**:
45+
- Create a Streamlit application to interact directly with the database.
46+
- Include features for querying and visualizing data from the database.
47+
48+
3. **Monitoring Setup**:
49+
- Configure Prometheus to scrape metrics from all running services.
50+
- Set up a Grafana container with a predefined dashboard to visualize Prometheus metrics.
51+
52+
4. **Docker Compose**:
53+
- Write a `docker-compose.yml` file to define and manage all services.
54+
- Include health checks for all services to ensure proper initialization.
55+
56+
---
57+
58+
### **Deliverables**
59+
1. A `docker-compose.yml` file defining all services.
60+
2. A folder structure with:
61+
- `frontend/`: Contains the Streamlit app.
62+
- `db/`: Contains the SQL initialization script.
63+
- `monitoring/`: Configuration files for Prometheus and Grafana.
64+
3. Documentation (in a `README.md` file) that includes:
65+
- Setup and deployment instructions.
66+
- Descriptions of each service and their interactions.
67+
- How to access the application and monitoring dashboards.
68+
69+
---
70+
71+
### **Evaluation Criteria**
72+
- **Completeness**:
73+
- All components (frontend, database, Prometheus, Grafana) are correctly configured and working.
74+
- **Code Quality**:
75+
- Clean and modular code for the frontend.
76+
- **Docker Knowledge**:
77+
- Proper usage of volumes, networks, and multi-service orchestration in Docker Compose.
78+
- **Monitoring**:
79+
- Prometheus and Grafana are correctly set up and functional.
80+
- **Documentation**:
81+
- Clear and concise instructions in the `README.md` file.
82+
83+
---
84+
85+
### **Bonus Tasks**
86+
1. Add additional metrics or alerts in Prometheus and visualize them in Grafana.
87+
2. Use environment variables in `docker-compose.yml` for configuration (e.g., database credentials).
88+

0 commit comments

Comments
 (0)