Skip to content

Commit 88008f1

Browse files
committed
feat: compress report js
chore: change docker-compose port
1 parent d14572b commit 88008f1

File tree

12 files changed

+569
-41
lines changed

12 files changed

+569
-41
lines changed

Diff for: .env.example

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# $ cat ~/.env
22

33
WEB_PORT=80
4-
DJANGO_ADMIN_PORT=8001
5-
DJANGO_API_PORT=8000
4+
DJANGO_ADMIN_PORT=8000
65
SERVER_IP=127.0.0.1 # The host machine IP
76

87

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tempWorkDir
88
mysql
99
.env
1010
/venv/
11-
/static/
11+
/CACHE/
1212

1313

1414
# web

Diff for: FasterRunner/settings/base.py

+47-28
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@
5656
"django_celery_beat",
5757
"rest_framework_swagger",
5858
"drf_yasg",
59+
"compressor",
5960
]
6061

6162
MIDDLEWARE = [
62-
'log_request_id.middleware.RequestIDMiddleware',
63-
"django.middleware.security.SecurityMiddleware",
6463
"django.middleware.gzip.GZipMiddleware",
64+
"htmlmin.middleware.HtmlMinifyMiddleware",
65+
"htmlmin.middleware.MarkRequestMiddleware",
66+
"log_request_id.middleware.RequestIDMiddleware",
67+
"django.middleware.security.SecurityMiddleware",
6568
"django.contrib.sessions.middleware.SessionMiddleware",
6669
"corsheaders.middleware.CorsMiddleware",
6770
"django.middleware.common.CommonMiddleware",
@@ -70,6 +73,32 @@
7073
"django.middleware.clickjacking.XFrameOptionsMiddleware",
7174
"fastrunner.utils.middleware.VisitTimesMiddleware",
7275
]
76+
# Static files (CSS, JavaScript, Images)
77+
# https://docs.djangoproject.com/en/2.1/howto/static-files/
78+
STATIC_URL = "/static/"
79+
80+
STATICFILES_FINDERS = (
81+
"django.contrib.staticfiles.finders.FileSystemFinder",
82+
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
83+
# Add this
84+
"compressor.finders.CompressorFinder",
85+
)
86+
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
87+
COMPRESS_ROOT = os.path.join(BASE_DIR, "static")
88+
STATIC_ROOT = os.path.join(BASE_DIR, "static_root")
89+
COMPRESS_ENABLED = True
90+
COMPRESS_CSS_HASHING_METHOD = "content"
91+
COMPRESS_FILTERS = {
92+
"css": [
93+
"compressor.filters.css_default.CssAbsoluteFilter",
94+
"compressor.filters.cssmin.rCSSMinFilter",
95+
],
96+
"js": [
97+
"compressor.filters.jsmin.JSMinFilter",
98+
],
99+
}
100+
HTML_MINIFY = True
101+
KEEP_COMMENTS_ON_MINIFYING = True
73102

74103
ROOT_URLCONF = "FasterRunner.urls"
75104

@@ -123,11 +152,6 @@
123152

124153
USE_TZ = False
125154

126-
# Static files (CSS, JavaScript, Images)
127-
# https://docs.djangoproject.com/en/2.1/howto/static-files/
128-
129-
STATIC_URL = "/static/"
130-
131155

132156
REST_FRAMEWORK = {
133157
# 'DEFAULT_AUTHENTICATION_CLASSES': ['FasterRunner.auth.DeleteAuthenticator', 'FasterRunner.auth.Authenticator', ],
@@ -229,29 +253,27 @@
229253
"disable_existing_loggers": True,
230254
"formatters": {
231255
"standard": {
232-
'format': '%(levelname)-2s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s',
256+
"format": "%(levelname)-2s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s",
233257
"datefmt": "%Y-%m-%d %H:%M:%S",
234258
},
235-
'color': {
236-
'()': 'colorlog.ColoredFormatter',
237-
'format': '%(green)s%(asctime)s [%(request_id)s] %(name)s %(log_color)s%(levelname)s [pid:%(process)d] '
238-
'[%(filename)s->%(funcName)s:%(lineno)s] %(cyan)s%(message)s',
239-
'log_colors': {
240-
'DEBUG': 'black',
241-
'INFO': 'white',
242-
'WARNING': 'yellow',
243-
'ERROR': 'red',
244-
'CRITICAL': 'bold_red',
259+
"color": {
260+
"()": "colorlog.ColoredFormatter",
261+
"format": "%(green)s%(asctime)s [%(request_id)s] %(name)s %(log_color)s%(levelname)s [pid:%(process)d] "
262+
"[%(filename)s->%(funcName)s:%(lineno)s] %(cyan)s%(message)s",
263+
"log_colors": {
264+
"DEBUG": "black",
265+
"INFO": "white",
266+
"WARNING": "yellow",
267+
"ERROR": "red",
268+
"CRITICAL": "bold_red",
245269
},
246270
}
247271
# 日志格式
248272
},
249273
"filters": {
250-
'request_id': {
251-
'()': 'log_request_id.filters.RequestIDFilter'
252-
},
253-
'require_debug_true': {
254-
'()': 'django.utils.log.RequireDebugTrue', # 过滤器,只有当setting的DEBUG = True时生效
274+
"request_id": {"()": "log_request_id.filters.RequestIDFilter"},
275+
"require_debug_true": {
276+
"()": "django.utils.log.RequireDebugTrue", # 过滤器,只有当setting的DEBUG = True时生效
255277
},
256278
},
257279
"handlers": {
@@ -268,17 +290,14 @@
268290
"maxBytes": 1024 * 1024 * 50,
269291
"backupCount": 5,
270292
"formatter": "color",
271-
'filters': ['request_id'],
272-
293+
"filters": ["request_id"],
273294
},
274295
"console": {
275296
"level": "DEBUG",
276297
"class": "logging.StreamHandler",
277298
"formatter": "color",
278-
'filters': ['request_id'],
279-
299+
"filters": ["request_id"],
280300
},
281-
282301
},
283302
"loggers": {
284303
"django": {

Diff for: FasterRunner/settings/docker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
# broker_url = f'amqp://{mq_user}:{mq_password}@mq:5672//'
6464
broker_url = f'amqp://{MQ_USER}:{MQ_PASSWORD}@mq:{MQ_PORT}//'
6565

66-
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
66+
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
6767

6868
SERVER_IP = environ.get('SERVER_IP', '')
6969
DJANGO_API_PORT = environ.get('DJANGO_API_PORT', '8000')

Diff for: FasterRunner/settings/pro.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# STATIC_URL = '/static/'
6969

7070
# 部署的时候执行python manage.py collectstatic,django会把所有App下的static文件都复制到STATIC_ROOT文件夹下
71-
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
71+
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')
7272

7373
# 开发者模式中使用访问静态文
7474
# STATICFILES_DIRS = (

Diff for: docker-compose.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ services:
3838
command: -c "/app/start.sh app"
3939
depends_on:
4040
- db
41-
ports:
42-
- "${DJANGO_API_PORT}:8000"
4341
restart: always
4442

4543
celery-worker:
@@ -84,7 +82,7 @@ services:
8482
nginx:
8583
build: ./nginx
8684
ports:
87-
- "${DJANGO_ADMIN_PORT}:80"
85+
- "${DJANGO_ADMIN_PORT}:8000"
8886
depends_on:
8987
- app
9088
restart: always

Diff for: nginx/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ FROM nginx:1.21-alpine
44

55
RUN rm /etc/nginx/conf.d/default.conf
66
COPY nginx.conf /etc/nginx/conf.d
7-
COPY --from=Base /app/static /www/FasterRunner/static
7+
COPY --from=Base /app/static_root /www/FasterRunner/static

Diff for: nginx/nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ upstream django {
22
server app:8000;
33
}
44
server {
5-
listen 80;
5+
listen 8000;
66
# server_name 127.0.0.1;
77
charset utf-8;
88

Diff for: requirements.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ pydantic==1.9.0
6767
gunicorn
6868
sentry-sdk~=1.5.8
6969
croniter~=1.3.5 # 计算下一次crontab
70-
django-log-request-id~=2.0.0
70+
django-log-request-id~=2.0.0
71+
72+
django-htmlmin==0.11.0
73+
django-compressor==2.3 # 压缩静态文件

Diff for: static/extent.js

+505
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: static_root/.gitkeep

Whitespace-only changes.

Diff for: templates/report_template.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% load static %}
2+
3+
{% load compress %}
14
<!DOCTYPE html>
25
<html>
36

@@ -8474,8 +8477,9 @@ <h5 class='category-name'></h5>
84748477

84758478
</script>
84768479

8477-
<script src='http://extentreports.com/resx/dist/js/extent.js' type='text/javascript'></script>
8478-
8480+
{% compress js %}
8481+
<script src="{% static 'extent.js' %}" type='text/javascript'></script>
8482+
{% endcompress js %}
84798483

84808484
<script type='text/javascript'>
84818485
$(window).off("keydown");

0 commit comments

Comments
 (0)