Skip to content

Commit

Permalink
- 优化Windows打包
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Oct 10, 2023
1 parent 65b5219 commit 60140fd
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ jobs:
pip install -r requirements.txt
shell: pwsh

- name: Prepare Frontend
run: |
Invoke-WebRequest -Uri "http://nginx.org/download/nginx-1.25.2.zip" -OutFile "nginx.zip"
Expand-Archive -Path "nginx.zip" -DestinationPath "nginx-1.25.2"
Move-Item -Path "nginx-1.25.2/nginx-1.25.2" -Destination "nginx"
Remove-Item -Path "nginx.zip"
Remove-Item -Path "nginx-1.25.2" -Recurse -Force
$FRONTEND_VERSION = (Invoke-WebRequest -Uri "https://api.github.com/repos/jxxghp/MoviePilot-Frontend/releases/latest" | ConvertFrom-Json).tag_name
Invoke-WebRequest -Uri "https://github.com/jxxghp/MoviePilot-Frontend/releases/download/$FRONTEND_VERSION/dist.zip" -OutFile "dist.zip"
Expand-Archive -Path "dist.zip" -DestinationPath "dist"
Move-Item -Path "dist/dist/*" -Destination "nginx/html" -Force
Remove-Item -Path "dist.zip"
Remove-Item -Path "dist" -Recurse -Force
Move-Item -Path "nginx/html/nginx.conf" -Destination "nginx/conf/nginx.conf" -Force
shell: pwsh

- name: Pyinstaller
run: |
pyinstaller windows.spec
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ MoviePilot需要配套下载器和媒体服务器配合使用。
docker pull jxxghp/moviepilot:latest
```

- Window
- Windows

后端:https://github.com/jxxghp/MoviePilot/releases

前端:https://github.com/jxxghp/MoviePilot-Frontend/releases
下载 [MoviePilot.exe](https://github.com/jxxghp/MoviePilot/releases),双击运行后自动生成配置文件目录。

## 配置

项目的所有配置均通过环境变量进行设置,支持两种配置方式:
- 在docker环境变量部分进行参数配置,部分环境建立容器后会自动显示待配置项,如未自动显示配置项则需要手动增加对应环境变量。
- 下载 [app.env](https://github.com/jxxghp/MoviePilot/raw/main/config/app.env) 文件,修改好配置后放置到配置文件映射路径根目录,配置项可根据说明自主增减。
- 在Docker环境变量部分或Wdinows系统环境变量中进行参数配置,如未自动显示配置项则需要手动增加对应环境变量。
- 下载 [app.env](https://github.com/jxxghp/MoviePilot/raw/main/config/app.env) 配置文件,修改好配置后放置到配置文件映射路径根目录,配置项可根据说明自主增减。

配置文件映射路径:`/config`,配置项生效优先级:环境变量 > env文件 > 默认值,部分参数如路径映射、站点认证、权限端口等必须通过环境变量进行配置
配置文件映射路径:`/config`,配置项生效优先级:环境变量 > env文件 > 默认值,**部分参数如路径映射、站点认证、权限端口、时区等必须通过环境变量进行配置**

> $\color{red}{*}$ 号标识的为必填项,其它为可选项,可选项可删除配置变量从而使用默认值。

Expand Down
1 change: 0 additions & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import secrets
import sys
from pathlib import Path
Expand Down
36 changes: 35 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import multiprocessing
from pathlib import Path

import uvicorn as uvicorn
from fastapi import FastAPI
Expand All @@ -13,6 +14,7 @@
from app.helper.display import DisplayHelper
from app.helper.sites import SitesHelper
from app.scheduler import Scheduler
from app.utils.system import SystemUtils

# App
App = FastAPI(title=settings.PROJECT_NAME,
Expand Down Expand Up @@ -44,6 +46,34 @@ def init_routers():
App.include_router(arr_router, prefix="/api/v3")


def start_frontend():
"""
启动前端服务
"""
if not SystemUtils.is_frozen():
return
if SystemUtils.is_windows():
nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx.exe'
else:
nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx'
if Path(nginx_path).exists():
import subprocess
subprocess.Popen(f"start {nginx_path}", shell=True)


def stop_frontend():
"""
停止前端服务
"""
if not SystemUtils.is_frozen():
return
import subprocess
if SystemUtils.is_windows():
subprocess.Popen(f"taskkill /f /im nginx.exe", shell=True)
else:
subprocess.Popen(f"killall nginx", shell=True)


@App.on_event("shutdown")
def shutdown_server():
"""
Expand All @@ -59,14 +89,16 @@ def shutdown_server():
DisplayHelper().stop()
# 停止定时服务
Scheduler().stop()
# 停止前端服务
stop_frontend()


@App.on_event("startup")
def start_module():
"""
启动模块
"""
# 虚伪显示
# 虚拟显示
DisplayHelper()
# 站点管理
SitesHelper()
Expand All @@ -80,6 +112,8 @@ def start_module():
Command()
# 初始化路由
init_routers()
# 启动前端服务
start_frontend()


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APP_VERSION = 'v1.3.0'
APP_VERSION = 'v1.3.0-1'
1 change: 1 addition & 0 deletions windows.spec
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ exe = EXE(
a.zipfiles,
a.datas,
collect_pkg_data('config'),
collect_pkg_data('nginx'),
collect_pkg_data('cf_clearance'),
collect_pkg_data('database', include_py_files=True),
[],
Expand Down

0 comments on commit 60140fd

Please sign in to comment.