funkčný template

This commit is contained in:
Alojz Masár
2026-02-15 17:18:12 +00:00
parent b962c1be7f
commit 8938b65685
10 changed files with 154 additions and 142 deletions

View File

@@ -1,4 +1,5 @@
PYTHON_BASE=3.13 PYTHON_BASE=3.13
DEVCONTAINER_IMAGE_REV=0.1
DEVCONTAINER_IMAGE_PULL_REPO=docker.masara.eu/python DEVCONTAINER_IMAGE_PULL_REPO=docker.masara.eu/python
DEVCONTAINER_IMAGE_PUSH_REPO=repo.masara.eu/python DEVCONTAINER_IMAGE_PUSH_REPO=repo.masara.eu/python
DEVCONTAINER_IMAGE_REV=0.1

View File

@@ -1,16 +1,17 @@
{ {
"name": "Python Dev", "name": "Python Dev",
"dockerComposeFile": "docker-compose.yml",
"service": "dev",
"containerEnv": { "containerEnv": {
"PIP_INDEX_URL": "https://dv.masara.eu/repository/pypi-group/simple", "PIP_INDEX_URL": "https://dv.masara.eu/repository/pypi-group/simple",
"PIP_ROOT_USER_ACTION": "ignore" "PIP_ROOT_USER_ACTION": "ignore"
}, },
"remoteEnv": { "remoteEnv": {
"DOCKER_BUILDKIT": "1" "DOCKER_BUILDKIT": "1",
"VIRTUAL_ENV": "/workspace/.venv",
"PATH": "/workspace/.venv/bin:${containerEnv:PATH}"
}, },
"workspaceFolder": "/workspace", "workspaceFolder": "/workspace",
"remoteUser": "root", "remoteUser": "root",
"overrideCommand": true,
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [
@@ -19,7 +20,8 @@
"ms-toolsai.jupyter", "ms-toolsai.jupyter",
"ms-python.black-formatter", "ms-python.black-formatter",
"ms-python.isort", "ms-python.isort",
"ms-azuretools.vscode-docker" "ms-azuretools.vscode-docker",
"openai.chatgpt"
], ],
"settings": { "settings": {
"python.formatting.provider": "black", "python.formatting.provider": "black",
@@ -36,14 +38,16 @@
} }
}, },
"mounts": [ "mounts": [
"type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
"type=bind,source=${localEnv:USERPROFILE}/.codex,target=/root/.codex"
], ],
"postCreateCommand": "bash .devcontainer/post_create.sh", "postCreateCommand": "bash .devcontainer/post_create.sh",
"forwardPorts": [ "forwardPorts": [],
],
"portsAttributes": { "portsAttributes": {
"*": { "*": {
"onAutoForward": "ignore" "onAutoForward": "ignore"
} }
} },
"image": "docker.masara.eu/python:3.13-0.1-devcontainer",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached"
} }

View File

@@ -1,8 +1,10 @@
services: services:
dev: dev:
image: ${DEVCONTAINER_IMAGE_PULL_REPO}:${PYTHON_BASE}-${DEVCONTAINER_IMAGE_REV}-devcontainer image: ${DEVCONTAINER_IMAGE_PULL_REPO}:${PYTHON_BASE}-${DEVCONTAINER_IMAGE_REV}-devcontainer
pull_policy: always pull_policy: always
init: true init: true
command: sleep infinity
tty: true
volumes: volumes:
- ..:/workspace:cached - ..:/workspace:cached
environment: environment:

View File

@@ -7,24 +7,29 @@ VENV_PATH="/workspace/.venv"
if [ ! -d "$VENV_PATH" ]; then if [ ! -d "$VENV_PATH" ]; then
echo "Virtuálne prostredie neexistuje vytváram..." echo "Virtuálne prostredie neexistuje vytváram..."
python -m venv "$VENV_PATH" 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 else
echo "Používam existujúce virtuálne prostredie..." echo "Používam existujúce virtuálne prostredie..."
# shellcheck disable=SC1090
# source "$VENV_PATH/bin/activate"
fi fi
echo "Aktivujem virtuálne prostredie..."
# shellcheck disable=SC1090
source "$VENV_PATH/bin/activate"
echo "Aktualizujem pip a základné nástroje..."
python -m pip install --upgrade pip setuptools wheel
# Inštalácia závislostí, ak existuje requirements.txt # Inštalácia závislostí, ak existuje requirements.txt
if [ -f "/workspace/requirements.txt" ]; then if [ -f "/workspace/requirements.txt" ]; then
echo "Inštalujem závislosti z requirements.txt..." echo "Inštalujem závislosti z requirements.txt..."
pip install -r /workspace/requirements.txt python -m pip install -r /workspace/requirements.txt
else else
echo "requirements.txt nenájdený preskakujem inštaláciu závislostí." echo "requirements.txt nenájdený preskakujem inštaláciu závislostí."
fi fi
# Ak sa terminál otvorí skôr, než Python extension stihne auto-aktiváciu,
# zabezpečíme aktiváciu aj cez shell init.
BASHRC="/root/.bashrc"
ACTIVATE_LINE='[ -f /workspace/.venv/bin/activate ] && source /workspace/.venv/bin/activate'
if ! grep -Fq "$ACTIVATE_LINE" "$BASHRC"; then
echo "$ACTIVATE_LINE" >> "$BASHRC"
fi