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
Binary file added .DS_Store
Binary file not shown.
94 changes: 94 additions & 0 deletions .github/workflows/python-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Python CI

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: [ "master", "main", "lab03" ]
paths:
- "app_python/**"
- ".github/workflows/python-ci.yml"

pull_request:
branches: [ "master" ]
paths:
- "app_python/**"
- ".github/workflows/python-ci.yml"

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: set up
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
cache-dependency-path: |
app_python/requirements.txt

- name: dependencies
run: |
python -m pip install --upgrade pip
pip install -r app_python/requirements.txt

- name: snyk
uses: snyk/actions/python@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK }}
with:
args: --severity-threshold=high

- name: Linter
run: |
pip install flake8
flake8 app_python/ --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 app_python/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Run tests with coverage
working-directory: app_python
run: pytest --cov=. --cov-report=xml --cov-fail-under=70

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: app_python/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}

docker:
name: docker
needs: test
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/lab03' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker metadata (CalVer)
id: meta
uses: docker/metadata-action@v5
with:
images: abrahambarrett228/devops-info-service
tags: |
type=raw,value={{date 'YYYY.MM'}}
type=raw,value={{date 'YYYY.MM'}}.${{ github.run_number }}
type=raw,value=latest

- name: Build and push
uses: docker/build-push-action@v6
with:
context: app_python
push: true
tags: ${{ steps.meta.outputs.tags }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test
test
venv
20 changes: 20 additions & 0 deletions app_python/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__pycache__/
*.pyc
*.pyo
*.pyd

venv/
.venv/
env/

.git/
.vscode/
.idea/

*.log
pytest_cache/
.coverage
htmlcov/

docs/
tests/
12 changes: 12 additions & 0 deletions app_python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Python
__pycache__/
*.py[cod]
venv/
*.log

# IDE
.vscode/
.idea/

# OS
.DS_Store
19 changes: 19 additions & 0 deletions app_python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.13-slim

ARG PORT=5000

WORKDIR /app/app_python

COPY requirements.txt .
COPY app.py .

RUN \
pip install --no-cache-dir -r requirements.txt && \
useradd --create-home --shell /usr/sbin/nologin appuser &&\
chown -R appuser /app/app_python

USER appuser

EXPOSE ${PORT}

CMD [ "python", "app.py" ]
117 changes: 117 additions & 0 deletions app_python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Python Web Server

## Overview

This web server provides information about itself and its environment.

## Prerequisites

- Python 3.14.0
- pip
- git
## Installation

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

## Running the Application

You can create `.env` file storing all enviroment values. To run application simply type:

```bash
python app.py
```

## Docker Support

### Building from Source

Create a Docker image locally from the application code:

```bash
docker build -t <image-name>:<tag> .
```

### Container Execution

Run the application in an isolated container environment:

```bash
docker run --rm -p <host-port>:<container-port> --name <container-name> <image-name>:<tag>
```


### Using Pre-built Images

The service is also available on Docker Hub for immediate deployment:

```bash
# Download the published image
docker pull abrahambarrett228/lab02

# Run the downloaded image
docker run --rm -p 5000:5000 abrahambarrett228/lab02
```

### Container Management

Basic operations for container lifecycle management:

```bash
# List running containers
docker ps

# Stop a running container
docker stop <container-name>

# View container logs
docker logs <container-name>

# Interactive shell access
docker exec -it <container-name> /bin/sh
```

## API Endpoints

- `GET /` - service data
- `GET /health` - Health check

## Configuration

Supported enviroment values:

- `HOST` - address of the application
- `PORT` - port of the application
- `DEBUG` - `[true/false]` do/don't enable debug features


## Testing

### Running Tests

Install dependencies
```bash
pip install -r requirements.txt
```

Run tests
```bash
pytest
```

Run with coverage (pytest-cov should be installed)
```bash
pytest --cov=app --cov-report=term
```

### Test Structure

Tests are located in `app_python/tests/` directory.


- `app_python/tests/test_error_endpoint.py` - tests related to errors
- `app_python/tests/test_health_endpoint.py` tests related to health endpoint
- `app_python/tests/test_mainpage_endpoint.py` tests related to the root endpoint
Loading