CaiWuXiTong/deploy/Dockerfile
renshen 960d418c8e 发布构建支持指定 Composer 下载源
国内网络访问 GitHub 受限时,composer install 会因 GitHub dist 拉取失败而中断
(api.github.com / codeload.github.com SSL_ERROR_SYSCALL)。

- deploy/Dockerfile 新增可选构建参数 COMPOSER_REPO_PACKAGIST,留空仍用官方源
- macOS 发布脚本默认传腾讯云镜像,可用 CAIWU_COMPOSER_REPO_PACKAGIST 覆盖
2026-09-30 14:07:55 +08:00

133 lines
4.2 KiB
Docker
Raw Permalink 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.

FROM php:8.3-apache-bookworm@sha256:fa8852a2e01747ffe8c8768bfd6bbc2f296f974aa0de90ee157a66664996d263 AS php-base
RUN apt-get -o Acquire::Retries=3 update \
&& apt-get -o Acquire::Retries=3 install -y --no-install-recommends \
curl \
libcurl4-openssl-dev \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libonig-dev \
libpng-dev \
libxml2-dev \
libzip-dev \
freetds-bin \
freetds-dev \
tdsodbc \
unixodbc-dev \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
&& docker-php-ext-install -j2 \
bcmath \
curl \
dom \
exif \
gd \
intl \
mbstring \
pdo_dblib \
pdo_odbc \
pdo_mysql \
simplexml \
xml \
zip \
&& a2enmod expires headers rewrite \
&& rm -rf /var/lib/apt/lists/*
FROM m.daocloud.io/docker.io/library/composer:2.8@sha256:5248900ab8b5f7f880c2d62180e40960cd87f60149ec9a1abfd62ac72a02577c AS composer-bin
FROM php-base AS vendor
COPY --from=composer-bin /usr/bin/composer /usr/local/bin/composer
WORKDIR /build
COPY composer.json composer.lock ./
## 可选:Composer 下载源(留空使用官方源)。
## 国内网络访问 GitHub 受限时,发布脚本会传入镜像源,例如 https://mirrors.cloud.tencent.com/composer/。
ARG COMPOSER_REPO_PACKAGIST=""
RUN --mount=type=cache,target=/tmp/composer-cache \
set -eu; \
if [ -n "${COMPOSER_REPO_PACKAGIST:-}" ]; then \
export COMPOSER_REPO_PACKAGIST; \
else \
unset COMPOSER_REPO_PACKAGIST; \
fi; \
attempt=1; \
while true; do \
if COMPOSER_CACHE_DIR=/tmp/composer-cache \
COMPOSER_MAX_PARALLEL_HTTP=4 \
composer install \
--prefer-dist \
--no-dev \
--no-interaction \
--no-progress \
--no-scripts \
--optimize-autoloader; then \
break; \
fi; \
if [ "$attempt" -ge 3 ]; then \
exit 1; \
fi; \
attempt=$((attempt + 1)); \
echo "Composer install failed; retrying ($attempt/3)." >&2; \
sleep 3; \
done
FROM php-base AS runtime
# Keep the existing PHP/Composer cache layers when adding PostgreSQL support.
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/*
ARG VCS_REF=unknown
ARG BUILD_DATE=unknown
ARG APP_VERSION=3.1.15
LABEL com.caiwu.project="CaiWuXiTong" \
org.opencontainers.image.revision="$VCS_REF" \
org.opencontainers.image.created="$BUILD_DATE"
ENV CAIWU_APP_VERSION="$APP_VERSION" \
CAIWU_BUILD_COMMIT="$VCS_REF" \
CAIWU_BUILD_TIME="$BUILD_DATE"
WORKDIR /var/www/html
COPY --from=vendor /build/vendor /var/www/html/vendor
COPY --from=frontend /js /var/www/html/public/js
COPY --from=frontend /css/app.css /var/www/html/public/css/app.css
COPY --from=frontend /mix-manifest.json /var/www/html/public/mix-manifest.json
COPY deploy/apache-vhost.conf /etc/apache2/sites-available/000-default.conf
COPY deploy/freetds.conf /etc/freetds/freetds.conf
COPY deploy/php.ini /usr/local/etc/php/conf.d/caiwu.ini
COPY deploy/entrypoint.sh /usr/local/bin/caiwu-entrypoint
COPY . /var/www/html
COPY --from=frontend /vendor /var/www/html/public/vendor
RUN test -f public/js/auth/common.min.js \
&& test -f public/css/app.css \
&& test -f public/mix-manifest.json \
&& test -f public/vendor/apexcharts/apexcharts.min.js \
&& test -f public/vendor/js-cookie/js.cookie.js \
&& test -f public/vendor/quicksand/css/quicksand.css \
&& chmod +x /usr/local/bin/caiwu-entrypoint \
&& 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
ENTRYPOINT ["caiwu-entrypoint"]
CMD ["apache2-foreground"]