CatPtain commited on
Commit
ede938f
·
verified ·
1 Parent(s): a7fc3c2

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +124 -71
Dockerfile CHANGED
@@ -1,74 +1,127 @@
1
- # Hugging Face Spaces WordPress Dockerfile
2
- # 适配单容器部署,使用SQLite数据库,包含自动清理功能
3
-
4
- FROM wordpress:6.4-apache
5
-
6
- # 设置环境变量
7
- ENV DEBIAN_FRONTEND=noninteractive
8
- ENV WORDPRESS_DB_HOST=localhost
9
- ENV WORDPRESS_DB_NAME=wordpress
10
- ENV WORDPRESS_DB_USER=wordpress
11
- ENV WORDPRESS_DB_PASSWORD=wordpress
12
- ENV PYTHONUNBUFFERED=1
13
-
14
- # 安装必要的包和SQLite开发库
15
- RUN apt-get update && apt-get install -y \
16
- sqlite3 \
17
- libsqlite3-dev \
18
- cron \
19
- wget \
20
- unzip \
21
- python3 \
22
- python3-pip \
23
- curl \
24
- && rm -rf /var/lib/apt/lists/*
25
-
26
- # 启用PHP SQLite扩展
27
- RUN docker-php-ext-install pdo_sqlite \
28
- && docker-php-ext-enable pdo_sqlite
29
-
30
- # 下载并安装SQLite Integration插件
31
- RUN cd /tmp && \
32
- wget https://downloads.wordpress.org/plugin/sqlite-database-integration.2.1.5.zip && \
33
- unzip sqlite-database-integration.2.1.5.zip && \
34
- mv sqlite-database-integration /usr/src/wordpress/wp-content/plugins/ && \
35
- rm sqlite-database-integration.2.1.5.zip
36
-
37
- # 创建必要的目录
38
- RUN mkdir -p /var/www/html/wp-content/database \
39
- && mkdir -p /var/log/wordpress \
40
- && mkdir -p /scripts
41
-
42
- # 复制Python应用文件
43
- COPY app.py /app/
44
- COPY requirements.txt /app/
45
-
46
- # 安装Python依赖
47
- RUN pip3 install --no-cache-dir -r /app/requirements.txt
48
-
49
- # 复制自定义wp-config.php
50
- COPY wp-config.php /usr/src/wordpress/
51
-
52
- # 复制监控清理脚本
53
- COPY monitor-cleanup.sh /scripts/
54
- RUN chmod +x /scripts/monitor-cleanup.sh
55
-
56
- # 复制启动脚本
57
- COPY start-services.sh /scripts/
58
- RUN chmod +x /scripts/start-services.sh
59
-
60
- # 设置cron任务 - 每天凌晨2点执行清理
61
- RUN echo "0 2 * * * /scripts/monitor-cleanup.sh >> /var/log/wordpress/cleanup.log 2>&1" | crontab -
62
-
63
- # 暴露端口7860 (Hugging Face Spaces标准端口)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  EXPOSE 7860
65
 
66
- # 修改Apache配置以使用端口7860
67
- RUN sed -i 's/Listen 80/Listen 7860/' /etc/apache2/ports.conf && \
68
- sed -i 's/:80>/:7860>/' /etc/apache2/sites-available/000-default.conf
69
 
70
- # 设置工作目录
71
- WORKDIR /var/www/html
72
-
73
- # 启动命令
74
- CMD ["/scripts/start-services.sh"]
 
1
+ # Dockerfile optimized for Hugging Face Spaces deployment
2
+ # Based on WordPress 6.8.1 with PHP 8.3 Apache
3
+
4
+ FROM php:8.3-apache
5
+
6
+ # Set environment variables for HF Spaces
7
+ ENV APACHE_DOCUMENT_ROOT=/var/www/html
8
+ ENV APACHE_RUN_USER=www-data
9
+ ENV APACHE_RUN_GROUP=www-data
10
+
11
+ # Install system dependencies
12
+ RUN set -eux; \
13
+ apt-get update; \
14
+ apt-get install -y --no-install-recommends \
15
+ ghostscript \
16
+ libfreetype6-dev \
17
+ libicu-dev \
18
+ libjpeg-dev \
19
+ libpng-dev \
20
+ libwebp-dev \
21
+ libzip-dev \
22
+ libsqlite3-dev \
23
+ sqlite3 \
24
+ wget \
25
+ unzip \
26
+ ; \
27
+ rm -rf /var/lib/apt/lists/*
28
+
29
+ # Configure and install PHP extensions
30
+ RUN set -ex; \
31
+ docker-php-ext-configure gd \
32
+ --with-freetype \
33
+ --with-jpeg \
34
+ --with-webp \
35
+ ; \
36
+ docker-php-ext-install -j "$(nproc)" \
37
+ bcmath \
38
+ exif \
39
+ gd \
40
+ intl \
41
+ mysqli \
42
+ pdo \
43
+ pdo_sqlite \
44
+ zip \
45
+ ;
46
+
47
+ # Configure PHP settings
48
+ RUN { \
49
+ echo 'opcache.memory_consumption=128'; \
50
+ echo 'opcache.interned_strings_buffer=8'; \
51
+ echo 'opcache.max_accelerated_files=4000'; \
52
+ echo 'opcache.revalidate_freq=2'; \
53
+ } > /usr/local/etc/php/conf.d/opcache-recommended.ini
54
+
55
+ RUN { \
56
+ echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE'; \
57
+ echo 'display_errors = Off'; \
58
+ echo 'log_errors = On'; \
59
+ echo 'error_log = /dev/stderr'; \
60
+ echo 'memory_limit = 256M'; \
61
+ echo 'upload_max_filesize = 32M'; \
62
+ echo 'post_max_size = 32M'; \
63
+ } > /usr/local/etc/php/conf.d/wordpress.ini
64
+
65
+ # Configure Apache for HF Spaces
66
+ RUN set -eux; \
67
+ a2enmod rewrite expires headers; \
68
+ # Configure Apache to listen on port 7860 (HF Spaces requirement)
69
+ sed -i 's/Listen 80/Listen 7860/' /etc/apache2/ports.conf; \
70
+ sed -i 's/:80>/:7860>/' /etc/apache2/sites-available/000-default.conf; \
71
+ # Set ServerName to avoid warnings
72
+ echo 'ServerName localhost' >> /etc/apache2/apache2.conf
73
+
74
+ # Download and install WordPress
75
+ RUN set -eux; \
76
+ version='6.8.1'; \
77
+ sha1='52d5f05c96a9155f78ed84700264307e5dea14b4'; \
78
+ curl -o wordpress.tar.gz -fL "https://wordpress.org/wordpress-$version.tar.gz"; \
79
+ echo "$sha1 *wordpress.tar.gz" | sha1sum -c -; \
80
+ tar -xzf wordpress.tar.gz -C /usr/src/; \
81
+ rm wordpress.tar.gz; \
82
+ cp -a /usr/src/wordpress/. /var/www/html/; \
83
+ chown -R www-data:www-data /var/www/html
84
+
85
+ # Install SQLite integration plugin for WordPress
86
+ RUN set -eux; \
87
+ wget -O sqlite-plugin.zip "https://downloads.wordpress.org/plugin/sqlite-database-integration.2.1.15.zip"; \
88
+ unzip sqlite-plugin.zip -d /var/www/html/wp-content/plugins/; \
89
+ rm sqlite-plugin.zip; \
90
+ chown -R www-data:www-data /var/www/html/wp-content/plugins/sqlite-database-integration
91
+
92
+ # Create WordPress configuration for SQLite
93
+ COPY wp-config-hf.php /var/www/html/wp-config.php
94
+ COPY db.php /var/www/html/wp-content/db.php
95
+
96
+ # Create .htaccess for pretty permalinks
97
+ RUN { \
98
+ echo '# BEGIN WordPress'; \
99
+ echo 'RewriteEngine On'; \
100
+ echo 'RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]'; \
101
+ echo 'RewriteBase /'; \
102
+ echo 'RewriteRule ^index\.php$ - [L]'; \
103
+ echo 'RewriteCond %{REQUEST_FILENAME} !-f'; \
104
+ echo 'RewriteCond %{REQUEST_FILENAME} !-d'; \
105
+ echo 'RewriteRule . /index.php [L]'; \
106
+ echo '# END WordPress'; \
107
+ } > /var/www/html/.htaccess
108
+
109
+ # Set proper permissions
110
+ RUN chown -R www-data:www-data /var/www/html && \
111
+ chmod -R 755 /var/www/html && \
112
+ chmod 644 /var/www/html/.htaccess
113
+
114
+ # Create SQLite database directory
115
+ RUN mkdir -p /var/www/html/wp-content/database && \
116
+ chown -R www-data:www-data /var/www/html/wp-content/database && \
117
+ chmod 755 /var/www/html/wp-content/database
118
+
119
+ # Expose port 7860 for Hugging Face Spaces
120
  EXPOSE 7860
121
 
122
+ # Copy startup script
123
+ COPY start-hf.sh /usr/local/bin/start-hf.sh
124
+ RUN chmod +x /usr/local/bin/start-hf.sh
125
 
126
+ # Start Apache
127
+ CMD ["/usr/local/bin/start-hf.sh"]