Verzia 0.1 - funkčná

This commit is contained in:
2025-12-07 09:44:04 +00:00
parent f0e399cabe
commit dbc1ceffef
11 changed files with 412 additions and 6 deletions

31
.devcontainer/Dockerfile Normal file
View File

@@ -0,0 +1,31 @@
# Používame oficiálny Python image, ale env bude podobné ako v base:ubuntu
ARG PYTHON_VERSION=3.13
FROM python:${PYTHON_VERSION}-slim
ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
VIRTUAL_ENV=/workspace/.venv \
PATH="/workspace/.venv/bin:${PATH}"
# Základ + Docker repo + docker-ce-cli + compose plugin + git
RUN set -eux; \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates curl gnupg && \
install -m 0755 -d /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
chmod a+r /etc/apt/keyrings/docker.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" \
> /etc/apt/sources.list.d/docker.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential pkg-config \
git \
docker-ce-cli docker-compose-plugin docker-buildx-plugin \
libatomic1 libstdc++6 libgcc-s1 \
procps \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workspace

View File

@@ -0,0 +1,52 @@
{
"name": "Python Dev",
"build": {
"dockerfile": "Dockerfile",
"context": ".",
"args": {
"PYTHON_VERSION": "3.13"
}
},
"containerEnv": {
"PIP_INDEX_URL": "https://dv.masara.eu/repository/pypi-group/simple"
// alebo "/simple", ak to Nexus vyžaduje
},
"remoteEnv": {
"DOCKER_BUILDKIT": "1"
},
"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"remoteUser": "root",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-python.black-formatter",
"ms-python.isort",
"ms-azuretools.vscode-docker"
],
"settings": {
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"python.formatting.provider": "black",
"python.analysis.extraPaths": [
"/app"
],
"editor.formatOnSave": true,
"python.defaultInterpreterPath": "/workspace/.venv/bin/python",
"remote.restoreForwardedPorts": false
}
}
},
"mounts": [
"type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock"
],
"postCreateCommand": "bash .devcontainer/post_create.sh",
"forwardPorts": [
// 8000,
// 8080
]
}

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e
VENV_PATH="/workspace/.venv"
# Ak venv neexistuje, vytvor ho a priprav pip
if [ ! -d "$VENV_PATH" ]; then
echo "Virtuálne prostredie neexistuje vytváram..."
python -m venv "$VENV_PATH"
echo "Aktivujem virtuálne prostredie..."
# shellcheck disable=SC1090
source "$VENV_PATH/bin/activate"
echo "Aktualizujem pip a základné nástroje..."
pip install --upgrade pip setuptools wheel
else
echo "Používam existujúce virtuálne prostredie..."
# shellcheck disable=SC1090
source "$VENV_PATH/bin/activate"
fi
# Inštalácia závislostí, ak existuje requirements.txt
if [ -f "/workspace/requirements.txt" ]; then
echo "Inštalujem závislosti z requirements.txt..."
pip install -r /workspace/requirements.txt
else
echo "requirements.txt nenájdený preskakujem inštaláciu závislostí."
fi

16
.dockerignore Normal file
View File

@@ -0,0 +1,16 @@
__pycache__
*.pyc
*.pyo
*.pyd
*.db
*.sqlite3
.env
*.log
.git
.gitignore
.vscode
.venv
venv
rest
docker

229
.gitignore vendored Normal file
View File

@@ -0,0 +1,229 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/
# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# Redis
*.rdb
*.aof
*.pid
# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/
# ActiveMQ
activemq-data/
# SageMath parsed files
*.sage.py
# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/
# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/
# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# Streamlit
.streamlit/secrets.toml
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
!*.code-workspace
# Built Visual Studio Code Extensions
*.vsix

1
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1 @@
{}

31
Dockerfile Normal file
View File

@@ -0,0 +1,31 @@
# syntax=docker/dockerfile:1.6
FROM python:3.13-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_INDEX_URL=https://dv.masara.eu/repository/pypi-group/simple \
PIP_NO_INPUT=1
ARG APP_USER_ID=1000
RUN useradd -u ${APP_USER_ID} -m appuser
WORKDIR /app
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
COPY app/ /app/
# ak len adresár /app
RUN chown -R appuser:appuser /app
# príklad vytvorenia ďalľieho adresára pre aplikáciu a zmena vlastníctva naraz aj pre /app
# RUN mkdir -p /models && chown -R appuser:appuser /models /app
USER appuser
# Príklad sprístupnenia a spustenia uvicorn
# EXPOSE 8080
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

View File

@@ -1,6 +1,20 @@
# Template projektu pre Python 3.13
Template obsahuje
## Template obsahuje
* definíciu docker kontajnera s podporu docker
* definíciu docker kontajnera s podporu docker a git
* python 3.13
* Nastavenie vscode
* .dockerignore a .gitignore
* Hello world aplikáciu
* vzorový Dockerfile pre aplikáciu
> Prvé otvorenie projektu môže trvať aj 10 min. Musí sa buildovať image.
## Otvorenie projektu
Pri otvorení projektu sa automaticky:
* kontroluje, či je vytvorené venv, ak nie, vytvorí sa a aktualizuje pip
* aktualizujú sa závislosti

0
app/__init__.py Normal file
View File

2
app/main.py Normal file
View File

@@ -0,0 +1,2 @@
# hello_world.py
print("Hello, world!")

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@