增加docke部署
This commit is contained in:
41
codes/agent/game-docker/docker/api/Dockerfile
Normal file
41
codes/agent/game-docker/docker/api/Dockerfile
Normal file
@@ -0,0 +1,41 @@
|
||||
FROM php:8.1-apache
|
||||
|
||||
# 安装 PHP 扩展
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libzip-dev \
|
||||
libpng-dev \
|
||||
libcurl4-openssl-dev \
|
||||
&& docker-php-ext-install pdo pdo_mysql mysqli zip gd curl \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 启用 Apache mod_rewrite
|
||||
RUN a2enmod rewrite
|
||||
|
||||
# 设置 Apache DocumentRoot
|
||||
ENV APACHE_DOCUMENT_ROOT /var/www/html
|
||||
|
||||
RUN sed -i 's|/var/www/html|${APACHE_DOCUMENT_ROOT}|g' \
|
||||
/etc/apache2/sites-available/000-default.conf \
|
||||
/etc/apache2/apache2.conf
|
||||
|
||||
# 允许 .htaccess 覆盖
|
||||
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
||||
|
||||
# 设置时区
|
||||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
|
||||
# 拷贝应用代码
|
||||
COPY api/ /var/www/html/
|
||||
COPY env_config.php /var/www/env_config.php
|
||||
# .env 由 docker-compose env_file 注入,不打包进镜像
|
||||
|
||||
# 设置权限
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
# 拷贝并设置启动入口脚本(用于替换 JS 中的硬编码域名)
|
||||
COPY docker/api/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
69
codes/agent/game-docker/docker/api/docker-entrypoint.sh
Normal file
69
codes/agent/game-docker/docker/api/docker-entrypoint.sh
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ============================================
|
||||
# API 服务启动入口脚本
|
||||
# 在 Apache 启动前替换静态 JS 文件中的硬编码域名
|
||||
# ============================================
|
||||
|
||||
echo "[entrypoint] Replacing hardcoded domains in JS files..."
|
||||
|
||||
# 默认值(与 .env.example 对应)
|
||||
SITE_API2_URL="${SITE_API2_URL:-https://api2.tscce.cn}"
|
||||
QQ_CALLBACK_URL="${QQ_CALLBACK_URL:-http://syhd.daoqijuyou77.cn}"
|
||||
|
||||
# 替换 api/source/pay/js/common.js 和 api/source/login/js/common.js 中的 g_RequestAddress
|
||||
for f in /var/www/html/source/pay/js/common.js /var/www/html/source/login/js/common.js; do
|
||||
if [ -f "$f" ]; then
|
||||
sed -i "s|var g_RequestAddress = 'https://api2.tscce.cn'|var g_RequestAddress = '${SITE_API2_URL}'|g" "$f"
|
||||
echo "[entrypoint] Updated: $f"
|
||||
fi
|
||||
done
|
||||
|
||||
# 替换 QQ 登录配置中的回调地址
|
||||
QQ_INC="/var/www/html/loginLib/qq/API/comm/inc.php"
|
||||
if [ -f "$QQ_INC" ]; then
|
||||
sed -i "s|__QQ_CALLBACK_URL__|${QQ_CALLBACK_URL}|g" "$QQ_INC"
|
||||
echo "[entrypoint] Updated: $QQ_INC"
|
||||
fi
|
||||
|
||||
# 替换 sample 目录中的硬编码域名
|
||||
SITE_API_URL="${SITE_API_URL:-https://api.tscce.cn}"
|
||||
SITE_PAY_NOTIFY_URL="${SITE_PAY_NOTIFY_URL:-http://api.daoqijuyou77.cn}"
|
||||
for f in /var/www/html/sample/onlinepay/js/common.js; do
|
||||
if [ -f "$f" ]; then
|
||||
sed -i "s|var g_RequestAddress = 'https://api.tscce.cn'|var g_RequestAddress = '${SITE_API_URL}'|g" "$f"
|
||||
echo "[entrypoint] Updated: $f"
|
||||
fi
|
||||
done
|
||||
for f in /var/www/html/sample/offlinepay/js/common.js; do
|
||||
if [ -f "$f" ]; then
|
||||
sed -i "s|var g_RequestAddress = 'https://api.daoqijuyou77.cn'|var g_RequestAddress = '${SITE_API_URL}'|g" "$f"
|
||||
echo "[entrypoint] Updated: $f"
|
||||
fi
|
||||
done
|
||||
for f in /var/www/html/sample/transfer/js/common.js /var/www/html/sample/refund/js/common.js; do
|
||||
if [ -f "$f" ]; then
|
||||
sed -i "s|var g_RequestAddress = 'https://api2.tscce.cn'|var g_RequestAddress = '${SITE_API2_URL}'|g" "$f"
|
||||
sed -i "s|var g_RequestAddress = 'https://api2.daoqijuyou77.cn'|var g_RequestAddress = '${SITE_API2_URL}'|g" "$f"
|
||||
echo "[entrypoint] Updated: $f"
|
||||
fi
|
||||
done
|
||||
|
||||
# 替换 sample PHP 文件中的硬编码域名
|
||||
SAMPLE_DIR="/var/www/html/sample"
|
||||
if [ -d "$SAMPLE_DIR" ]; then
|
||||
# onlinepay/test.php 和 onlinepay/index.php
|
||||
find "$SAMPLE_DIR" -name "*.php" -exec sed -i \
|
||||
-e "s|https://api.tscce.cn|${SITE_API_URL}|g" \
|
||||
-e "s|https://api2.tscce.cn|${SITE_API2_URL}|g" \
|
||||
-e "s|https://api2.daoqijuyou77.cn|${SITE_API2_URL}|g" \
|
||||
-e "s|https://api.daoqijuyou77.cn|${SITE_API_URL}|g" \
|
||||
{} +
|
||||
echo "[entrypoint] Updated: sample/ PHP files"
|
||||
fi
|
||||
|
||||
echo "[entrypoint] Domain replacement complete. Starting Apache..."
|
||||
|
||||
# 启动 Apache(前台运行)
|
||||
exec apache2-foreground
|
||||
Reference in New Issue
Block a user