diff --git a/.gitignore b/.gitignore index 3e7d7e33c..0b6f47933 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ composer.lock # php cs fixer cache file .php-cs-fixer.cache + +# exclude self-runtime +/bin/* +!/bin/spc +!/bin/setup-runtime diff --git a/bin/setup-runtime b/bin/setup-runtime new file mode 100755 index 000000000..54c89455f --- /dev/null +++ b/bin/setup-runtime @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# set error-quit, verbose, non-variable-quit +set -eu +# see what system used +__OS__=$(uname -s) +# see what arch used +__ARCH__=$(uname -m) +# format arch name +case $__ARCH__ in +arm64 | aarch64) __ARCH__=arm64 ;; +x86_64|x64) __ARCH__=x64 ;; +*) ;; +esac + +# format uname +case $__OS__ in +Darwin) __OS_FIXED__=macos ;; +Linux) __OS_FIXED__=linux ;; +*) echo "Current OS is not supported" && exit 1 ;; +esac + +# set project dir +__DIR__=$(cd "$(dirname "$0")" && pwd) +__PROJECT__=$(cd ${__DIR__}/../ && pwd) + +# set download dir +__PHP_RUNTIME_URL__="https://github.com/swoole/swoole-src/releases/download/v5.0.1/swoole-cli-v5.0.1-${__OS_FIXED__}-${__ARCH__}.tar.xz" +__COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar" + +# download static-php binary (currently using swoole-cli temporarily) +test -d ${__PROJECT__}/downloads || mkdir ${__PROJECT__}/downloads +# download static php binary +test -f ${__PROJECT__}/downloads/runtime.tar.xz || curl -#fSL -o ${__PROJECT__}/downloads/runtime.tar.xz "$__PHP_RUNTIME_URL__" +test -f ${__DIR__}/php || { tar -xf ${__PROJECT__}/downloads/runtime.tar.xz -C ${__DIR__}/ && mv ${__DIR__}/swoole-cli ${__DIR__}/php && rm ${__DIR__}/LICENSE ; } # (TODO: temporarily use swoole-cli as php) +chmod +x ${__DIR__}/php +# download composer +test -f ${__DIR__}/composer || curl -#fSL -o ${__DIR__}/composer "$__COMPOSER_URL__" +chmod +x ${__DIR__}/composer +# sanity check for php and composer +${__DIR__}/php -v >/dev/null || { echo "Failed to run php" && exit 1; } +${__DIR__}/php ${__DIR__}/composer --version >/dev/null || { echo "Failed to run composer" && exit 1; } + +echo "Setup runtime OK!" +echo "runtime bin path needs to add manually by command below:" +echo "" +echo " export PATH=\"${__DIR__}:\$PATH\"" +echo "" diff --git a/quickstart/linux/x86_64/README.md b/quickstart/linux/x86_64/README.md new file mode 100644 index 000000000..deb80a2be --- /dev/null +++ b/quickstart/linux/x86_64/README.md @@ -0,0 +1,34 @@ +# 快速启动容器环境 + +> 提供了 debian 11 构建 和 alpine 构建环境 +> 任意选一个就可以 + +## debian 11 构建环境 + +```bash + +# 启动 debian 11 容器环境 +sh quickstart/linux/x86_64/run-debian-11-container.sh + +# 进入容器 +sh quickstart/linux/x86_64/connection-static-php-cli.sh + +# 准备构建基础软件 +sh quickstart/linux/x86_64/debian-11-init.sh + +``` + +## aline 构建环境 + +```bash + +# 启动 alpine 容器环境 +sh quickstart/linux/x86_64/run-alpine-3.16-container.sh + +# 进入容器 +sh sh quickstart/linux/x86_64/connection-static-php-cli.sh + +# 准备构建基础软件 +sh quickstart/linux/x86_64/alpine-3.16-init.sh + +``` \ No newline at end of file diff --git a/quickstart/linux/x86_64/alpine-3.16-init.sh b/quickstart/linux/x86_64/alpine-3.16-init.sh new file mode 100644 index 000000000..238e91bdc --- /dev/null +++ b/quickstart/linux/x86_64/alpine-3.16-init.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) + +test -f /etc/apk/repositories.save || cp /etc/apk/repositories /etc/apk/repositories.save +sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +apk update + +apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils \ No newline at end of file diff --git a/quickstart/linux/x86_64/connection-static-php-cli.sh b/quickstart/linux/x86_64/connection-static-php-cli.sh new file mode 100644 index 000000000..109735024 --- /dev/null +++ b/quickstart/linux/x86_64/connection-static-php-cli.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) + +cd ${__DIR__} + +docker exec -it static-php-cli-dev-1 bash diff --git a/quickstart/linux/x86_64/debian-11-init.sh b/quickstart/linux/x86_64/debian-11-init.sh new file mode 100644 index 000000000..9e4463b6b --- /dev/null +++ b/quickstart/linux/x86_64/debian-11-init.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) + +sed -i "s@deb.debian.org@mirrors.ustc.edu.cn@g" /etc/apt/sources.list && \ +sed -i "s@security.debian.org@mirrors.ustc.edu.cn@g" /etc/apt/sources.list + +apt update -y +apt install -y git curl wget ca-certificates +apt install -y xz-utils autoconf automake libclang-13-dev clang lld libtool cmake bison re2c gettext coreutils lzip zip unzip +apt install -y pkg-config bzip2 flex + + +# apt install build-essential linux-headers-$(uname -r) \ No newline at end of file diff --git a/quickstart/linux/x86_64/prepare.sh b/quickstart/linux/x86_64/prepare.sh new file mode 100644 index 000000000..bd2783309 --- /dev/null +++ b/quickstart/linux/x86_64/prepare.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} + +composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ + +chmod +x bin/spc + +./bin/spc fetch --all --debug + +./bin/spc list-ext + + +#./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=gcc --cxx=g++ --debug + +./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug diff --git a/quickstart/linux/x86_64/run-alpine-3.16-container.sh b/quickstart/linux/x86_64/run-alpine-3.16-container.sh new file mode 100644 index 000000000..b53d9cd43 --- /dev/null +++ b/quickstart/linux/x86_64/run-alpine-3.16-container.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__DIR__} + + +{ + docker stop static-php-cli-dev-1 +} || { + echo $? +} +cd ${__DIR__} +IMAGE=alpine:3.16 + +cd ${__DIR__} +docker run --rm --name static-php-cli-dev-1 -d -v ${__PROJECT__}:/work -w /work $IMAGE tail -f /dev/null + diff --git a/quickstart/linux/x86_64/run-debian-11-container.sh b/quickstart/linux/x86_64/run-debian-11-container.sh new file mode 100644 index 000000000..a9239727a --- /dev/null +++ b/quickstart/linux/x86_64/run-debian-11-container.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__DIR__} + + +{ + docker stop static-php-cli-dev-1 +} || { + echo $? +} +cd ${__DIR__} +IMAGE=debian:11 + +cd ${__DIR__} +docker run --rm --name static-php-cli-dev-1 -d -v ${__PROJECT__}:/work -w /work $IMAGE tail -f /dev/null + diff --git a/quickstart/macOS/x86_64/prepare.sh b/quickstart/macOS/x86_64/prepare.sh new file mode 100644 index 000000000..93b835608 --- /dev/null +++ b/quickstart/macOS/x86_64/prepare.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} + +export PATH=${__PROJECT__}/bin/runtime:$PATH + +composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ + +chmod +x bin/spc + +./bin/spc fetch --all --debug + +./bin/spc list-ext + +./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo,pdo_sqlite,ftp,curl" --cc=clang --cxx=clang++ --debug