Added dockerfile

Issue #5
Close #5
This commit is contained in:
laucyun
2022-04-20 21:30:15 +08:00
parent da7d13612c
commit 9344cb1205
6 changed files with 180 additions and 28 deletions
+20
View File
@@ -0,0 +1,20 @@
# Compose
COMPOSE_PROJECT_NAME=dnslog
COMPOSE_HTTP_TIMEOUT=3600
DOCKER_CLIENT_TIMEOUT=3600
DOCKER_SUBNET=172.16.239.0/24
# MySQL
DB_HOST=mysql
DB_PORT=3306
DB_USER=root
DB_PASSWORD=PucJ86KwPz9sfigZzlGa
DB_NAME=dnslog
# DNSLog
SECRET_KEY=GeqwBTQCvK4Yg2VneExUxtNGuLR4pQYy6xduMfPAM4oJgdqQ12
DNS_DOMAIN=eyes.sh
ADMIN_DOMAIN=eyes.sh
NS1_DOMAIN=eyes_dns1.lijiejie.com
NS2_DOMAIN=eyes_dns2.lijiejie.com
SERVER_IP=123.123.123.123
+30
View File
@@ -0,0 +1,30 @@
FROM python:3.8
ENV TZ Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD . /dnslog
RUN pip install -r /dnslog/requirements.txt
RUN chmod +x /dnslog/docker-entrypoint.sh
WORKDIR /dnslog
EXPOSE 53
ENTRYPOINT ["/dnslog/docker-entrypoint.sh"]
# Install nginx
RUN apt update -y
RUN apt-get install -y \
ca-certificates \
nginx \
gettext-base \
&& rm -rf /var/lib/apt/lists/*
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
RUN cp /dnslog/dnslog_nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+21 -13
View File
@@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#ma=s-l!2obwj%h-6uu^sbw+4%i2w79%v3^ill62k3&7tjf5dc' SECRET_KEY = os.getenv("SECRET_KEY", "#ma=s-l!2obwj%h-6uu^sbw+4%i2w79%v3^ill62k3&7tjf5dc")
DEBUG = False DEBUG = False
@@ -15,6 +15,13 @@ ALLOWED_HOSTS = ['*']
# SECURE_SSL_REDIRECT = True # SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# CSRF
CSRF_TRUSTED_ORIGINS = [
"http://localhost:8080", "http://localhost",
"http://%s" % (os.getenv("ADMIN_DOMAIN", "eyes.sh")),
"https://%s" % (os.getenv("ADMIN_DOMAIN", "eyes.sh"))
]
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
@@ -59,10 +66,10 @@ WSGI_APPLICATION = 'dnslog.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME', 'NAME': os.getenv('DB_NAME', 'mysql'),
'USER': 'DB_USER', 'USER': os.getenv('DB_USER', 'root'),
'PASSWORD': 'DB_PASSWORD', 'PASSWORD': os.getenv('DB_PASSWORD', 'root'),
'HOST': 'DB_HOST', 'HOST': os.getenv('DB_HOST', 'localhost'),
'PORT': '3306' 'PORT': '3306'
} }
} }
@@ -80,26 +87,26 @@ LANGUAGES = (
('en', _('English')), ('en', _('English')),
) )
LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),) LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'), )
STATIC_URL = '/static/' STATIC_URL = '/static/'
if DEBUG: if DEBUG:
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),) STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), )
else: else:
STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# 用于DNS记录的域名 # 用于DNS记录的域名
DNS_DOMAIN = 'eyes.sh' DNS_DOMAIN = os.getenv('DNS_DOMAIN', 'eyes.sh')
# 管理后台域名 # 管理后台域名
ADMIN_DOMAIN = ['eyes.sh', 'www.eyes.sh'] ADMIN_DOMAIN = os.getenv('ADMIN_DOMAIN', 'eyes.sh')
# NS域名 # NS域名
NS1_DOMAIN = 'eyes_dns1.lijiejie.com' NS1_DOMAIN = os.getenv('NS1_DOMAIN', 'eyes_dns1.lijiejie.com')
NS2_DOMAIN = 'eyes_dns2.lijiejie.com' NS2_DOMAIN = os.getenv('NS2_DOMAIN', 'eyes_dns1.lijiejie.com')
# 服务器外网地址 # 服务器外网地址
SERVER_IP = '123.123.123.123' SERVER_IP = os.getenv('SERVER_IP', '123.123.123.123')
if not DEBUG: if not DEBUG:
LOGGING = {} LOGGING = {}
@@ -110,7 +117,8 @@ else:
'disable_existing_loggers': True, 'disable_existing_loggers': True,
'formatters': { 'formatters': {
'verbose': { 'verbose': {
'format': "[%(asctime)s] %(levelname)s [ %(filename)s] [line %(lineno)s] %(message)s", 'format':
"[%(asctime)s] %(levelname)s [ %(filename)s] [line %(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S" 'datefmt': "%d/%b/%Y %H:%M:%S"
}, },
'simple': { 'simple': {
+8 -2
View File
@@ -1,9 +1,15 @@
server { server {
listen 80; listen 80;
server_name eyes.sh www.eyes.sh *.eyes.sh; server_name localhost $ADMIN_DOMAI;
uwsgi_pass_request_headers on; uwsgi_pass_request_headers on;
location = /favicon.ico { access_log off; log_not_found off; } if ($request_uri ~* "^/$") {
return 302 $scheme://$http_host/login;
}
location = /favicon.ico {
access_log off; log_not_found off;
}
location /static/ { location /static/ {
alias /dnslog/static/; alias /dnslog/static/;
} }
+62
View File
@@ -0,0 +1,62 @@
version: '3'
services:
mysql:
image: mariadb:10.6
container_name: mysql
restart: always
command: --character-set-server=utf8 --collation-server=utf8_general_ci
environment:
DB_USER: $DB_USER
DB_PORT: $DB_PORT
MARIADB_ROOT_PASSWORD: $DB_PASSWORD
MARIADB_DATABASE: $DB_NAME
healthcheck:
test: "mysql -h127.0.0.1 -P$$DB_PORT -u$$DB_USER -p$$MARIADB_ROOT_PASSWORD -e 'SHOW DATABASES;'"
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
- net
dnslog:
build:
context: .
dockerfile: Dockerfile
image: dnslog
container_name: dnslog
restart: always
environment:
DB_HOST: $DB_HOST
DB_PORT: $DB_PORT
DB_USER: $DB_USER
DB_PASSWORD: $DB_PASSWORD
DB_NAME: $DB_NAME
SECRET_KEY: $SECRET_KEY
DNS_DOMAIN: $DNS_DOMAIN
ADMIN_DOMAIN: $ADMIN_DOMAIN
NS1_DOMAIN: $NS1_DOMAIN
NS2_DOMAIN: $NS2_DOMAIN
SERVER_IP: $SERVER_IP
depends_on:
- mysql
ports:
- 53:53/tcp
- 53:53/udp
- 8080:80/tcp
healthcheck:
test: "wget -nv -t1 --spider http://localhost/login --no-check-certificate > /dev/null"
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
- net
networks:
net:
driver: bridge
ipam:
driver: default
config:
- subnet: $DOCKER_SUBNET
+26
View File
@@ -0,0 +1,26 @@
#! /usr/bin/env sh
set -e
python /dnslog/manage.py makemigrations logview
python /dnslog/manage.py migrate
python /dnslog/manage.py collectstatic --noinput
# Run nginx
nginx_count=`ps aux|grep nginx|grep -v grep|wc -l`
if [ $nginx_count -eq 0 ]; then
nginx -g 'daemon off;' &
fi
# Run zoneresolver.py
zoneresolver_count=`ps aux|grep zoneresolver|grep -v grep|wc -l`
if [ $zoneresolver_count -eq 0 ]; then
python /dnslog/zoneresolver.py &
fi
# Run gunicorn
gunicorn_count=`ps aux|grep gunicorn|grep -v grep|wc -l`
if [ $gunicorn_count -eq 0 ]; then
gunicorn --workers 5 --bind 0.0.0.0:8000 dnslog.wsgi:application --daemon
fi
exec "$@"