Skip to content

Commit

Permalink
Merge pull request #25
Browse files Browse the repository at this point in the history
compress report js & change docker-compose port
  • Loading branch information
lihuacai168 authored Nov 18, 2022
2 parents d14572b + 88008f1 commit a4ddec0
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 41 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# $ cat ~/.env

WEB_PORT=80
DJANGO_ADMIN_PORT=8001
DJANGO_API_PORT=8000
DJANGO_ADMIN_PORT=8000
SERVER_IP=127.0.0.1 # The host machine IP


Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tempWorkDir
mysql
.env
/venv/
/static/
/CACHE/


# web
Expand Down
75 changes: 47 additions & 28 deletions FasterRunner/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@
"django_celery_beat",
"rest_framework_swagger",
"drf_yasg",
"compressor",
]

MIDDLEWARE = [
'log_request_id.middleware.RequestIDMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.middleware.gzip.GZipMiddleware",
"htmlmin.middleware.HtmlMinifyMiddleware",
"htmlmin.middleware.MarkRequestMiddleware",
"log_request_id.middleware.RequestIDMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
Expand All @@ -70,6 +73,32 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"fastrunner.utils.middleware.VisitTimesMiddleware",
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = "/static/"

STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# Add this
"compressor.finders.CompressorFinder",
)
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
COMPRESS_ROOT = os.path.join(BASE_DIR, "static")
STATIC_ROOT = os.path.join(BASE_DIR, "static_root")
COMPRESS_ENABLED = True
COMPRESS_CSS_HASHING_METHOD = "content"
COMPRESS_FILTERS = {
"css": [
"compressor.filters.css_default.CssAbsoluteFilter",
"compressor.filters.cssmin.rCSSMinFilter",
],
"js": [
"compressor.filters.jsmin.JSMinFilter",
],
}
HTML_MINIFY = True
KEEP_COMMENTS_ON_MINIFYING = True

ROOT_URLCONF = "FasterRunner.urls"

Expand Down Expand Up @@ -123,11 +152,6 @@

USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = "/static/"


REST_FRAMEWORK = {
# 'DEFAULT_AUTHENTICATION_CLASSES': ['FasterRunner.auth.DeleteAuthenticator', 'FasterRunner.auth.Authenticator', ],
Expand Down Expand Up @@ -229,29 +253,27 @@
"disable_existing_loggers": True,
"formatters": {
"standard": {
'format': '%(levelname)-2s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s',
"format": "%(levelname)-2s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
'color': {
'()': 'colorlog.ColoredFormatter',
'format': '%(green)s%(asctime)s [%(request_id)s] %(name)s %(log_color)s%(levelname)s [pid:%(process)d] '
'[%(filename)s->%(funcName)s:%(lineno)s] %(cyan)s%(message)s',
'log_colors': {
'DEBUG': 'black',
'INFO': 'white',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'bold_red',
"color": {
"()": "colorlog.ColoredFormatter",
"format": "%(green)s%(asctime)s [%(request_id)s] %(name)s %(log_color)s%(levelname)s [pid:%(process)d] "
"[%(filename)s->%(funcName)s:%(lineno)s] %(cyan)s%(message)s",
"log_colors": {
"DEBUG": "black",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red",
},
}
# 日志格式
},
"filters": {
'request_id': {
'()': 'log_request_id.filters.RequestIDFilter'
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue', # 过滤器,只有当setting的DEBUG = True时生效
"request_id": {"()": "log_request_id.filters.RequestIDFilter"},
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue", # 过滤器,只有当setting的DEBUG = True时生效
},
},
"handlers": {
Expand All @@ -268,17 +290,14 @@
"maxBytes": 1024 * 1024 * 50,
"backupCount": 5,
"formatter": "color",
'filters': ['request_id'],

"filters": ["request_id"],
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "color",
'filters': ['request_id'],

"filters": ["request_id"],
},

},
"loggers": {
"django": {
Expand Down
2 changes: 1 addition & 1 deletion FasterRunner/settings/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# broker_url = f'amqp://{mq_user}:{mq_password}@mq:5672//'
broker_url = f'amqp://{MQ_USER}:{MQ_PASSWORD}@mq:{MQ_PORT}//'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATIC_ROOT = os.path.join(BASE_DIR, 'static')

SERVER_IP = environ.get('SERVER_IP', '')
DJANGO_API_PORT = environ.get('DJANGO_API_PORT', '8000')
Expand Down
2 changes: 1 addition & 1 deletion FasterRunner/settings/pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
# STATIC_URL = '/static/'

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

# 开发者模式中使用访问静态文
# STATICFILES_DIRS = (
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ services:
command: -c "/app/start.sh app"
depends_on:
- db
ports:
- "${DJANGO_API_PORT}:8000"
restart: always

celery-worker:
Expand Down Expand Up @@ -84,7 +82,7 @@ services:
nginx:
build: ./nginx
ports:
- "${DJANGO_ADMIN_PORT}:80"
- "${DJANGO_ADMIN_PORT}:8000"
depends_on:
- app
restart: always
Expand Down
2 changes: 1 addition & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FROM nginx:1.21-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
COPY --from=Base /app/static /www/FasterRunner/static
COPY --from=Base /app/static_root /www/FasterRunner/static
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ upstream django {
server app:8000;
}
server {
listen 80;
listen 8000;
# server_name 127.0.0.1;
charset utf-8;

Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ pydantic==1.9.0
gunicorn
sentry-sdk~=1.5.8
croniter~=1.3.5 # 计算下一次crontab
django-log-request-id~=2.0.0
django-log-request-id~=2.0.0

django-htmlmin==0.11.0
django-compressor==2.3 # 压缩静态文件
505 changes: 505 additions & 0 deletions static/extent.js

Large diffs are not rendered by default.

Empty file added static_root/.gitkeep
Empty file.
8 changes: 6 additions & 2 deletions templates/report_template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% load static %}

{% load compress %}
<!DOCTYPE html>
<html>

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

</script>

<script src='http://extentreports.com/resx/dist/js/extent.js' type='text/javascript'></script>

{% compress js %}
<script src="{% static 'extent.js' %}" type='text/javascript'></script>
{% endcompress js %}

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

0 comments on commit a4ddec0

Please sign in to comment.