zipusyan commited on
Commit
db82a5e
·
verified ·
1 Parent(s): 4d0f347

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +56 -2
  2. dmtask.sh +13 -0
  3. entrypoint.sh +67 -0
  4. nginx.conf +24 -0
  5. supervisord.conf +47 -0
Dockerfile CHANGED
@@ -1,2 +1,56 @@
1
- FROM netcccyun/dnsmgr
2
- EXPOSE 8081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM alpine:3.19
2
+
3
+ # Install all dependencies
4
+ RUN apk add --no-cache \
5
+ mariadb mariadb-client \
6
+ nginx \
7
+ php82 php82-fpm \
8
+ php82-pdo php82-pdo_mysql php82-mysqli \
9
+ php82-mbstring php82-curl php82-openssl php82-json \
10
+ php82-tokenizer php82-xml php82-ctype php82-bcmath \
11
+ php82-fileinfo php82-gd php82-zip php82-phar \
12
+ php82-session php82-dom php82-simplexml php82-xmlwriter \
13
+ php82-iconv php82-posix php82-pcntl \
14
+ supervisor \
15
+ curl unzip \
16
+ && ln -sf /usr/bin/php82 /usr/bin/php
17
+
18
+ # Download dnsmgr release
19
+ RUN curl -fSL -o /tmp/dnsmgr.zip https://github.com/netcccyun/dnsmgr/releases/download/2.18/dnsmgr_2.18.zip \
20
+ && unzip -q /tmp/dnsmgr.zip -d /tmp/dnsmgr \
21
+ && mkdir -p /app/www \
22
+ && cp -r /tmp/dnsmgr/* /app/www/ \
23
+ && cp -r /tmp/dnsmgr/.??* /app/www/ \
24
+ && rm -rf /tmp/dnsmgr.zip /tmp/dnsmgr
25
+
26
+ # Configure nginx
27
+ COPY nginx.conf /etc/nginx/http.d/default.conf
28
+
29
+ # Configure php-fpm
30
+ RUN sed -i 's/;daemonize\s*=\s*yes/daemonize = no/' /etc/php82/php-fpm.conf \
31
+ && sed -i 's/listen\s*=\s*127.0.0.1:9000/listen = \/run\/php\/php8.2-fpm.sock/' /etc/php82/php-fpm.d/www.conf \
32
+ && sed -i 's/;listen.owner\s*=\s*nobody/listen.owner = nginx/' /etc/php82/php-fpm.d/www.conf \
33
+ && sed -i 's/;listen.group\s*=\s*nobody/listen.group = nginx/' /etc/php82/php-fpm.d/www.conf \
34
+ && mkdir -p /run/php
35
+
36
+ # Configure supervisord
37
+ COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
38
+
39
+ # Copy entrypoint script
40
+ COPY entrypoint.sh /entrypoint.sh
41
+ RUN chmod +x /entrypoint.sh
42
+
43
+ # Copy dmtask wrapper
44
+ COPY dmtask.sh /app/www/dmtask.sh
45
+ RUN chmod +x /app/www/dmtask.sh
46
+
47
+ # Create required directories
48
+ RUN mkdir -p /run/nginx /run/mysqld /var/lib/mysql /var/log/mariadb /var/log/supervisor \
49
+ && chown -R mysql:mysql /var/lib/mysql /var/log/mariadb /run/mysqld \
50
+ && chown -R nginx:nginx /app/www \
51
+ && chown -R nginx:nginx /run/php
52
+
53
+ EXPOSE 8081
54
+
55
+ ENTRYPOINT ["/entrypoint.sh"]
56
+ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
dmtask.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ if [ ! -f /app/www/.env ]; then
3
+ sleep 60
4
+ exit 0
5
+ fi
6
+
7
+ mysql -u dnsmgr -p123456 dnsmgr -e "SELECT 1 FROM dnsmgr_config LIMIT 1" >/dev/null 2>&1
8
+ if [ $? -ne 0 ]; then
9
+ sleep 10
10
+ exit 1
11
+ fi
12
+
13
+ exec /usr/bin/php /app/www/think dmtask
entrypoint.sh ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ DB_ROOT_PASSWORD="123456"
5
+ DB_NAME="dnsmgr"
6
+ DB_USER="dnsmgr"
7
+ DB_PASSWORD="123456"
8
+ DB_PORT=3306
9
+ DB_PREFIX="dnsmgr_"
10
+ INIT_FLAG="/var/lib/mysql/.initialized"
11
+
12
+ if [ ! -f "$INIT_FLAG" ]; then
13
+ echo "=== Initializing MariaDB ==="
14
+
15
+ mysql_install_db --datadir=/var/lib/mysql --user=mysql >/dev/null 2>&1
16
+
17
+ mysqld --datadir=/var/lib/mysql --user=mysql --skip-networking &
18
+ MYSQL_PID=$!
19
+
20
+ for i in $(seq 1 30); do
21
+ if mysql -u root --socket=/run/mysqld/mysqld.sock -e "SELECT 1" >/dev/null 2>&1; then
22
+ break
23
+ fi
24
+ sleep 1
25
+ done
26
+
27
+ mysql -u root --socket=/run/mysqld/mysqld.sock <<EOSQL
28
+ FLUSH PRIVILEGES;
29
+ ALTER USER 'root'@'localhost' IDENTIFIED BY '${DB_ROOT_PASSWORD}';
30
+ CREATE DATABASE IF NOT EXISTS \`${DB_NAME}\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
31
+ CREATE USER IF NOT EXISTS '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASSWORD}';
32
+ GRANT ALL PRIVILEGES ON \`${DB_NAME}\`.* TO '${DB_USER}'@'localhost';
33
+ FLUSH PRIVILEGES;
34
+ EOSQL
35
+
36
+ kill $MYSQL_PID 2>/dev/null
37
+ wait $MYSQL_PID 2>/dev/null || true
38
+
39
+ touch "$INIT_FLAG"
40
+ echo "=== MariaDB initialized ==="
41
+ fi
42
+
43
+ if [ ! -f /app/www/.env ]; then
44
+ cat > /app/www/.env <<EOF
45
+ APP_DEBUG = false
46
+
47
+ [APP]
48
+ DEFAULT_TIMEZONE = Asia/Shanghai
49
+
50
+ [DATABASE]
51
+ TYPE = mysql
52
+ HOSTNAME = 127.0.0.1
53
+ DATABASE = ${DB_NAME}
54
+ USERNAME = ${DB_USER}
55
+ PASSWORD = ${DB_PASSWORD}
56
+ HOSTPORT = ${DB_PORT}
57
+ CHARSET = utf8mb4
58
+ PREFIX = ${DB_PREFIX}
59
+ DEBUG = false
60
+
61
+ [LANG]
62
+ default_lang = zh-cn
63
+ EOF
64
+ echo "=== .env written ==="
65
+ fi
66
+
67
+ exec "$@"
nginx.conf ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ server {
2
+ listen 8081;
3
+ server_name _;
4
+ root /app/www/public;
5
+ index index.php index.html;
6
+
7
+ access_log /dev/stdout;
8
+ error_log /dev/stderr;
9
+
10
+ location / {
11
+ try_files $uri $uri/ /index.php?$query_string;
12
+ }
13
+
14
+ location ~ \.php$ {
15
+ fastcgi_pass unix:/run/php/php8.2-fpm.sock;
16
+ fastcgi_index index.php;
17
+ fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
18
+ include fastcgi_params;
19
+ }
20
+
21
+ location ~ /\.(ht|env|git) {
22
+ deny all;
23
+ }
24
+ }
supervisord.conf ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+ logfile=/dev/stdout
4
+ logfile_maxbytes=0
5
+ pidfile=/run/supervisord.pid
6
+
7
+ [program:mariadb]
8
+ command=/usr/bin/mysqld --datadir=/var/lib/mysql --user=mysql
9
+ priority=10
10
+ autostart=true
11
+ autorestart=true
12
+ stdout_logfile=/dev/stdout
13
+ stdout_logfile_maxbytes=0
14
+ stderr_logfile=/dev/stderr
15
+ stderr_logfile_maxbytes=0
16
+
17
+ [program:php-fpm]
18
+ command=/usr/sbin/php-fpm82 --nodaemonize --fpm-config /etc/php82/php-fpm.conf
19
+ priority=20
20
+ autostart=true
21
+ autorestart=true
22
+ stdout_logfile=/dev/stdout
23
+ stdout_logfile_maxbytes=0
24
+ stderr_logfile=/dev/stderr
25
+ stderr_logfile_maxbytes=0
26
+
27
+ [program:nginx]
28
+ command=/usr/sbin/nginx -g "daemon off;"
29
+ priority=30
30
+ autostart=true
31
+ autorestart=true
32
+ stdout_logfile=/dev/stdout
33
+ stdout_logfile_maxbytes=0
34
+ stderr_logfile=/dev/stderr
35
+ stderr_logfile_maxbytes=0
36
+
37
+ [program:dmtask]
38
+ command=/bin/sh /app/www/dmtask.sh
39
+ priority=40
40
+ autostart=true
41
+ autorestart=true
42
+ startsecs=5
43
+ startretries=3
44
+ stdout_logfile=/dev/stdout
45
+ stdout_logfile_maxbytes=0
46
+ stderr_logfile=/dev/stderr
47
+ stderr_logfile_maxbytes=0