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
30 changes: 30 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ pkgs ? import <nixpkgs> {} }:

let
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
fastapi
uvicorn
pydantic
starlette
python-dotenv
prometheus-client
annotated-doc
]);
in
pkgs.stdenv.mkDerivation rec {
pname = "devops-info-service";
version = "1.0.0";
src = ./.;

nativeBuildInputs = [ pkgs.makeWrapper ];

installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/app
cp app.py $out/app/app.py

makeWrapper ${pythonEnv}/bin/python $out/bin/devops-info-service \
--add-flags "$out/app/app.py"
runHook postInstall
'';
}
64 changes: 64 additions & 0 deletions labs/lab18/app_python/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/
pip-wheel-metadata/

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

# IDEs and editors
.vscode/
.idea/
*.swp
*.swo
*~
.project
.pydevproject
.settings/

# Version control
.git/
.gitignore
.gitattributes

# Documentation (keep only what's needed)
docs/
*.md
!README.md

# Logs
*.log
app.log

# Tests
tests/
test_*.py
*_test.py
pytest.ini
.pytest_cache/
.coverage
htmlcov/

# OS files
.DS_Store
Thumbs.db
desktop.ini

# Environment files
.env
.env.local
.env.*.local

# Temporary files
*.tmp
*.temp
44 changes: 44 additions & 0 deletions labs/lab18/app_python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.pyc
*.pyo
*.pyd
.Python
*.so
*.egg
*.egg-info/
dist/
build/

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

# Testing
.pytest_cache/
.coverage
htmlcov/
coverage.xml

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

# OS
.DS_Store
Thumbs.db

# Environment
.env
.env.local

# Logs
*.log
app.log
32 changes: 32 additions & 0 deletions labs/lab18/app_python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Using Python slim image
FROM python:3.13-slim

# Working directory
WORKDIR /app

# Non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser

# Copying requirements first for better layer caching
COPY requirements.txt .

# Installing dependencies without cache to reduce image size
RUN pip install --no-cache-dir -r requirements.txt

# Copying application code
COPY app.py .

# Changing ownership to non-root user
RUN chown -R appuser:appuser /app

RUN mkdir -p /data && chown -R appuser:appuser /data

# Switch to non-root user
USER appuser

# Expose port
EXPOSE 8000

# Runing the application
CMD ["python", "app.py"]

Loading