Skip to content

Commit fa5aacf

Browse files
authored
Merge pull request #152 from buyfakett/master
减小docker镜像
2 parents 9602ad3 + 3563b86 commit fa5aacf

20 files changed

+24
-8
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.md
2+
.idea
3+
.git

Dockerfile

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
FROM python:3.9.5-slim-buster
1+
FROM node:18-alpine as webui
2+
COPY . /app
3+
WORKDIR /app/fcb-fronted/
4+
ENV NPM_CONFIG_LOGLEVEL=verbose
5+
RUN npm i
6+
RUN npm run build-only
7+
# 似乎需要把文件移动才能正常
8+
RUN mv dist/logo_small.png dist/assets/
9+
10+
11+
FROM python:3.9.5-alpine as FileCodeBox
212
LABEL author="Lan"
313
LABEL email="vast@tom.com"
414
LABEL version="6"
515

616

7-
COPY . /app
17+
# 先安装依赖可以产生缓存
18+
WORKDIR /app
19+
COPY requirements.txt /app
20+
RUN /usr/local/bin/python -m pip install --upgrade pip && pip install -r requirements.txt
21+
COPY ./backend/ /app
22+
COPY --from=webui /app/fcb-fronted/dist/ /app/dist
823
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
924
RUN echo 'Asia/Shanghai' >/etc/timezone
10-
WORKDIR /app
11-
RUN pip install -r requirements.txt
1225
EXPOSE 12345
1326
CMD ["python","main.py"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

main.py renamed to backend/main.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@
3131
async def assets(file_path: str):
3232
if settings.max_save_seconds > 0:
3333
if re.match(r'SendView-[\d|a-f|A-F]+\.js', file_path):
34-
with open(BASE_DIR / f'./fcb-fronted/dist/assets/{file_path}', 'r', encoding='utf-8') as f:
34+
with open(BASE_DIR / f'./dist/assets/{file_path}', 'r', encoding='utf-8') as f:
3535
# 删除永久保存选项
3636
content = f.read()
3737
content = content.replace('_(c,{label:e(r)("send.expireData.forever"),value:"forever"},null,8,["label"]),', '')
3838
return HTMLResponse(content=content, media_type='text/javascript')
3939
if re.match(r'index-[\d|a-f|A-F]+\.js', file_path):
40-
with open(BASE_DIR / f'./fcb-fronted/dist/assets/{file_path}', 'r', encoding='utf-8') as f:
40+
with open(BASE_DIR / f'./dist/assets/{file_path}', 'r', encoding='utf-8') as f:
4141
# 更改本文描述
4242
desc_zh, desc_en = await max_save_times_desc(settings.max_save_seconds)
4343
content = f.read()
4444
content = content.replace('天数<7', desc_zh)
4545
content = content.replace('Days <7', desc_en)
4646
return HTMLResponse(content=content, media_type='text/javascript')
47-
return FileResponse(f'./fcb-fronted/dist/assets/{file_path}')
47+
return FileResponse(f'./dist/assets/{file_path}')
4848

4949

5050
register_tortoise(
@@ -79,7 +79,7 @@ async def startup_event():
7979
@app.get('/')
8080
async def index():
8181
return HTMLResponse(
82-
content=open(BASE_DIR / './fcb-fronted/dist/index.html', 'r', encoding='utf-8').read()
82+
content=open(BASE_DIR / './dist/index.html', 'r', encoding='utf-8').read()
8383
.replace('{{title}}', str(settings.name))
8484
.replace('{{description}}', str(settings.description))
8585
.replace('{{keywords}}', str(settings.keywords))

0 commit comments

Comments
 (0)