From 9b08ae17fc0fed95dcce800a95a367b3c98af4a7 Mon Sep 17 00:00:00 2001 From: fish Date: Thu, 26 Mar 2026 20:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E7=BB=93=E6=9E=84=E5=92=8C=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 17 +++++++++++++++ .gitea/workflows/ci-cd.yml | 44 ++++++++++++++++++++++++++++++++++++++ deploy/docker-compose.yml | 24 +++++++++++++++++++++ deploy/docker/Dockerfile | 10 +++++++++ deploy/nginx/nginx.conf | 34 +++++++++++++++++++++++++++++ requirements.txt | 17 +++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 .env.example create mode 100644 .gitea/workflows/ci-cd.yml create mode 100644 deploy/docker-compose.yml create mode 100644 deploy/docker/Dockerfile create mode 100644 deploy/nginx/nginx.conf create mode 100644 requirements.txt diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..99f7f8f --- /dev/null +++ b/.env.example @@ -0,0 +1,17 @@ +# 环境变量配置 + +# 应用配置 +APP_NAME=asset_helper +APP_ENV=development +APP_DEBUG=True +APP_SECRET_KEY=your-secret-key-here + +# 数据库配置 +DATABASE_URL=sqlite:///asset_helper.db + +# 服务器配置 +SERVER_HOST=0.0.0.0 +SERVER_PORT=8000 + +# 其他配置 +LOG_LEVEL=INFO diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml new file mode 100644 index 0000000..364da75 --- /dev/null +++ b/.gitea/workflows/ci-cd.yml @@ -0,0 +1,44 @@ +name: CI/CD Pipeline + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Build Docker image + run: | + cd deploy + docker-compose build + + deploy: + needs: build + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Deploy + run: | + cd deploy + docker-compose up -d diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..e32dde3 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + app: + build: + context: .. + dockerfile: deploy/docker/Dockerfile + ports: + - "8000:8000" + env_file: + - .env + volumes: + - ..:/app + depends_on: + - nginx + + nginx: + image: nginx:latest + ports: + - "80:80" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro + - ..:/app + restart: always diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile new file mode 100644 index 0000000..d786e65 --- /dev/null +++ b/deploy/docker/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.9-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "app.py"] diff --git a/deploy/nginx/nginx.conf b/deploy/nginx/nginx.conf new file mode 100644 index 0000000..63724e0 --- /dev/null +++ b/deploy/nginx/nginx.conf @@ -0,0 +1,34 @@ +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + sendfile on; + keepalive_timeout 65; + + server { + listen 80; + server_name localhost; + + location / { + proxy_pass http://app:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /static/ { + alias /app/static/; + expires 30d; + } + + location /media/ { + alias /app/media/; + expires 30d; + } + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5de4243 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,17 @@ +# 项目依赖 + +# Web 框架 +Flask==2.0.1 + +# 数据库 +SQLAlchemy==1.4.32 + +# 环境变量管理 +python-dotenv==0.19.2 + +# 工具库 +requests==2.27.1 +pytest==6.2.5 + +# 生产环境 +gunicorn==20.1.0