centralizácia nastavení do .devcontainer/.env

This commit is contained in:
2026-02-21 19:48:14 +00:00
parent 8c99d6e975
commit b48ee09f80
6 changed files with 207 additions and 110 deletions

View File

@@ -1,5 +1,36 @@
PYTHON_BASE=3.13
DEVCONTAINER_IMAGE_REV=0.1
DEVCONTAINER_IMAGE_PULL_REPO=docker.masara.eu/python
DEVCONTAINER_IMAGE_PUSH_REPO=repo.masara.eu/python
# Python version used in devcontainer image tag (e.g. 3.13).
PYTHON_BASE=3.13
# Image revision for versioned tag: <repo>:<python>-<rev>-devcontainer.
DEVCONTAINER_IMAGE_REV=0.1
# Registry/repository used by docker-compose to pull the devcontainer image.
DEVCONTAINER_IMAGE_PULL_REPO=docker.masara.eu/python
# Registry/repository used by publish script to push the devcontainer image.
DEVCONTAINER_IMAGE_PUSH_REPO=repo.masara.eu/python
# Private PyPI index URL used by pip inside the container.
PIP_INDEX_URL=https://dv.masara.eu/repository/pypi-group/simple
# Allows running pip as root without interactive warning/failure.
PIP_ROOT_USER_ACTION=ignore
# Workspace mount path inside container.
WORKSPACE_DIR=/workspace
# Path to virtual environment created/used by post_create.sh.
VENV_PATH=/workspace/.venv
# Requirements file installed by post_create.sh (if file exists).
REQUIREMENTS_FILE=/workspace/requirements.txt
# User used by VS Code remote server inside container (e.g. root).
DEVCONTAINER_RUN_USER=root
# UID for app user created in project Dockerfile (non-devcontainer image build).
APP_USER_ID=1000
# Home directory for REMOTE_USER inside container.
REMOTE_HOME=/root

View File

@@ -1,60 +1,49 @@
{
"name": "Python Dev",
"dockerComposeFile": "docker-compose.yml",
"service": "dev",
"containerEnv": {
"PIP_INDEX_URL": "https://dv.masara.eu/repository/pypi-group/simple",
"PIP_ROOT_USER_ACTION": "ignore"
},
"remoteEnv": {
"DOCKER_BUILDKIT": "1",
"VIRTUAL_ENV": "/workspace/.venv",
"PATH": "/workspace/.venv/bin:${containerEnv:PATH}"
},
"workspaceFolder": "/workspace",
"remoteUser": "root",
"overrideCommand": true,
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.autopep8",
"ms-toolsai.jupyter",
"ms-python.black-formatter",
"ms-python.isort",
"codezombiech.gitignore",
"davidanson.vscode-markdownlint",
"ms-azuretools.vscode-docker",
"docker.docker",
"openai.chatgpt",
"continue.continue"
],
"settings": {
"python.formatting.provider": "black",
"python.analysis.extraPaths": [
"${workspaceFolder}/app"
],
"editor.formatOnSave": true,
"python.terminal.activateEnvironment": true,
"python.defaultInterpreterPath": ".venv/bin/python",
"remote.restoreForwardedPorts": false,
"remote.autoForwardPortsSource": "output",
"debug.javascript.autoAttachFilter": "disabled"
}
"name": "Python Dev",
"dockerComposeFile": "docker-compose.yml",
"service": "dev",
"workspaceFolder": "/workspace",
"overrideCommand": true,
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.autopep8",
"ms-toolsai.jupyter",
"ms-python.black-formatter",
"ms-python.isort",
"codezombiech.gitignore",
"davidanson.vscode-markdownlint",
"ms-azuretools.vscode-docker",
"docker.docker",
"openai.chatgpt",
"continue.continue"
],
"settings": {
"python.formatting.provider": "black",
"python.analysis.extraPaths": [
"${workspaceFolder}/app"
],
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticMode": "workspace",
"editor.formatOnSave": true,
"python.terminal.activateEnvironment": true,
"python.defaultInterpreterPath": "${env:VENV_PATH}/bin/python",
"remote.restoreForwardedPorts": false,
"remote.autoForwardPortsSource": "output",
"debug.javascript.autoAttachFilter": "disabled"
}
}
},
"mounts": [
"type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock"
],
"postCreateCommand": "bash .devcontainer/post_create.sh",
"forwardPorts": [],
"portsAttributes": {
"*": {
"onAutoForward": "ignore"
}
}
},
"mounts": [
"type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
"type=volume,source=docextractor-codex,target=/root/.codex",
"type=bind,source=${localEnv:USERPROFILE}/.codex/auth.json,target=/root/.codex/auth.json,readonly",
"type=bind,source=${localEnv:USERPROFILE}/.pypirc,target=/root/.pypirc,readonly"
],
"postCreateCommand": "bash .devcontainer/post_create.sh",
"forwardPorts": [],
"portsAttributes": {
"*": {
"onAutoForward": "ignore"
}
}
}
}

View File

@@ -1,11 +1,22 @@
services:
services:
dev:
image: ${DEVCONTAINER_IMAGE_PULL_REPO}:${PYTHON_BASE}-${DEVCONTAINER_IMAGE_REV}-devcontainer
pull_policy: always
init: true
user: ${DEVCONTAINER_RUN_USER:-root}
command: sleep infinity
tty: true
volumes:
- ..:/workspace:cached
- docextractor-codex:${REMOTE_HOME:-/root}/.codex
- ${USERPROFILE}/.codex/auth.json:${REMOTE_HOME:-/root}/.codex/auth.json:ro
- ${USERPROFILE}/.pypirc:${REMOTE_HOME:-/root}/.pypirc:ro
environment:
PYTHON_BASE: ${PYTHON_BASE}
PIP_INDEX_URL: ${PIP_INDEX_URL}
PIP_ROOT_USER_ACTION: ${PIP_ROOT_USER_ACTION}
WORKSPACE_DIR: ${WORKSPACE_DIR}
VENV_PATH: ${VENV_PATH}
REQUIREMENTS_FILE: ${REQUIREMENTS_FILE}
volumes:
docextractor-codex:

View File

@@ -1,7 +1,18 @@
#!/usr/bin/env bash
set -e
set -euo pipefail
VENV_PATH="/workspace/.venv"
WORKSPACE_DIR="${WORKSPACE_DIR:-/workspace}"
VENV_PATH="${VENV_PATH:-$WORKSPACE_DIR/.venv}"
REQUIREMENTS_FILE="${REQUIREMENTS_FILE:-$WORKSPACE_DIR/requirements.txt}"
# Resolve current user's home robustly (works for root and non-root users).
USER_HOME="${HOME:-}"
if [ -z "$USER_HOME" ] && command -v getent >/dev/null 2>&1; then
USER_HOME="$(getent passwd "$(id -un)" | cut -d: -f6)"
fi
if [ -z "$USER_HOME" ]; then
USER_HOME="/root"
fi
BASHRC_PATH="${BASHRC_PATH:-$USER_HOME/.bashrc}"
# Ak venv neexistuje, vytvor ho a priprav pip
if [ ! -d "$VENV_PATH" ]; then
@@ -19,17 +30,17 @@ 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
if [ -f "/workspace/requirements.txt" ]; then
if [ -f "$REQUIREMENTS_FILE" ]; then
echo "Inštalujem závislosti z requirements.txt..."
python -m pip install -r /workspace/requirements.txt
python -m pip install -r "$REQUIREMENTS_FILE"
else
echo "requirements.txt nenájdený preskakujem inštaláciu závislostí."
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"
ACTIVATE_LINE="[ -f \"$VENV_PATH/bin/activate\" ] && source \"$VENV_PATH/bin/activate\""
touch "$BASHRC_PATH"
if ! grep -Fq "$ACTIVATE_LINE" "$BASHRC_PATH"; then
echo "$ACTIVATE_LINE" >> "$BASHRC_PATH"
fi