CI update
added Docker on tag Autotest on mergerequest to main
This commit is contained in:
84
.dockerignore
Normal file
84
.dockerignore
Normal file
@@ -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
|
||||
1
.gitea/template
Normal file
1
.gitea/template
Normal file
@@ -0,0 +1 @@
|
||||
README.md
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Process redis for auth service
|
||||
name: Build image
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -21,10 +21,12 @@ jobs:
|
||||
- name: Arch checkout
|
||||
run: test -f Dockerfile || { echo "Dockerfile not found"; exit 1; }
|
||||
|
||||
- name: Login
|
||||
- name: Login to registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" \
|
||||
| docker login $REGISTRY -u ${{ gitea.actor }} --password-stdin
|
||||
| docker login "$REGISTRY" \
|
||||
-u "${{ secrets.REGISTRY_USER }}" \
|
||||
--password-stdin
|
||||
|
||||
- name: Set Version
|
||||
id: version
|
||||
@@ -43,16 +45,44 @@ jobs:
|
||||
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 --pull --no-cache --provenance=false --sbom=false \
|
||||
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 --pull --no-cache --provenance=false --sbom=false \
|
||||
docker build \
|
||||
--build-arg PYTHON_VERSION="$PYTHON_VERSION" \
|
||||
--pull --no-cache --provenance=false --sbom=false \
|
||||
-t $REGISTRY/$REPO:$VERSION \
|
||||
.
|
||||
fi
|
||||
@@ -69,4 +99,9 @@ jobs:
|
||||
- name: Notify success
|
||||
if: success()
|
||||
run: |
|
||||
MESSAGE="Built image: \`${{ env.REGISTRY }}/${{ env.REPO }}:${{ env.VERSION }}\`\nBranch: \`${{ gitea.ref_name }}\`\nCommit: \`${{ gitea.sha }}\`"
|
||||
MESSAGE="Built image: \`${{ env.REGISTRY }}/${{ env.REPO }}:${{ env.VERSION }}\`\nBranch: \`${{ gitea.ref_name }}\`\nCommit: \`${{ gitea.sha }}\`"
|
||||
|
||||
- name: Logout
|
||||
if: always()
|
||||
run: |
|
||||
docker logout "$REGISTRY"
|
||||
49
.gitea/workflows/test.yml
Normal file
49
.gitea/workflows/test.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
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: ".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
|
||||
83
.gitignore
vendored
83
.gitignore
vendored
@@ -1,9 +1,86 @@
|
||||
# =========================
|
||||
# IDE
|
||||
# =========================
|
||||
|
||||
*.code-workspace
|
||||
.spyproject
|
||||
.vs
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
__pycache__
|
||||
*.pyc
|
||||
|
||||
# =========================
|
||||
# Python
|
||||
# =========================
|
||||
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
|
||||
|
||||
# =========================
|
||||
# Virtual environments
|
||||
# =========================
|
||||
|
||||
.venv/
|
||||
venv/
|
||||
env/
|
||||
ENV/
|
||||
|
||||
|
||||
# =========================
|
||||
# Environment / secrets
|
||||
# =========================
|
||||
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
|
||||
# =========================
|
||||
# Custom / code tests
|
||||
# =========================
|
||||
|
||||
nogit
|
||||
*.test.*
|
||||
*.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
|
||||
1
.py-version
Normal file
1
.py-version
Normal file
@@ -0,0 +1 @@
|
||||
3.11
|
||||
48
Dockerfile
Normal file
48
Dockerfile
Normal file
@@ -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"]
|
||||
47
README.md
Normal file
47
README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# ${REPO_NAME}
|
||||
|
||||
${REPO_DESCRIPTION}
|
||||
|
||||
## Requirements
|
||||
|
||||
Required Python version is specified in `.python-version`.
|
||||
|
||||
Install application dependencies:
|
||||
|
||||
```bash
|
||||
python -m pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Install development dependencies:
|
||||
|
||||
```bash
|
||||
python -m pip install -r requirements-dev.txt
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
Run all tests:
|
||||
|
||||
```bash
|
||||
python -m pytest
|
||||
```
|
||||
|
||||
Tests are also executed automatically for Pull Requests targeting `main`.
|
||||
|
||||
A Pull Request must pass automated tests before it can be merged.
|
||||
|
||||
## Docker
|
||||
|
||||
Docker images are built automatically:
|
||||
|
||||
- when changes are pushed to the `deploy` branch;
|
||||
- when a version tag matching `v*.*.*` is created.
|
||||
|
||||
The Python version used for Docker builds is taken from `.python-version`.
|
||||
|
||||
## Project structure
|
||||
|
||||
```text
|
||||
src/ Application source code
|
||||
tests/ Automated tests
|
||||
```
|
||||
1
req-dev.txt
Normal file
1
req-dev.txt
Normal file
@@ -0,0 +1 @@
|
||||
pytest
|
||||
0
src/main.py
Normal file
0
src/main.py
Normal file
Reference in New Issue
Block a user