Skip to content

Commit

Permalink
Merge branch 'build_native_php' into build-windows-php
Browse files Browse the repository at this point in the history
jingjingxyk committed Jan 25, 2025
2 parents a87997c + a070bdc commit 07bf175
Showing 9 changed files with 141 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -69,6 +69,16 @@ bash setup-php-runtime.sh
# 来自 https://www.swoole.com/download
bash setup-php-runtime.sh --mirror china

# 使用swoole-cli
# shell脚本中启用别名扩展功能‌
shopt -s expand_aliases
__DIR__=$(cd "$(dirname "$0")"; pwd)
export PATH="${__DIR__}/bin/runtime:$PATH"
ln -sf ${__DIR__}/bin/runtime/swoole-cli ${__DIR__}/bin/runtime/php
alias php="php -d curl.cainfo=${__DIR__}/bin/runtime/cacert.pem -d openssl.cafile=${__DIR__}/bin/runtime/cacert.pem"
which php
php -v

```

## 快速准备运行环境
3 changes: 3 additions & 0 deletions build-release-example.sh
Original file line number Diff line number Diff line change
@@ -186,6 +186,9 @@ if [ ! -f "${__PROJECT__}/bin/runtime/php" ]; then
fi

export PATH="${__PROJECT__}/bin/runtime:$PATH"
# 交互模式下alias 扩展默认是开启的,脚本模式下默认是关闭的
# 在shell脚本中启用别名扩展功能‌
shopt -s expand_aliases
alias php="php -d curl.cainfo=${__PROJECT__}/bin/runtime/cacert.pem -d openssl.cafile=${__PROJECT__}/bin/runtime/cacert.pem"

php -v
2 changes: 1 addition & 1 deletion sapi/docker/build-export-container.sh
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ done

case "$MIRROR" in
china | openatom)
CONTAINER_BASE_IMAGE="hub.atomgit.com/library/alpine:3.18"
CONTAINER_BASE_IMAGE="docker.io/library/alpine:3.18"
;;
esac

2 changes: 1 addition & 1 deletion sapi/quickstart/linux/run-alpine-container.sh
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ while [ $# -gt 0 ]; do
MIRROR="$2"
case "$MIRROR" in
china | openatom)
IMAGE="hub.atomgit.com/library/alpine:3.18"
IMAGE="docker.io/library/alpine:3.18"
;;
esac
;;
2 changes: 1 addition & 1 deletion sapi/quickstart/linux/run-debian-container.sh
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ while [ $# -gt 0 ]; do
MIRROR="$2"
case "$MIRROR" in
china | openatom)
IMAGE="hub.atomgit.com/library/debian:12"
IMAGE="docker.io/library/debian:12"
;;
esac
;;
117 changes: 117 additions & 0 deletions sapi/scripts/build-swoole-cli-alpine-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash

set -exu
__DIR__=$(
cd "$(dirname "$0")"
pwd
)
__PROJECT__=$(
cd ${__DIR__}/../../
pwd
)

cd ${__DIR__}
cd ${__PROJECT__}

test -d var/build-swoole-cli-container/ && rm -rf var/build-swoole-cli-container/
mkdir -p var/build-swoole-cli-container/
cd ${__PROJECT__}/var/build-swoole-cli-container/

cp -f ${__PROJECT__}/setup-swoole-cli-runtime.sh .

VERSION="6.0.0.0"
bash setup-swoole-cli-runtime.sh --version v${VERSION}

cat >php.ini <<'EOF'
curl.cainfo="/usr/local/swoole-cli/etc/cacert.pem"
openssl.cafile="/usr/local/swoole-cli/etc/cacert.pem"
swoole.use_shortname=off
display_errors = On
error_reporting = E_ALL
upload_max_filesize="128M"
post_max_size="128M"
memory_limit="1G"
date.timezone="UTC"
opcache.enable=On
opcache.enable_cli=On
opcache.jit=1225
opcache.jit_buffer_size=128M
; jit 更多配置参考 https://mp.weixin.qq.com/s/Tm-6XVGQSlz0vDENLB3ylA
expose_php=Off
apc.enable_cli=1
EOF

cat >Dockerfile <<'EOF'
FROM alpine:3.20
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /usr/local/swoole-cli/etc/conf.d/
ADD ./bin/runtime/swoole-cli /usr/local/bin/
ADD ./bin/runtime/composer /usr/local/bin/
ADD ./bin/runtime/cacert.pem /usr/local/swoole-cli/etc/
ADD ./php.ini /usr/local/swoole-cli/etc/
RUN chmod a+x /usr/local/bin/swoole-cli
RUN chmod a+x /usr/local/bin/composer
RUN ln -sf /usr/local/bin/swoole-cli /usr/local/bin/php
ARG MIRROR=""
RUN test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save
RUN if [ "${MIRROR}" = "ustc" -o "${MIRROR}" = "china" ]; then { sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories ; } fi
RUN if [ "${MIRROR}" = "tuna" ]; then { sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories ; } fi
RUN apk add ca-certificates tini
RUN mkdir /work
WORKDIR /work
ENTRYPOINT ["tini", "--"]
EOF

PLATFORM=''
ARCH=$(uname -m)
case $ARCH in
'x86_64')
PLATFORM='linux/amd64'
;;
'aarch64')
PLATFORM='linux/arm64'
;;
esac

while [ $# -gt 0 ]; do
case "$1" in
--platform)
PLATFORM="$2"
;;
--*)
echo "Illegal option $1"
;;
esac
shift $(($# > 0 ? 1 : 0))
done

TIME=$(date -u '+%Y%m%dT%H%M%SZ')
ARCH=$(uname -m)

TAG="alpine-3.20-v${VERSION}-${ARCH}-${TIME}"
TAG=${VERSION}
IMAGE="docker.io/phpswoole/swoole-cli:${TAG}"

#MIRROR='china'
MIRROR=''
docker buildx build -t ${IMAGE} -f ./Dockerfile . --platform ${PLATFORM} --build-arg="MIRROR=${MIRROR}"

echo ${IMAGE}
# docker save -o "swoole-cli-image.tar" ${IMAGE}

docker run --rm --name demo ${IMAGE} swoole-cli -v
docker run --rm --name demo ${IMAGE} swoole-cli -m
docker run --rm --name demo ${IMAGE} swoole-cli --ri swoole
5 changes: 3 additions & 2 deletions sapi/src/template/make.php
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@

?>
#!/usr/bin/env bash
shopt -s expand_aliases
__PROJECT_DIR__=$(cd "$(dirname "$0")"; pwd)
CLI_BUILD_TYPE=<?= $this->getBuildType() . PHP_EOL ?>
SRC=<?= $this->phpSrcDir . PHP_EOL ?>
@@ -497,8 +498,8 @@
if [ -n "$2" ]; then
MIRROR=$2
case "$MIRROR" in
china | openatom )
CONTAINER_BASE_IMAGE="hub.atomgit.com/library/alpine:3.18"
china | openatom)
CONTAINER_BASE_IMAGE="docker.io/library/alpine:3.18"
;;
esac
fi
4 changes: 3 additions & 1 deletion setup-php-runtime.sh
Original file line number Diff line number Diff line change
@@ -156,10 +156,12 @@ cd ${__PROJECT__}/
set +x

echo " "
echo " USE PHP RUNTIME :"
echo " USE PHP RUNTIME : "
echo " "
echo " export PATH=\"${__PROJECT__}/bin/runtime:\$PATH\" "
echo " "
echo " shopt -s expand_aliases "
echo " "
echo " alias php='php -d curl.cainfo=${__PROJECT__}/bin/runtime/cacert.pem -d openssl.cafile=${__PROJECT__}/bin/runtime/cacert.pem' "
echo " OR "
echo " alias php='php -c ${__PROJECT__}/bin/runtime/php.ini' "
2 changes: 2 additions & 0 deletions setup-swoole-cli-runtime.sh
Original file line number Diff line number Diff line change
@@ -228,6 +228,8 @@ echo " USE PHP-CLI RUNTIME :"
echo " "
echo " export PATH=\"${__PROJECT__}/bin/runtime:\$PATH\" "
echo " "
echo " shopt -s expand_aliases "
echo " "
echo " alias swoole-cli='swoole-cli -d curl.cainfo=${__PROJECT__}/bin/runtime/cacert.pem -d openssl.cafile=${__PROJECT__}/bin/runtime/cacert.pem' "
echo " OR "
echo " alias swoole-cli='swoole-cli -c ${__PROJECT__}/bin/runtime/php.ini' "

0 comments on commit 07bf175

Please sign in to comment.