Skip to content

Commit 6a6812f

Browse files
houaiaiclaude
andcommitted
优化镜像构建和添加自动 Composer 依赖安装功能
1. S6 Overlay 安装优化:合并下载、解压、清理为单层,减少镜像层数 2. 添加 entrypoint.sh:自动检测并安装 Composer 依赖 3. 清理优化:添加 PECL 缓存清理 /root/.cache/pecl 4. Composer 优化:添加版本验证和 /tmp/* 清理 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8fe47ad commit 6a6812f

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

Dockerfile

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:8.4.16-cli-alpine
1+
FROM php:8.4.15-cli-alpine
22
ARG S6_OVERLAY_VERSION=3.2.1.0
33

44
LABEL Maintainer="ShaoBo Wan (Tinywan) <756684177@qq.com>" \
@@ -24,27 +24,35 @@ RUN apk add --no-cache --virtual .build-deps \
2424
&& apk del .build-deps \
2525
&& rm -rf /var/cache/apk/* /tmp/* /root/.pearrc /usr/local/include/php
2626

27-
# Add Composer (with cache cleanup)
27+
# Add Composer (with cache cleanup, no plugins/scripts)
2828
RUN curl -sS https://getcomposer.org/installer | php \
2929
&& mv composer.phar /usr/local/bin/composer \
30-
&& rm -rf /root/.composer/cache
30+
&& composer --version \
31+
&& rm -rf /root/.composer/cache /tmp/*
3132

3233
# Configure PHP
3334
COPY config/php.ini /usr/local/etc/php/conf.d/zzz_custom.ini
3435

3536
# Setup document root
3637
RUN mkdir -p /app
3738

39+
# Add entrypoint script for auto composer install
40+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
41+
RUN chmod +x /usr/local/bin/entrypoint.sh
42+
43+
# Install S6 Overlay v3 (download, extract, cleanup in one layer)
44+
RUN apk add --no-cache curl \
45+
&& curl -fsSL https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz -o /tmp/s6-overlay-noarch.tar.xz \
46+
&& tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz \
47+
&& curl -fsSL https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz -o /tmp/s6-overlay-x86_64.tar.xz \
48+
&& tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz \
49+
&& rm -f /tmp/s6-overlay-*.tar.xz \
50+
&& apk del curl
51+
3852
# Use S6 Overlay as init system with environment to override services
3953
VOLUME /app
4054
WORKDIR /app
4155
EXPOSE 8787
4256

57+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
4358
CMD ["php", "start.php","start"]
44-
45-
# Install S6 Overlay v3
46-
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
47-
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
48-
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-x86_64.tar.xz /tmp
49-
RUN tar -C / -Jxpf /tmp/s6-overlay-x86_64.tar.xz
50-
ENTRYPOINT ["/init"]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## Build
77

88
```
9-
docker build -t tinywan/docker-php-webman:8.3.4 .
9+
docker build -t tinywan/docker-php-webman:8.4.15-cli-alpine .
1010
```
1111
## Usage
1212

@@ -22,6 +22,7 @@ docker run --rm -it -p 8787:8787 -v /home/www/webman:/app tinywan/docker-php-web
2222

2323
```
2424
docker run --rm -it -p 8787:8787 -v e:/dnmp/www/webman:/app tinywan/docker-php-webman
25+
docker run --rm -it -p 8780:8787 -v e:/dnmp/www/webman/video.webman.tinywan.com:/app tinywan/docker-php-webman:8.4.15-cli-alpine
2526
```
2627

2728
Test Run

entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
4+
cd /app
5+
6+
# Auto install dependencies if vendor/autoload.php not exists
7+
if [ ! -f vendor/autoload.php ]; then
8+
echo "Composer dependencies not found, installing..."
9+
composer install --no-interaction --no-scripts --no-plugins
10+
fi
11+
12+
# Execute s6-overlay init then the command
13+
exec /init "$@"

extension/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,5 +682,5 @@ fi
682682

683683
# Cleanup build artifacts and caches
684684
echo "---------- Cleanup ----------"
685-
rm -rf /tmp/* /var/cache/apk/* /root/.pearrc /usr/local/include/php
685+
rm -rf /tmp/* /var/cache/apk/* /root/.pearrc /usr/local/include/php /root/.cache/pecl
686686
docker-php-source delete

0 commit comments

Comments
 (0)