Skip to content

Commit 0b00d13

Browse files
committed
Added ai app and simple webapp
1 parent 95b35d5 commit 0b00d13

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed

project-ai-app/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
## Install Ollama on Linux
3+
4+
```
5+
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
6+
```
7+
8+
```
9+
Unable to find image 'ollama/ollama:latest' locally
10+
latest: Pulling from ollama/ollama
11+
6414378b6477: Pull complete
12+
9423a26b200c: Pull complete
13+
629da9618c4f: Pull complete
14+
00b71e3f044c: Pull complete
15+
Digest: sha256:18bfb1d605604fd53dcad20d0556df4c781e560ebebcd923454d627c994a0e37
16+
Status: Downloaded newer image for ollama/ollama:latest
17+
2352d454e7117a79459cd7d1413e686680a80927494ff6dbd70faebd3dcfabb0
18+
```
19+
20+
## Pull Llama 3.2:1b Model
21+
22+
```
23+
curl http://localhost:11434/api/pull -d '{
24+
"model": "llama3.2:1b"
25+
}'
26+
```
27+
28+
```
29+
docker exec -it ollama ollama ls
30+
```
31+
32+
## Test if the model is serving
33+
34+
```
35+
curl http://localhost:11434/api/chat -d '{
36+
"model": "llama3.2:1b",
37+
"messages": [
38+
{
39+
"role": "user",
40+
"content": "Where is Paris"
41+
}
42+
],
43+
"stream": false
44+
}'
45+
```
46+
47+
```
48+
docker exec -it ollama ollama ps
49+
NAME ID SIZE PROCESSOR UNTIL
50+
llama3.2:1b baf6a787fdff 2.2 GB 100% CPU 4 minutes from now
51+
```
52+
53+
54+
## Clone the AI Application
55+
56+
Fork the Github Repo - https://github.com/db-agent/db-agent
57+
58+
```
59+
git clone https://github.com/db-agent/db-agent.git
60+
61+
```
62+
63+
## Build and deploy the App
64+
65+
```
66+
cd db-agent
67+
docker compose -f docker-compose.local.yml build
68+
docker compose -f docker-compose.local.yml up -d
69+
# Check logs
70+
docker compose -f docker-compose.local.yml logs -f
71+
72+
73+
```
74+

project-simple-webapp/README.mp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Assignment: Building a 3-Tier Application Using Docker Compose
2+
3+
## Objective
4+
This assignment will guide you through designing and deploying a 3-tier application architecture using **Docker Compose**. The 3-tier architecture includes a web server (frontend), an application server (backend), and a database server (DB). Each tier is containerized and orchestrated using Docker Compose.
5+
6+
---
7+
8+
## Application Overview
9+
10+
You will create a simple web application with the following components:
11+
12+
1. **Web Server (Frontend)**: A **Nginx** server to serve static content and act as a reverse proxy for the application server.
13+
2. **Application Server (Backend)**: A Python Flask application that handles business logic and interacts with the database.
14+
3. **Database Server**: A **PostgreSQL** database to store application data.
15+
16+
---
17+
18+
## Tasks
19+
20+
### 1. Database Server
21+
- Use PostgreSQL as the database.
22+
- Initialize the database with a schema and some sample data.
23+
- Expose the necessary port to allow the application server to connect.
24+
25+
### 2. Application Server
26+
- Create a Flask application that:
27+
- Connects to the database to fetch and store data.
28+
- Exposes RESTful APIs for the web server to consume.
29+
- Use environment variables to configure database credentials.
30+
31+
### 3. Web Server
32+
- Use Nginx to serve static files.
33+
- Configure Nginx as a reverse proxy to forward API requests to the application server.
34+
35+
### 4. Docker Compose
36+
- Define all three services (`web`, `app`, `db`) in a `docker-compose.yml` file.
37+
- Set up networking to allow communication between the services.
38+
- Use Docker volumes for persistent data storage.
39+
40+
41+
---
42+
43+
## Deliverables
44+
1. A `docker-compose.yml` file to orchestrate the services.
45+
2. Configuration files for the database, application, and web server.
46+
3. A fully functional 3-tier application accessible from the browser.
47+
4. A `README.md` with clear setup and deployment instructions.
48+

project-simple-webapp/app/app.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from flask import Flask, jsonify
2+
from sqlalchemy import create_engine, text
3+
4+
app = Flask(__name__)
5+
6+
DATABASE_URL = "postgresql://user:password@db:5432/mydb"
7+
engine = create_engine(DATABASE_URL)
8+
9+
@app.route('/api/users', methods=['GET'])
10+
def get_users():
11+
with engine.connect() as connection:
12+
result = connection.execute(text("SELECT * FROM users"))
13+
users = [dict(row._mapping) for row in result]
14+
return jsonify(users)
15+
16+
if __name__ == "__main__":
17+
app.run(host="0.0.0.0", port=5000)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask
2+
sqlalchemy
3+
psycopg2-binary

project-simple-webapp/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+
('Alice', 'alice@example.com'),
9+
('Bob', 'bob@example.com');

project-simple-webapp/web/nginx.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
server {
2+
listen 80;
3+
4+
location / {
5+
proxy_pass http://app:5000;
6+
}
7+
}

0 commit comments

Comments
 (0)