初始化项目文件

This commit is contained in:
2025-07-11 16:54:11 +08:00
parent 6bffd582a0
commit 39fedaac16
213 changed files with 16944 additions and 0 deletions

11
build_file/dev/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM nginx
RUN mkdir -p /data \
&& cd /data \
&& mkdir static \
&& mkdir upload \
&& mkdir upload-video \
&& mkdir upload-note
COPY default.conf /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY dist /usr/share/nginx/html

54
build_file/dev/build.py Normal file
View File

@ -0,0 +1,54 @@
# coding=utf-8
import datetime
import os
def cp_file(rsc, des):
file_list = os.listdir(rsc)
for i in file_list:
if i in ['venv', '.idea', '.gitignore', 'static', 'migrations', '.git', '__pycache__', 'upload', 'templates', 'logs', 'upload-video', 'build.py', 'move.sh']:
continue
if os.path.isfile(os.path.join(rsc, i)):
os.system('copy /Y %s %s' % (os.path.join(rsc, i), os.path.join(des, i)))
else:
os.makedirs(os.path.join(des, i))
cp_file(os.path.join(rsc, i), os.path.join(des, i))
# 程序执行会将前后端程序复制到部署文件夹
if __name__ == '__main__':
os.system('chcp 65001')
build_dir = r'C:\Users\m1582\Documents\vmshare\build'
date = datetime.datetime.today().date().strftime('%Y-%m-%d')
# 公共api
rsc_dir = r'..\..\api_django'
des_dir = r'%s\api_django' % build_dir
if os.path.exists(des_dir):
if not os.path.exists(r'%s\zzzz_bak' % build_dir):
os.makedirs(r'%s\zzzz_bak' % build_dir)
if os.path.exists(r'%s\zzzz_bak\%s_api_django' % (build_dir, date)):
os.system(r'rd /s /q %s\zzzz_bak\%s_api_django' % (build_dir, date))
os.system(r'move %s %s\zzzz_bak\%s_api_django' % (des_dir, build_dir, date))
os.makedirs(des_dir)
cp_file(rsc_dir, des_dir)
# 后端
rsc_dir = r'..\..\api_iris'
des_dir = r'%s\api_iris' % build_dir
if os.path.exists(des_dir):
if not os.path.exists(r'%s\zzzz_bak' % build_dir):
os.makedirs(r'%s\zzzz_bak' % build_dir)
if os.path.exists(r'%s\zzzz_bak\%s_api_iris' % (build_dir, date)):
os.system(r'rd /s /q %s\zzzz_bak\%s_api_iris' % (build_dir, date))
os.system(r'move %s %s\zzzz_bak\%s_api_iris' % (des_dir, build_dir, date))
os.makedirs(des_dir)
cp_file(rsc_dir, des_dir)
# 前端
rsc_dir_web = r'C:\Users\m1582\Documents\project\web_ylsa\web_vue\dist'
if os.path.exists(rsc_dir_web):
if os.path.exists(r'%s\dist' % build_dir):
if os.path.exists(r'%s\zzzz_bak\%s_dist' % (build_dir, date)):
os.system(r'rd /s /q %s\zzzz_bak\%s_dist' % (build_dir, date))
os.system(r'move %s/dist %s\zzzz_bak\%s_dist' % (build_dir, build_dir, date))
os.system('move %s %s' % (rsc_dir_web, build_dir))
# 配置文件
cp_file(r".\\", build_dir)

View File

@ -0,0 +1,86 @@
upstream api_iris {
server api_iris:8080;
}
upstream api_django {
server api_django:8000;
}
server {
listen 80;
proxy_read_timeout 600;
client_max_body_size 9000m;
autoindex on;
autoindex_exact_size off;
set_real_ip_from 192.168.0.0/16;
real_ip_header proxy_protocol;
autoindex_localtime on;
charset utf-8;
root /usr/share/nginx/html;
location /api/ {
proxy_pass http://api_iris/api/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api_django/ {
proxy_pass http://api_django/api/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /admin/ {
proxy_pass http://api_iris/admin/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static/ {
alias /data/static/;
}
location /upload/ {
internal;
alias /data/upload/;
sendfile on;
charset utf-8;
}
location /upload-note/ {
internal;
alias /data/upload-note/;
sendfile on;
charset utf-8;
}
location /upload-video/ {
internal;
alias /data/upload-video/;
sendfile on;
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
charset utf-8;
}
location ^~/ws {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://api_iris/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
location / {
try_files $uri /index.html;
autoindex on;
}
}

View File

@ -0,0 +1,60 @@
version: "3"
services:
api_iris:
image: api_iris:1.0
container_name: api_iris
restart: always
environment:
- version=dev
healthcheck:
test:
[
"CMD-SHELL",
"curl -sS 'http://127.0.0.1:8080/api' || kill 1"
]
interval: 5m
timeout: 10s
retries: 3
volumes:
- "/mnt/static:/web/api_iris/static/"
- "/mnt/upload:/web/api_iris/upload/"
- "/mnt/upload-note:/web/api_iris/upload-note/"
- "/mnt/upload-video:/web/api_iris/upload-video/"
- "/mnt/log/api_iris:/web/api_iris/logs/"
- "/mnt/log/nginx_vue:/web/api_iris/logs/nginx"
- "/etc/localtime:/etc/localtime"
api_django:
image: api_django:1.0
container_name: api_django
restart: always
command: /bin/bash -c "uwsgi --ini uwsgi.ini"
healthcheck:
test:
[
"CMD-SHELL",
"curl -sS 'http://127.0.0.1:8000/api' || kill 1"
]
interval: 5m
timeout: 10s
retries: 3
volumes:
- "/etc/localtime:/etc/localtime"
web_ylsa:
image: web_ylsa:1.0
container_name: web_ylsa
restart: always
volumes:
- "/mnt/static:/data/static/"
- "/mnt/upload:/data/upload/"
- "/mnt/upload-note:/data/upload-note/"
- "/mnt/upload-video:/data/upload-video/"
- "/mnt/log/nginx-vue:/var/log/nginx/"
- "/etc/localtime:/etc/localtime"
ports:
- "80:80"
depends_on:
- api_iris
- api_django

20
build_file/dev/move-o.sh Normal file
View File

@ -0,0 +1,20 @@
#!/bin/bash
if [[ -n $(docker ps -q -f "name=api_iris") ]]; then
cd /data/web/myweb
docker-compose down
fi
cd /data/web
if [[ -d "myweb_$(date +%Y%m%d)" ]]; then
rm -rf myweb_$(date +%Y%m%d)
fi
if [[ -d "myweb" ]]; then
mv myweb myweb_$(date +%Y%m%d)
fi
mkdir myweb
cp /mnt/build/build.zip myweb
cd myweb
unzip build.zip
chmod 755 -R /data/web/myweb
cd /data/web/myweb
sh update.sh

20
build_file/dev/move.sh Normal file
View File

@ -0,0 +1,20 @@
#!/bin/bash
if [[ -n $(docker ps -qa -f "name=api_iris") ]]; then
cd /data/web/myweb
docker-compose down
fi
cd /data/web
if [[ -d "myweb_$(date +%Y%m%d)" ]]; then
rm -rf myweb_$(date +%Y%m%d)
fi
if [[ -d "myweb" ]]; then
mv myweb myweb_$(date +%Y%m%d)
fi
mkdir myweb
cp /mnt/build/build.zip myweb
cd myweb
unzip build.zip
chmod 755 -R /data/web/myweb
cd /data/web/myweb
bash update.sh $@

46
build_file/dev/nginx.conf Normal file
View File

@ -0,0 +1,46 @@
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
map $time_iso8601 $logDate {
'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
default 'date-not-found';
}
access_log /var/log/nginx/access-$logDate.log main;
open_log_file_cache max=10;
sendfile on;
#tcp_nopush on;
keepalive_timeout 600;
client_header_timeout 600;
client_body_timeout 600;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
}

View File

@ -0,0 +1,34 @@
#!/bin/bash
if [ "$(sudo docker images -q web_ylsa:1.0 2> /dev/null)" != "" ];
then
echo web_ylsa------remove
sudo docker rmi web_ylsa:1.0
fi
if [ "$(sudo docker images -q api_iris:1.0 2> /dev/null)" != "" ];
then
echo api_iris------remove
sudo docker rmi api_iris:1.0
fi
if [ "$(sudo docker images -q api_django:1.0 2> /dev/null)" != "" ];
then
echo api_django------remove
sudo docker rmi api_django:1.0
fi
echo web_ylsa------building
sudo docker build -t web_ylsa:1.0 .
echo web_ylsa------complete
echo api_iris------building
sudo docker build -t api_iris:1.0 ./api_iris
echo api_iris------complete
echo api_django------building
docker build -t api_django:1.0 ./api_django
echo api_django------complete
docker-compose up -d
echo complete

27
build_file/dev/update.sh Normal file
View File

@ -0,0 +1,27 @@
#!/bin/bash
if [ $# == 0 ];then
args=("web_vue" "api_iris" "api_django")
else
args=$@
fi
for arg in ${args[*]};do
if [ $arg == "" ]; then
continue
fi
if [ "$(sudo docker images -q $arg:1.0 2> /dev/null)" != "" ];
then
echo $arg------remove
sudo docker rmi $arg:1.0
fi
echo $arg------building
if [ $arg == "web_vue" ];then
sudo docker build -t $arg:1.0 .
else
sudo docker build -t $arg:1.0 ./$arg
fi
echo $arg------complete
done
docker-compose up -d
echo complete