提交docker编译
This commit is contained in:
parent
ce94f58eb0
commit
e4e52db4f3
|
|
@ -1,11 +1,27 @@
|
||||||
# Dockerfile
|
|
||||||
FROM python:3.9-slim
|
FROM python:3.9-slim
|
||||||
|
|
||||||
# 安装nginx
|
# 设置时区
|
||||||
RUN apt-get update && apt-get install -y \
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
# 完全清空并重写所有源文件
|
||||||
|
RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/* && \
|
||||||
|
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main" > /etc/apt/sources.list && \
|
||||||
|
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main" >> /etc/apt/sources.list && \
|
||||||
|
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security trixie-security main" >> /etc/apt/sources.list
|
||||||
|
|
||||||
|
|
||||||
|
# 设置 ll 别名
|
||||||
|
RUN echo "alias ll='ls -alF'" >> /root/.bashrc
|
||||||
|
|
||||||
|
# 安装 nginx
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
nginx \
|
nginx \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# 设置 pip 清华源
|
||||||
|
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
|
||||||
|
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn
|
||||||
|
|
||||||
# 创建应用目录
|
# 创建应用目录
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
@ -32,4 +48,4 @@ RUN chmod +x /start.sh
|
||||||
# 初始化数据库
|
# 初始化数据库
|
||||||
RUN python backend/init_db.py
|
RUN python backend/init_db.py
|
||||||
|
|
||||||
ENTRYPOINT ["/start.sh"]
|
ENTRYPOINT ["/start.sh"]
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ CORS(app)
|
||||||
def get_db_connection():
|
def get_db_connection():
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
|
# 确保使用UTF-8编码
|
||||||
|
conn.execute('PRAGMA encoding = "UTF-8"')
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
@app.route('/api/cars', methods=['GET'])
|
@app.route('/api/cars', methods=['GET'])
|
||||||
|
|
@ -69,6 +71,7 @@ def search_car():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
|
# 修改查询语句以正确处理中文字符
|
||||||
cars = conn.execute('SELECT * FROM cars WHERE plate LIKE ?', (f'%{plate}%',)).fetchall()
|
cars = conn.execute('SELECT * FROM cars WHERE plate LIKE ?', (f'%{plate}%',)).fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
@ -85,6 +88,7 @@ def get_car_by_plate(plate):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
|
# 修改查询语句以正确处理中文字符
|
||||||
car = conn.execute('SELECT * FROM cars WHERE plate = ?', (plate,)).fetchone()
|
car = conn.execute('SELECT * FROM cars WHERE plate = ?', (plate,)).fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# backend/init_db.py
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
@ -10,6 +11,8 @@ os.makedirs(os.path.dirname(db_path), exist_ok=True)
|
||||||
|
|
||||||
# 创建数据库连接
|
# 创建数据库连接
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
|
# 确保使用UTF-8编码
|
||||||
|
conn.execute('PRAGMA encoding = "UTF-8"')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# 创建车辆表
|
# 创建车辆表
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从后端API获取数据
|
// 从后端API获取数据
|
||||||
console.log(`发送请求到: http://localhost:5000/api/cars/search?plate=${encodeURIComponent(plate)}`);
|
console.log(`发送请求到: /api/cars/search?plate=${encodeURIComponent(plate)}`);
|
||||||
fetch(`http://localhost:5000/api/cars/search?plate=${encodeURIComponent(plate)}`)
|
fetch(`/api/cars/search?plate=${encodeURIComponent(plate)}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
console.log(`收到响应状态: ${response.status}`);
|
console.log(`收到响应状态: ${response.status}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,11 @@ mvcar/
|
||||||
# 构建Docker镜像
|
# 构建Docker镜像
|
||||||
docker build -t mvcar-app .
|
docker build -t mvcar-app .
|
||||||
|
|
||||||
|
# 构建Docker镜像
|
||||||
|
docker build -t mvcar-app:v1.0.0 -t mvcar-app:latest .
|
||||||
|
|
||||||
# 运行容器
|
# 运行容器
|
||||||
docker run -d -p 80:80 --name mvcar-container mvcar-app
|
docker run -d -p 80:80 --name mvcar-container mvcar-app
|
||||||
|
|
||||||
# 或者使用docker-compose(如果创建了docker-compose.yml)
|
# 或者使用docker-compose(如果创建了docker-compose.yml)
|
||||||
docker-compose up --build -d
|
docker-compose up --build -d
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue