Skip to content

Commit 7408bb7

Browse files
committed
Initial VPN bot
0 parents  commit 7408bb7

24 files changed

+3369
-0
lines changed

.github/workflows/ci.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [3.12]
15+
16+
services:
17+
postgres:
18+
image: postgres:15
19+
env:
20+
POSTGRES_PASSWORD: postgres
21+
POSTGRES_DB: vpn_bot_test
22+
ports:
23+
- 5432:5432
24+
options: >-
25+
--health-cmd pg_isready
26+
--health-interval 10s
27+
--health-timeout 5s
28+
--health-retries 5
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
38+
- name: Cache dependencies
39+
uses: actions/cache@v3
40+
with:
41+
path: ~/.cache/pip
42+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
43+
restore-keys: |
44+
${{ runner.os }}-pip-
45+
46+
- name: Install dependencies
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install -r requirements.txt
50+
51+
- name: Run linting
52+
run: |
53+
# Stop the build if there are Python syntax errors or undefined names
54+
ruff check bot/ --select=E9,F63,F7,F82 --show-source --statistics
55+
# Treat all other issues as warnings
56+
ruff check bot/ --exit-zero --statistics
57+
58+
- name: Check code formatting
59+
run: |
60+
black --check bot/
61+
62+
- name: Type checking
63+
run: |
64+
# Install mypy if not in requirements
65+
pip install mypy types-requests
66+
mypy bot/ --ignore-missing-imports
67+
68+
- name: Run tests
69+
env:
70+
BOT_TOKEN: "test_token"
71+
ADMIN_TG_ID: "123456789"
72+
DB_URL: "postgresql+asyncpg://postgres:postgres@localhost:5432/vpn_bot_test"
73+
run: |
74+
pytest tests/ -v --cov=bot --cov-report=xml
75+
76+
- name: Upload coverage to Codecov
77+
uses: codecov/codecov-action@v3
78+
with:
79+
file: ./coverage.xml
80+
flags: unittests
81+
name: codecov-umbrella
82+
83+
security:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- name: Set up Python
89+
uses: actions/setup-python@v4
90+
with:
91+
python-version: 3.12
92+
93+
- name: Install dependencies
94+
run: |
95+
python -m pip install --upgrade pip
96+
pip install bandit safety
97+
98+
- name: Run security checks
99+
run: |
100+
bandit -r bot/ -f json -o bandit-report.json || true
101+
safety check --json --output safety-report.json || true
102+
103+
- name: Upload security reports
104+
uses: actions/upload-artifact@v3
105+
with:
106+
name: security-reports
107+
path: |
108+
bandit-report.json
109+
safety-report.json
110+
111+
docker:
112+
runs-on: ubuntu-latest
113+
steps:
114+
- uses: actions/checkout@v4
115+
116+
- name: Build Docker image
117+
run: |
118+
docker build -t vpn-bot:test .
119+
120+
- name: Test Docker image
121+
run: |
122+
# Test that the image can be created and basic imports work
123+
docker run --rm vpn-bot:test python -c "import bot; print('Import successful')"

.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
share/python-wheels/
20+
*.egg-info/
21+
.installed.cfg
22+
*.egg
23+
MANIFEST
24+
25+
# Environment
26+
.env
27+
.venv
28+
env/
29+
venv/
30+
ENV/
31+
env.bak/
32+
venv.bak/
33+
34+
# IDE
35+
.vscode/
36+
.idea/
37+
*.swp
38+
*.swo
39+
40+
# Database
41+
*.db
42+
*.sqlite3
43+
44+
# Logs
45+
*.log
46+
47+
# Testing
48+
.pytest_cache/
49+
.coverage
50+
htmlcov/
51+
52+
# Docker
53+
.docker/
54+
55+
# Alembic
56+
alembic/versions/*.py
57+
!alembic/versions/__init__.py

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM python:3.12-slim
2+
3+
# Set environment variables
4+
ENV PYTHONUNBUFFERED=1
5+
ENV PYTHONDONTWRITEBYTECODE=1
6+
7+
# Set work directory
8+
WORKDIR /app
9+
10+
# Install system dependencies
11+
RUN apt-get update && apt-get install -y \
12+
gcc \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Copy requirements and install Python dependencies
16+
COPY requirements.txt .
17+
RUN pip install --no-cache-dir -r requirements.txt
18+
19+
# Copy application code
20+
COPY bot/ ./bot/
21+
COPY run.py .
22+
23+
# Create non-root user
24+
RUN useradd --create-home --shell /bin/bash botuser && \
25+
chown -R botuser:botuser /app
26+
USER botuser
27+
28+
# Create directory for database
29+
RUN mkdir -p /app/data
30+
31+
# Expose health check port
32+
EXPOSE 8000
33+
34+
# Health check
35+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
36+
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
37+
38+
# Run the bot
39+
CMD ["python", "run.py"]

0 commit comments

Comments
 (0)