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
13 changes: 13 additions & 0 deletions .github/cache-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"cache": {
"pip": true,
"docker": true,
"node": false,
"actions": true
},
"optimizations": {
"parallel_jobs": true,
"skip_duplicate_actions": true,
"cancel_in_progress_on_new_commit": true
}
}
65 changes: 65 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI/CD Pipeline

on:
push:
branches: [ main, master ]
paths:
- 'app_python/**'
pull_request:
branches: [ main, master ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
cache-dependency-path: 'app_python/requirements.txt'

- name: Install dependencies
working-directory: ./app_python
run: |
pip install -r requirements.txt
pip install pytest pytest-cov httpx

- name: Test with pytest
working-directory: ./app_python
run: |
python -m pytest tests/ -v --cov=app --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./app_python/coverage.xml

build:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')

steps:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

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

- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./app_python
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:latest
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:${{ github.sha }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test
.vscode
78 changes: 78 additions & 0 deletions app_python/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Python
__pycache__/
*.py[cod]
*.pyo
*.so
*.pyd
.Python

# Virtual environments
venv/
env/
ENV/
env.bak/
venv.bak/
.venv/

# Distribution / packaging
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
tests/

# Logs
*.log
logs/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Git
.git/
.gitignore

# Docker
Dockerfile
docker-compose*.yml

# Documentation
docs/
*.md
LICENSE
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
18 changes: 18 additions & 0 deletions app_python/.pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[pytest]
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts =
-v
--tb=short
--strict-markers
--disable-warnings
--cov=.
--cov-report=term-missing
--cov-report=xml
--cov-report=html
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
integration: integration tests
unit: unit tests
53 changes: 53 additions & 0 deletions app_python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Build stage for Python dependencies (optional - can use for compilation if needed)
FROM python:3.13-slim AS builder

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*

# Copy requirements first for better layer caching
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

# Final stage
FROM python:3.13-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
PORT=5000

# Create non-root user
RUN groupadd -r appuser && useradd -r -m -g appuser appuser

# Set working directory
WORKDIR /app

# Copy Python packages from builder stage
COPY --from=builder /root/.local /home/appuser/.local
ENV PATH=/root/.local/bin:$PATH

# Copy application code
COPY app.py .

# Create directory for logs and set permissions
RUN mkdir -p /app/logs && chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

# Expose application port
EXPOSE ${PORT}

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/health')" || exit 1

# Command to run the application
# CMD bash
CMD ["python", "app.py"]
Loading