From 785a6980f6d721fbaeb38b773b2d3f052aebb2d1 Mon Sep 17 00:00:00 2001 From: SIRMENT <> Date: Wed, 16 Sep 2026 18:47:15 +0000 Subject: [PATCH] Initial commit --- .dockerignore | 84 +++++++++++++++++++++++++++++ .gitea/workflows/build.yml | 107 +++++++++++++++++++++++++++++++++++++ .gitea/workflows/test.yml | 50 +++++++++++++++++ .gitignore | 86 +++++++++++++++++++++++++++++ .py-version | 1 + Dockerfile | 48 +++++++++++++++++ README.md | 51 ++++++++++++++++++ req-dev.txt | 1 + req.txt | 0 src/main.py | 0 tests/.gitkeep | 0 11 files changed, 428 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitea/workflows/test.yml create mode 100644 .gitignore create mode 100644 .py-version create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 req-dev.txt create mode 100644 req.txt create mode 100644 src/main.py create mode 100644 tests/.gitkeep diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..01bc08a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,84 @@ +# ========================= +# Git / Gitea +# ========================= + +.git/ +.gitea/ + + +# ========================= +# Python cache +# ========================= + +__pycache__/ +*.py[cod] + + +# ========================= +# Virtual environments +# ========================= + +.venv/ +venv/ +env/ +ENV/ + + +# ========================= +# Tests +# Тесты выполняет CI, в production image они не нужны +# ========================= + +tests/ +.pytest_cache/ +.coverage +coverage.xml +htmlcov/ + + +# ========================= +# Build artifacts +# ========================= + +build/ +dist/ +*.egg-info/ + + +# ========================= +# Local configuration / secrets +# ========================= + +.env +.env.* + +!.env.example + + +# ========================= +# IDE +# ========================= + +*.code-workspace +.spyproject +.vs +.vscode +.idea + + +# ========================= +# Logs / temporary files +# ========================= + +*.log +*.tmp +*.swp +*.swo + + +# ========================= +# OS garbage +# ========================= + +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..b5ccc57 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,107 @@ +name: Build image + +on: + push: + branches: + - deploy + tags: + - v*.*.* + +jobs: + build: + runs-on: docker-amd64 + + env: + REGISTRY: git.arconlab.ru + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Arch checkout + run: test -f Dockerfile || { echo "Dockerfile not found"; exit 1; } + + - name: Login to registry + run: | + echo "${{ secrets.REGISTRY_TOKEN }}" \ + | docker login "$REGISTRY" \ + -u "${{ secrets.REGISTRY_USER }}" \ + --password-stdin + + - name: Set Version + id: version + run: | + REPO=$(echo "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]') + REF_NAME="${{ gitea.ref_name }}" + REF_TYPE="${{ gitea.ref_type }}" # "branch" или "tag" + + if [ "$REF_TYPE" = "tag" ]; then + VERSION="$REF_NAME" + else + VERSION="${REF_NAME}_latest" + fi + + echo "REPO=$REPO" >> $GITHUB_ENV + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "REF_TYPE=$REF_TYPE" >> $GITHUB_ENV + + - name: Verify release tag belongs to main + if: gitea.ref_type == 'tag' + run: | + + git fetch --unshallow origin \ + main:refs/remotes/origin/main \ + || git fetch origin \ + main:refs/remotes/origin/main + + + if ! git merge-base \ + --is-ancestor \ + "${{ gitea.sha }}" \ + origin/main + then + echo "ERROR: Release tags must point to a commit from main." + exit 1 + fi + + + - name: Set Python version + run: | + echo "PYTHON_VERSION=$(cat .py-version)" >> "$GITHUB_ENV" + + + - name: Build Image + run: | + if [ "$REF_TYPE" = "tag" ]; then + docker build \ + --build-arg PYTHON_VERSION="$PYTHON_VERSION" \ + --pull --no-cache --provenance=false --sbom=false \ + -t $REGISTRY/$REPO:$VERSION \ + -t $REGISTRY/$REPO:latest \ + . + else + docker build \ + --build-arg PYTHON_VERSION="$PYTHON_VERSION" \ + --pull --no-cache --provenance=false --sbom=false \ + -t $REGISTRY/$REPO:$VERSION \ + . + fi + + - name: Push Image + run: | + docker push $REGISTRY/$REPO:$VERSION + if [ "$REF_TYPE" = "tag" ]; then + docker push $REGISTRY/$REPO:latest + fi + + + + - name: Notify success + if: success() + run: | + MESSAGE="Built image: \`${{ env.REGISTRY }}/${{ env.REPO }}:${{ env.VERSION }}\`\nBranch: \`${{ gitea.ref_name }}\`\nCommit: \`${{ gitea.sha }}\`" + + - name: Logout + if: always() + run: | + docker logout "$REGISTRY" \ No newline at end of file diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..2248c72 --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,50 @@ +name: Tests + +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + pytest: + + # Имя твоего Gitea Runner. + # У тебя уже используется docker-amd64 в build.yml. + runs-on: docker-amd64 + + steps: + + # ------------------------- + # Checkout repository + # ------------------------- + + - name: Checkout + uses: actions/checkout@v4 + + + # ------------------------- + # Python + # ------------------------- + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version-file: ".py-version" + + + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r req.txt + python -m pip install -r req-dev.txt + + + # ------------------------- + # Tests + # ------------------------- + + - name: Run tests + run: | + python -m pytest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4411758 --- /dev/null +++ b/.gitignore @@ -0,0 +1,86 @@ +# ========================= +# IDE +# ========================= + +*.code-workspace +.spyproject +.vs +.vscode +.idea + + +# ========================= +# Python +# ========================= + +__pycache__/ +*.py[cod] +*$py.class +*.so + + +# ========================= +# Virtual environments +# ========================= + +.venv/ +venv/ +env/ +ENV/ + + +# ========================= +# Environment / secrets +# ========================= + +.env +.env.* +!.env.example + + +# ========================= +# Custom / code tests +# ========================= + +nogit +*.test.* + + + +# ========================= +# Tests / coverage +# ========================= + +.pytest_cache/ +.coverage +coverage.xml +htmlcov/ + + +# ========================= +# Python build artifacts +# На случай, если позже начнём собирать Python package +# ========================= + +build/ +dist/ +*.egg-info/ +.eggs/ + + +# ========================= +# Logs / temporary files +# ========================= + +*.log +*.tmp +*.swp +*.swo + + +# ========================= +# OS garbage +# ========================= + +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/.py-version b/.py-version new file mode 100644 index 0000000..902b2c9 --- /dev/null +++ b/.py-version @@ -0,0 +1 @@ +3.11 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..613be13 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# ========================= +# Base image +# ========================= + +ARG PYTHON_VERSION=3.11 + +FROM python:${PYTHON_VERSION}-slim + + +# ========================= +# Python env +# ========================= +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV PIP_NO_CACHE_DIR=1 +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 + + +# ========================= +# Application directory +# ========================= + +WORKDIR /app + + +# ========================= +# Dependencies +# ========================= + + +COPY req.txt ./req.txt + +RUN python -m pip install --upgrade pip \ + && python -m pip install -r req.txt + + +# ========================= +# Application +# ========================= + +COPY src/ ./src/ + + +# ========================= +# Startup +# ========================= + +CMD ["python", "src/main.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..be43fe1 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# core + +New, better iteration of ARTEX + +## Requirements + +Required Python version is specified in `.py-version` (currently Python 3.11). + +Install application dependencies: + +```bash +python -m pip install -r req.txt +``` + +Install development dependencies: + +```bash +python -m pip install -r req-dev.txt +``` + +Run the application: + +```bash +python src/main.py +``` + +`src/main.py` is initially empty. Add application logic before using the image as a service. + +## Tests + +Run all tests: + +```bash +python -m pytest +``` + +Tests are also executed automatically for Pull Requests targeting `main`. + +## Docker + +Docker images are built automatically: + +- when changes are pushed to the `deploy` branch; +- when a version tag matching `v*.*.*` is created. + +## Project structure + +```text +src/ Application source code +tests/ Add automated tests here +``` diff --git a/req-dev.txt b/req-dev.txt new file mode 100644 index 0000000..55b033e --- /dev/null +++ b/req-dev.txt @@ -0,0 +1 @@ +pytest \ No newline at end of file diff --git a/req.txt b/req.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29