liuyuqi-dellpc 1 year ago
parent
commit
b562e9b8bb

+ 27 - 0
.dockerignore

@@ -0,0 +1,27 @@
+**/__pycache__
+**/.venv
+**/.classpath
+**/.dockerignore
+**/.env
+**/.git
+**/.gitignore
+**/.project
+**/.settings
+**/.toolstarget
+**/.vs
+**/.vscode
+**/*.*proj.user
+**/*.dbmdl
+**/*.jfm
+**/bin
+**/charts
+**/docker-compose*
+**/compose*
+**/Dockerfile*
+**/node_modules
+**/npm-debug.log
+**/obj
+**/secrets.dev.yaml
+**/values.dev.yaml
+LICENSE
+README.md

+ 38 - 0
.env

@@ -0,0 +1,38 @@
+# Domain
+# This would be set to the production domain with an env var on deployment
+DOMAIN=localhost
+
+# Environment: local, staging, production
+ENVIRONMENT=local
+
+PROJECT_NAME="Full Stack FastAPI Project"
+STACK_NAME=full-stack-fastapi-project
+
+# Backend
+BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173,http://localhost.tiangolo.com"
+SECRET_KEY=changethis
+FIRST_SUPERUSER=admin@example.com
+FIRST_SUPERUSER_PASSWORD=changethis
+USERS_OPEN_REGISTRATION=False
+
+# Emails
+SMTP_HOST=
+SMTP_USER=
+SMTP_PASSWORD=
+EMAILS_FROM_EMAIL=info@example.com
+SMTP_TLS=True
+SMTP_SSL=False
+SMTP_PORT=587
+
+# Postgres
+POSTGRES_SERVER=localhost
+POSTGRES_PORT=5432
+POSTGRES_DB=app
+POSTGRES_USER=postgres
+POSTGRES_PASSWORD=changethis
+
+SENTRY_DSN=
+
+# Configure these with your own Docker registry images
+DOCKER_IMAGE_BACKEND=backend
+DOCKER_IMAGE_FRONTEND=frontend

+ 19 - 0
.vscode/launch.json

@@ -0,0 +1,19 @@
+{
+    "configurations": [
+        {
+            "name": "Docker: Python - Flask",
+            "type": "docker",
+            "request": "launch",
+            "preLaunchTask": "docker-run: debug",
+            "python": {
+                "pathMappings": [
+                    {
+                        "localRoot": "${workspaceFolder}",
+                        "remoteRoot": "/app"
+                    }
+                ],
+                "projectType": "flask"
+            }
+        }
+    ]
+}

+ 40 - 0
.vscode/tasks.json

@@ -0,0 +1,40 @@
+{
+	"version": "2.0.0",
+	"tasks": [
+		{
+			"type": "docker-build",
+			"label": "docker-build",
+			"platform": "python",
+			"dockerBuild": {
+				"tag": "fastapi:latest",
+				"dockerfile": "${workspaceFolder}/Dockerfile",
+				"context": "${workspaceFolder}",
+				"pull": true
+			}
+		},
+		{
+			"type": "docker-run",
+			"label": "docker-run: debug",
+			"dependsOn": [
+				"docker-build"
+			],
+			"dockerRun": {
+				"env": {
+					"FLASK_APP": "aa"
+				}
+			},
+			"python": {
+				"args": [
+					"run",
+					"--no-debugger",
+					"--no-reload",
+					"--host",
+					"0.0.0.0",
+					"--port",
+					"5002"
+				],
+				"module": "flask"
+			}
+		}
+	]
+}

+ 25 - 0
Dockerfile

@@ -0,0 +1,25 @@
+# For more information, please refer to https://aka.ms/vscode-docker-python
+FROM python:3.10-slim
+
+EXPOSE 5002
+
+# Keeps Python from generating .pyc files in the container
+ENV PYTHONDONTWRITEBYTECODE=1
+
+# Turns off buffering for easier container logging
+ENV PYTHONUNBUFFERED=1
+
+# Install pip requirements
+COPY requirements.txt .
+RUN python -m pip install -r requirements.txt
+
+WORKDIR /app
+COPY . /app
+
+# Creates a non-root user with an explicit UID and adds permission to access the /app folder
+# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
+RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
+USER appuser
+
+# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
+CMD ["gunicorn", "--bind", "0.0.0.0:5002", "aa:app"]

+ 2 - 0
README.md

@@ -1,5 +1,7 @@
 # fastapi
 
+fastapi
+
 ```
 pip install fastapi
 pip install uvicorn

+ 25 - 0
backend/Dockerfile

@@ -0,0 +1,25 @@
+# For more information, please refer to https://aka.ms/vscode-docker-python
+FROM python:3.10-slim
+
+EXPOSE 5002
+
+# Keeps Python from generating .pyc files in the container
+ENV PYTHONDONTWRITEBYTECODE=1
+
+# Turns off buffering for easier container logging
+ENV PYTHONUNBUFFERED=1
+
+# Install pip requirements
+COPY requirements.txt .
+RUN python -m pip install -r requirements.txt
+
+WORKDIR /app
+COPY . /app
+
+# Creates a non-root user with an explicit UID and adds permission to access the /app folder
+# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
+RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
+USER appuser
+
+# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
+CMD ["gunicorn", "--bind", "0.0.0.0:5002", "aa:app"]

+ 1 - 0
backend/app/__init__.py

@@ -0,0 +1 @@
+from .app import app

+ 13 - 0
backend/app/app.py

@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2024/03/19 16:50:59
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+from fastapi import FastAPI
+from app.api import api_router
+
+if __name__=='__main__':
+    pass

+ 0 - 0
backend/app/config.py


+ 12 - 0
backend/main.py

@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2024/03/19 16:50:59
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   
+'''
+
+from app import app
+if __name__=='__main__':
+    pass

+ 0 - 0
deploy/mysql/my.conf


+ 11 - 0
deploy/nginx/default.conf

@@ -0,0 +1,11 @@
+server {
+  listen 80;
+
+  location / {
+    root /usr/share/nginx/html;
+    index index.html index.htm;
+    try_files $uri /index.html =404;
+  }
+
+  include /etc/nginx/extra-conf.d/*.conf;
+}

+ 14 - 0
docker-compose.debug.yml

@@ -0,0 +1,14 @@
+version: '3.4'
+
+services:
+  fastapi:
+    image: fastapi
+    build:
+      context: .
+      dockerfile: ./Dockerfile
+    command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m flask run --no-debugger --no-reload --host 0.0.0.0 --port 5002"]
+    ports:
+      - 5002:5002
+      - 5678:5678
+    environment:
+      - FLASK_APP=-m aa

+ 44 - 0
docker-compose.yml

@@ -0,0 +1,44 @@
+version: '3.4'
+
+services:
+  fastapi:
+    image: fastapi
+    build:
+      context: .
+      dockerfile: ./Dockerfile
+    ports:
+      - 5002:5002
+    
+  db:
+    image: postgres:12
+    environment:
+      POSTGRES_USER: postgres
+      POSTGRES_PASSWORD: postgres
+      POSTGRES_DB: fastapi
+    env_file:
+      - .env
+    ports:
+      - 5432:5432
+    volumes:
+      - pgdata:/var/lib/postgresql/data
+    restart: always
+  
+  adminer:
+    image: adminer:latest
+    ports:
+      - 8080:8080
+    restart: always
+    networks:
+      - fastapi-network
+    depends_on:
+      - db
+    environment:
+      - ADMINER_DESIGN=pepa-linha-dark
+
+volumes:
+  pgdata:
+
+networks:
+  fastapi-network:
+    driver: bridge
+    external: true

+ 0 - 0
docs/Develop.md


+ 0 - 0
docs/Index.md


+ 12 - 0
frontend/Dockerfile

@@ -0,0 +1,12 @@
+FROM node:20 as build-stage
+WORKDIR /app
+COPY package*.json /app/
+RUN npm install
+COPY ./ /app/
+ARG VITE_API_URL=${VITE_API_URL}
+RUN npm run build
+
+FROM nginx:1
+COPY --from=build-stage /app/dist/ /usr/share/nginx/html
+COPY ./nginx.conf /etc/nginx/conf.d/default.conf
+COPY ./nginx-backend-not-found.conf /etc/nginx/extra-conf.d/backend-not-found.conf

+ 41 - 0
frontend/package.json

@@ -0,0 +1,41 @@
+{
+    "name": "frontend",
+    "private": true,
+    "version": "0.0.0",
+    "type": "module",
+    "scripts": {
+        "dev": "vite",
+        "build": "tsc && vite build",
+        "lint": "biome check --apply-unsafe --no-errors-on-unmatched --files-ignore-unknown=true ./",
+        "preview": "vite preview",
+        "generate-client": "openapi --input ./openapi.json --useOptions --useUnionTypes --output ./src/client --client axios --exportSchemas true"
+    },
+    "dependencies": {
+        "@chakra-ui/icons": "2.1.1",
+        "@chakra-ui/react": "2.8.2",
+        "@emotion/react": "11.11.3",
+        "@emotion/styled": "11.11.0",
+        "@tanstack/react-router": "1.19.1",
+        "axios": "1.6.2",
+        "form-data": "4.0.0",
+        "framer-motion": "10.16.16",
+        "react": "^18.2.0",
+        "react-dom": "^18.2.0",
+        "react-hook-form": "7.49.3",
+        "react-icons": "5.0.1",
+        "react-query": "3.39.3",
+        "zustand": "4.5.0"
+    },
+    "devDependencies": {
+        "@biomejs/biome": "1.6.1",
+        "@tanstack/router-devtools": "1.19.1",
+        "@tanstack/router-vite-plugin": "1.19.0",
+        "@types/node": "20.10.5",
+        "@types/react": "^18.2.37",
+        "@types/react-dom": "^18.2.15",
+        "@vitejs/plugin-react-swc": "^3.5.0",
+        "openapi-typescript-codegen": "0.25.0",
+        "typescript": "^5.2.2",
+        "vite": "^5.0.12"
+    }
+}

+ 3 - 0
requirements.txt

@@ -0,0 +1,3 @@
+# To ensure app dependencies are ported from your virtual environment/host machine into your container, run 'pip freeze > requirements.txt' in the terminal to overwrite this file
+flask==3.0.0
+gunicorn==20.1.0