CaiWuXiTong/deploy/Dockerfile.local

135 lines
4.8 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# syntax=docker/dockerfile:1.7
# 本地部署用 Dockerfile
# 基于 deploy/Dockerfile,额外安装 composer 依赖与前端构建产物
# 由 docker-compose.local.yml 使用
FROM php:8.3-apache-bookworm
# ---------------- 系统依赖 + PHP 扩展 ----------------
ENV DEBIAN_FRONTEND=noninteractive
# 切换到清华 Debian 镜像(国内访问 deb.debian.org 不稳)
RUN sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null \
|| sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list 2>/dev/null \
|| true
# 强制非交互式 dpkg 配置(避免 media-types 等包 conffile 提示卡住)
RUN echo 'Dpkg::Options {"--force-confnew"; "--force-confdef";};' > /etc/apt/apt.conf.d/99force-conf \
&& echo 'APT::Get::Assume-Yes "true";' >> /etc/apt/apt.conf.d/99force-conf
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
libcurl4-openssl-dev \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libonig-dev \
libpng-dev \
libxml2-dev \
libzip-dev \
freetds-bin \
tdsodbc \
unixodbc-dev \
unzip \
zip \
git \
python3 \
make \
g++ \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
&& docker-php-ext-install -j"$(nproc)" \
bcmath \
curl \
dom \
exif \
gd \
intl \
mbstring \
pdo_odbc \
pdo_mysql \
simplexml \
xml \
zip \
&& a2enmod expires headers rewrite \
&& rm -rf /var/lib/apt/lists/*
# ---------------- Composer ----------------
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# ---------------- Node.js (LTS) ----------------
COPY --from=node:20-bookworm-slim /usr/local/bin/node /usr/local/bin/node
COPY --from=node:20-bookworm-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
WORKDIR /var/www/html
# ---------------- 安装依赖 ----------------
# 锁文件先于源码复制,普通 PHP/Blade 改动不会让 Composer 和 npm 重新下载。
COPY composer.json composer.lock ./
RUN --mount=type=cache,target=/tmp/composer-cache \
COMPOSER_CACHE_DIR=/tmp/composer-cache composer install --prefer-dist \
--no-interaction \
--no-scripts \
--no-progress \
--no-ansi
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --no-audit --no-fund --legacy-peer-deps
# ---------------- 复制源码 ----------------
RUN apt-get -o Acquire::Retries=3 update \
&& apt-get -o Acquire::Retries=3 install -y --no-install-recommends libpq-dev \
&& docker-php-ext-install -j2 pdo_pgsql \
&& rm -rf /var/lib/apt/lists/*
COPY . /var/www/html
COPY deploy/apache-vhost.conf /etc/apache2/sites-available/000-default.conf
COPY deploy/php.ini /usr/local/etc/php/conf.d/jiangling.ini
COPY deploy/entrypoint.sh /usr/local/bin/jiangling-entrypoint
COPY deploy/local-healthcheck.sh /usr/local/bin/jiangling-healthcheck
RUN composer dump-autoload --no-scripts --optimize
# ---------------- 构建前端资源 ----------------
# 提升 node 堆内存上限;dev 模式无压缩,避免 mix/webpack 生产构建 OOM
ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run dev \
&& mkdir -p public/vendor/apexcharts public/vendor/js-cookie \
&& cp node_modules/apexcharts/dist/apexcharts.min.js \
public/vendor/apexcharts/apexcharts.min.js \
&& cp node_modules/js-cookie/dist/js.cookie.min.js \
public/vendor/js-cookie/js.cookie.js \
&& test -s public/js/manifest.js \
&& test -s public/js/vendor.js \
&& test -s public/css/app.css \
&& test -s public/mix-manifest.json \
&& test -s public/vendor/apexcharts/apexcharts.min.js \
&& test -s public/vendor/js-cookie/js.cookie.js
# ---------------- 目录与权限 ----------------
RUN chmod +x /usr/local/bin/jiangling-entrypoint /usr/local/bin/jiangling-healthcheck \
&& mkdir -p \
storage/app/public \
storage/app/temp \
storage/app/uploads \
storage/framework/cache/data \
storage/framework/sessions \
storage/framework/views \
storage/logs \
bootstrap/cache \
&& chown -R www-data:www-data storage bootstrap/cache public
ARG LOCAL_BUILD_FINGERPRINT=unknown
LABEL com.caiwu.project="CaiWuXiTong" \
com.caiwu.local-build-fingerprint="$LOCAL_BUILD_FINGERPRINT"
ENTRYPOINT ["jiangling-entrypoint"]
CMD ["apache2-foreground"]