CaiWuXiTong/deploy/Dockerfile

140 lines
4.6 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.

FROM php:8.3.36-apache-bookworm@sha256:cbd3b3d9011668443d54ab40ec31db56c73d91b4c8198935d639aa80d2d815c1 AS php-base
# 国内构建机访问 deb.debian.org 常被代理拦截(502),统一改用清华 Debian 镜像。
RUN set -eu; \
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.sources /etc/apt/sources.list.d/*.list; do \
[ -f "$f" ] || continue; \
sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g; s|security.debian.org|mirrors.tuna.tsinghua.edu.cn|g' "$f"; \
done
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"]