From 68acfc2176b531682995919227ae1c4d91854bfc Mon Sep 17 00:00:00 2001 From: buyfakett Date: Wed, 1 May 2024 23:31:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index baecefd..f2c88e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9.5-slim-buster +FROM python:3.9.5-alpine LABEL author="Lan" LABEL email="vast@tom.com" LABEL version="6" From b0817517b61658706afb6070dcb955abcfbe8559 Mon Sep 17 00:00:00 2001 From: buyfakett Date: Thu, 2 May 2024 00:29:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=EF=BC=8C=E5=89=8D=E7=AB=AF=E5=9C=A8?= =?UTF-8?q?docker=E4=B8=AD=E7=BC=96=E8=AF=91=EF=BC=8C=E8=BF=9B=E4=B8=80?= =?UTF-8?q?=E6=AD=A5=E5=87=8F=E5=B0=8F=E9=95=9C=E5=83=8F=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 3 +++ Dockerfile | 21 +++++++++++++++++---- {apps => backend/apps}/__init__.py | 0 {apps => backend/apps}/admin/__init__.py | 0 {apps => backend/apps}/admin/depends.py | 0 {apps => backend/apps}/admin/pydantics.py | 0 {apps => backend/apps}/admin/views.py | 0 {apps => backend/apps}/base/__init__.py | 0 {apps => backend/apps}/base/depends.py | 0 {apps => backend/apps}/base/models.py | 0 {apps => backend/apps}/base/pydantics.py | 0 {apps => backend/apps}/base/utils.py | 0 {apps => backend/apps}/base/views.py | 0 {core => backend/core}/__init__.py | 0 {core => backend/core}/response.py | 0 {core => backend/core}/settings.py | 0 {core => backend/core}/storage.py | 0 {core => backend/core}/tasks.py | 0 {core => backend/core}/utils.py | 0 main.py => backend/main.py | 8 ++++---- 20 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 .dockerignore rename {apps => backend/apps}/__init__.py (100%) rename {apps => backend/apps}/admin/__init__.py (100%) rename {apps => backend/apps}/admin/depends.py (100%) rename {apps => backend/apps}/admin/pydantics.py (100%) rename {apps => backend/apps}/admin/views.py (100%) rename {apps => backend/apps}/base/__init__.py (100%) rename {apps => backend/apps}/base/depends.py (100%) rename {apps => backend/apps}/base/models.py (100%) rename {apps => backend/apps}/base/pydantics.py (100%) rename {apps => backend/apps}/base/utils.py (100%) rename {apps => backend/apps}/base/views.py (100%) rename {core => backend/core}/__init__.py (100%) rename {core => backend/core}/response.py (100%) rename {core => backend/core}/settings.py (100%) rename {core => backend/core}/storage.py (100%) rename {core => backend/core}/tasks.py (100%) rename {core => backend/core}/utils.py (100%) rename main.py => backend/main.py (88%) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38d43dd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +*.md +.idea +.git diff --git a/Dockerfile b/Dockerfile index f2c88e3..36d3847 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,26 @@ -FROM python:3.9.5-alpine +FROM node:18-alpine as webui +COPY . /app +WORKDIR /app/fcb-fronted/ +ENV NPM_CONFIG_LOGLEVEL=verbose +RUN npm i +RUN npm run build-only +# 似乎需要把文件移动才能正常 +RUN mv dist/logo_small.png dist/assets/ + + +FROM python:3.9.5-alpine as FileCodeBox LABEL author="Lan" LABEL email="vast@tom.com" LABEL version="6" -COPY . /app +# 先安装依赖可以产生缓存 +WORKDIR /app +COPY requirements.txt /app +RUN /usr/local/bin/python -m pip install --upgrade pip && pip install -r requirements.txt +COPY ./backend/ /app +COPY --from=webui /app/fcb-fronted/dist/ /app/dist RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' >/etc/timezone -WORKDIR /app -RUN pip install -r requirements.txt EXPOSE 12345 CMD ["python","main.py"] \ No newline at end of file diff --git a/apps/__init__.py b/backend/apps/__init__.py similarity index 100% rename from apps/__init__.py rename to backend/apps/__init__.py diff --git a/apps/admin/__init__.py b/backend/apps/admin/__init__.py similarity index 100% rename from apps/admin/__init__.py rename to backend/apps/admin/__init__.py diff --git a/apps/admin/depends.py b/backend/apps/admin/depends.py similarity index 100% rename from apps/admin/depends.py rename to backend/apps/admin/depends.py diff --git a/apps/admin/pydantics.py b/backend/apps/admin/pydantics.py similarity index 100% rename from apps/admin/pydantics.py rename to backend/apps/admin/pydantics.py diff --git a/apps/admin/views.py b/backend/apps/admin/views.py similarity index 100% rename from apps/admin/views.py rename to backend/apps/admin/views.py diff --git a/apps/base/__init__.py b/backend/apps/base/__init__.py similarity index 100% rename from apps/base/__init__.py rename to backend/apps/base/__init__.py diff --git a/apps/base/depends.py b/backend/apps/base/depends.py similarity index 100% rename from apps/base/depends.py rename to backend/apps/base/depends.py diff --git a/apps/base/models.py b/backend/apps/base/models.py similarity index 100% rename from apps/base/models.py rename to backend/apps/base/models.py diff --git a/apps/base/pydantics.py b/backend/apps/base/pydantics.py similarity index 100% rename from apps/base/pydantics.py rename to backend/apps/base/pydantics.py diff --git a/apps/base/utils.py b/backend/apps/base/utils.py similarity index 100% rename from apps/base/utils.py rename to backend/apps/base/utils.py diff --git a/apps/base/views.py b/backend/apps/base/views.py similarity index 100% rename from apps/base/views.py rename to backend/apps/base/views.py diff --git a/core/__init__.py b/backend/core/__init__.py similarity index 100% rename from core/__init__.py rename to backend/core/__init__.py diff --git a/core/response.py b/backend/core/response.py similarity index 100% rename from core/response.py rename to backend/core/response.py diff --git a/core/settings.py b/backend/core/settings.py similarity index 100% rename from core/settings.py rename to backend/core/settings.py diff --git a/core/storage.py b/backend/core/storage.py similarity index 100% rename from core/storage.py rename to backend/core/storage.py diff --git a/core/tasks.py b/backend/core/tasks.py similarity index 100% rename from core/tasks.py rename to backend/core/tasks.py diff --git a/core/utils.py b/backend/core/utils.py similarity index 100% rename from core/utils.py rename to backend/core/utils.py diff --git a/main.py b/backend/main.py similarity index 88% rename from main.py rename to backend/main.py index 2c2ddee..fe148ca 100644 --- a/main.py +++ b/backend/main.py @@ -31,20 +31,20 @@ app.add_middleware( async def assets(file_path: str): if settings.max_save_seconds > 0: if re.match(r'SendView-[\d|a-f|A-F]+\.js', file_path): - with open(BASE_DIR / f'./fcb-fronted/dist/assets/{file_path}', 'r', encoding='utf-8') as f: + with open(BASE_DIR / f'./dist/assets/{file_path}', 'r', encoding='utf-8') as f: # 删除永久保存选项 content = f.read() content = content.replace('_(c,{label:e(r)("send.expireData.forever"),value:"forever"},null,8,["label"]),', '') return HTMLResponse(content=content, media_type='text/javascript') if re.match(r'index-[\d|a-f|A-F]+\.js', file_path): - with open(BASE_DIR / f'./fcb-fronted/dist/assets/{file_path}', 'r', encoding='utf-8') as f: + with open(BASE_DIR / f'./dist/assets/{file_path}', 'r', encoding='utf-8') as f: # 更改本文描述 desc_zh, desc_en = await max_save_times_desc(settings.max_save_seconds) content = f.read() content = content.replace('天数<7', desc_zh) content = content.replace('Days <7', desc_en) return HTMLResponse(content=content, media_type='text/javascript') - return FileResponse(f'./fcb-fronted/dist/assets/{file_path}') + return FileResponse(f'./dist/assets/{file_path}') register_tortoise( @@ -79,7 +79,7 @@ async def startup_event(): @app.get('/') async def index(): return HTMLResponse( - content=open(BASE_DIR / './fcb-fronted/dist/index.html', 'r', encoding='utf-8').read() + content=open(BASE_DIR / './dist/index.html', 'r', encoding='utf-8').read() .replace('{{title}}', str(settings.name)) .replace('{{description}}', str(settings.description)) .replace('{{keywords}}', str(settings.keywords))