Skip to content

Commit 655767d

Browse files
committed
Global refactoring
1 parent 995a6bf commit 655767d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2703
-1210
lines changed

.dockerignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# Virtual environments
29+
venv/
30+
env/
31+
ENV/
32+
33+
# IDE
34+
.vscode/
35+
.idea/
36+
*.swp
37+
*.swo
38+
39+
# OS
40+
.DS_Store
41+
Thumbs.db
42+
43+
# Logs
44+
*.log
45+
logs/
46+
47+
# Test coverage
48+
.coverage
49+
.pytest_cache/
50+
htmlcov/
51+
52+
# Documentation
53+
docs/
54+
*.md
55+
56+
# Local data (these should be mounted as volumes)
57+
src/data/*.db
58+
src/data/*.json
59+
60+
# Temporary files
61+
tmp/
62+
temp/

.github/workflows/ci.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: CI/CD Pipeline
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+
13+
strategy:
14+
matrix:
15+
python-version: [3.9, 3.10, 3.11]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Cache pip packages
26+
uses: actions/cache@v3
27+
with:
28+
path: ~/.cache/pip
29+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
30+
restore-keys: |
31+
${{ runner.os }}-pip-
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -r requirements.txt
37+
pip install pytest pytest-cov pytest-mock
38+
39+
- name: Lint with flake8
40+
run: |
41+
pip install flake8
42+
# stop the build if there are Python syntax errors or undefined names
43+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
44+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
45+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
46+
47+
- name: Test with pytest
48+
run: |
49+
pytest src/tests/ --cov=src --cov-report=xml --cov-report=html
50+
51+
- name: Upload coverage to Codecov
52+
uses: codecov/codecov-action@v3
53+
with:
54+
file: ./coverage.xml
55+
flags: unittests
56+
name: codecov-umbrella
57+
fail_ci_if_error: false
58+
59+
docker:
60+
runs-on: ubuntu-latest
61+
needs: test
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
69+
- name: Build Docker image
70+
run: |
71+
docker build -t freegpt4-api:latest .
72+
73+
- name: Test Docker container
74+
run: |
75+
docker run --rm -d --name test-container freegpt4-api:latest
76+
sleep 10
77+
docker logs test-container
78+
docker stop test-container || true

Dockerfile

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,65 @@
1+
# Multi-stage build for better optimization
2+
FROM python:3.12-slim as builder
3+
4+
# Install build dependencies
5+
RUN apt-get update && apt-get install -y \
6+
gcc \
7+
libsqlite3-dev \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Create virtual environment
11+
RUN python -m venv /opt/venv
12+
ENV PATH="/opt/venv/bin:$PATH"
13+
14+
# Copy requirements and install Python dependencies
15+
COPY requirements.txt .
16+
RUN pip install --no-cache-dir --upgrade pip && \
17+
pip install --no-cache-dir -r requirements.txt
18+
19+
# Production stage
120
FROM python:3.12-slim
221

3-
WORKDIR /app/
4-
COPY --chown=www-data:www-data . .
22+
# Install runtime dependencies
23+
RUN apt-get update && apt-get install -y \
24+
chromium \
25+
libsqlite3-dev \
26+
&& rm -rf /var/lib/apt/lists/* \
27+
&& apt-get clean
28+
29+
# Create non-root user
30+
RUN groupadd -r freegpt && useradd -r -g freegpt freegpt
31+
32+
# Copy virtual environment from builder
33+
COPY --from=builder /opt/venv /opt/venv
34+
ENV PATH="/opt/venv/bin:$PATH"
535

6-
RUN apt update && apt install gcc chromium libsqlite3-dev -y
7-
RUN pip3 install --upgrade pip
8-
RUN pip3 install -r requirements.txt
36+
# Set working directory
37+
WORKDIR /app
938

39+
# Copy application code
40+
COPY --chown=freegpt:freegpt . .
41+
42+
# Create data directory with proper permissions
43+
RUN mkdir -p /app/src/data && \
44+
chown -R freegpt:freegpt /app
45+
46+
# Switch to non-root user
47+
USER freegpt
48+
49+
# Set working directory to src
1050
WORKDIR /app/src
1151

52+
# Environment variables
1253
ENV PORT=5500
13-
EXPOSE "$PORT/tcp"
54+
ENV PYTHONPATH="/app/src"
55+
56+
# Expose port
57+
EXPOSE $PORT
58+
59+
# Health check
60+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
61+
CMD curl -f http://localhost:$PORT/models || exit 1
1462

15-
#shell form necessary
16-
SHELL ["python3","FreeGPT4_Server.py"]
17-
ENTRYPOINT ["python3","FreeGPT4_Server.py"]
18-
#CMD ["--cookie-file","/cookies.json"]
63+
# Default command
64+
ENTRYPOINT ["python", "FreeGPT4_Server.py"]
65+
CMD ["--enable-gui", "--enable-fast-api"]
2.46 KB
Binary file not shown.

pytest.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[tool:pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_classes = Test*
5+
python_functions = test_*
6+
addopts =
7+
-v
8+
--tb=short
9+
--strict-markers
10+
--disable-warnings
11+
--color=yes
12+
markers =
13+
unit: Unit tests
14+
integration: Integration tests
15+
slow: Slow tests
16+
auth: Authentication tests
17+
database: Database tests
18+
validation: Validation tests

0 commit comments

Comments
 (0)