Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions labs/lab18/app_python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

RUN groupadd -g 1000 nonroot \
&& useradd -r --no-create-home -u 1000 -g nonroot nonroot

RUN mkdir -p /data && chown -R nonroot:nonroot /data && chmod 755 /data

USER nonroot

EXPOSE 5000/tcp

ENTRYPOINT ["python", "app.py"]
82 changes: 82 additions & 0 deletions labs/lab18/app_python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Overview

Lightweight web application built using __FastAPI__. It provides essential service and system information, along with a health check endpoint to monitor application status. The application shares various details about the server environment, including runtime status and configuration.

## Prerequisites

Before you begin, ensure you have the following prerequisites:

Python Version: Python 3.11 or higher
Dependencies: The application depends on the FastAPI framework and other packages specified in the requirements.txt file.

## Installation

```bash
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

## Running the Application

```bash python app.py
# Or with custom config
PORT=8080 python app.py
```

## How to run using Docker

### Build your own docker image

```bash
cd app_python
docker build -t <tag> .
```

### OR pull from Docker Hub

```bash
docker pull bulatgazizov/app_python:0.0.1
```

### Run application

```bash
docker run -p 5000:<expose port> <tag>
```

## API Endpoints

| Method | Endpoint | Description |
|--------|------------|-----------------------------------------|
| GET | / | Service and system information. |
| GET | /health | Health check for the application. |

### `/` - Service and System Information

This endpoint returns information about the service, system details, and configuration.

### `/health` - Health Check

This endpoint returns the health status of the application along with the current timestamp.

### `/visits`

Return current visits count.

Example:

```json
{
'visits': 43,
'timestamp': "YYYY-MM-DD HH:MM:SS.mmmmmm"
}
```

## Configuration

| Environment Variable | Description | Default Value |
|----------------------|-----------------------------------------|---------------|
| `HOST` | The host address for the application. | `0.0.0.0` |
| `PORT` | The port the application listens on. | `5000` |
| `DEBUG` | Enables debug mode if set to `true`. | `false` |
Binary file not shown.
Loading
Loading