This commit is contained in:
2026-05-18 16:10:05 +08:00
parent 05ac848293
commit 13bacc6491
4 changed files with 10995 additions and 38 deletions
+7
View File
@@ -0,0 +1,7 @@
**
!app/
!bin/
!config/
!migrations/
!composer.*
!entrypoint.sh
+27 -38
View File
@@ -1,54 +1,43 @@
# Default Dockerfile
#
# @link https://www.hyperf.io
# @document https://hyperf.wiki
# @contact group@hyperf.io
# @license https://github.com/hyperf/hyperf/blob/master/LICENSE
FROM docker.io/hyperf/hyperf:8.3-alpine-v3.19-swoole
FROM hyperf/hyperf:8.3-alpine-v3.19-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"
LABEL org.opencontainers.image.title="datahub-backend" \
org.opencontainers.image.vendor="WPIC" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.source="https://192.168.30.181:3000/wpic-dev/datahub"
##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone
ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
ARG TIMEZONE=Asia/Shanghai
ENV TIMEZONE=${TIMEZONE} \
APP_ENV=prod \
SCAN_CACHEABLE=(true)
# update
RUN set -ex \
# show php version and extensions
&& php -v \
&& php -m \
&& php --ri swoole \
# ---------- some config ----------
&& cd /etc/php* \
# - config PHP
&& { \
RUN set -eux; \
php -v; php -m; php --ri swoole; \
cd /etc/php*; \
{ \
echo "upload_max_filesize=128M"; \
echo "post_max_size=128M"; \
echo "memory_limit=1G"; \
echo "date.timezone=${TIMEZONE}"; \
} | tee conf.d/99_overrides.ini \
# - config timezone
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
&& echo "${TIMEZONE}" > /etc/timezone \
# ---------- clear works ----------
&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
} | tee conf.d/99_overrides.ini; \
ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime; \
echo "${TIMEZONE}" > /etc/timezone; \
rm -rf /var/cache/apk/* /tmp/* /usr/share/man
WORKDIR /opt/www
# Composer Cache
# COPY ./composer.* /opt/www/
# RUN composer install --no-dev --no-scripts
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist --no-interaction
COPY . /opt/www
RUN composer install --no-dev -o && php bin/hyperf.php
COPY . .
RUN composer dump-autoload --optimize --classmap-authoritative --no-dev
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 9501
ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD wget -qO- http://127.0.0.1:9501/health || exit 1
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["php", "/opt/www/bin/hyperf.php", "start"]
+10920
View File
File diff suppressed because it is too large Load Diff
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
# Datahub backend container entrypoint.
# Flow: wait_tcp pg/mq -> migrate --force -> app:install -> exec swoole.
set -eu
wait_tcp() {
host="$1"
port="$2"
label="$3"
timeout="${4:-90}"
echo "[entrypoint] waiting for ${label} @ ${host}:${port} (up to ${timeout}s)"
i=0
while [ "$i" -lt "$timeout" ]; do
if php -r "exit(@fsockopen('${host}', ${port}, \$e, \$s, 1) ? 0 : 1);" 2>/dev/null; then
echo "[entrypoint] ${label} reachable"
return 0
fi
i=$((i + 1))
sleep 1
done
echo "[entrypoint] ${label} @ ${host}:${port} unreachable after ${timeout}s" >&2
return 1
}
DB_HOST="${DB_HOST:-host.containers.internal}"
DB_PORT="${DB_PORT:-5432}"
AMQP_HOST="${AMQP_HOST:-host.containers.internal}"
AMQP_PORT="${AMQP_PORT:-5672}"
WAIT_TIMEOUT="${ENTRYPOINT_WAIT_TIMEOUT:-90}"
wait_tcp "${DB_HOST}" "${DB_PORT}" "postgres" "${WAIT_TIMEOUT}"
wait_tcp "${AMQP_HOST}" "${AMQP_PORT}" "rabbitmq" "${WAIT_TIMEOUT}"
echo "[entrypoint] running migrate --force"
php /opt/www/bin/hyperf.php migrate --force
echo "[entrypoint] running app:install"
php /opt/www/bin/hyperf.php app:install
echo "[entrypoint] handing off to: $*"
exec "$@"