This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new bf9e9f836 feat: Install apisix and apisix-runtime from source code 
(#10729)
bf9e9f836 is described below

commit bf9e9f8362cbe223af203d77a316ad0ace0c9a46
Author: Vacant <[email protected]>
AuthorDate: Wed Jan 3 18:26:38 2024 +0800

    feat: Install apisix and apisix-runtime from source code (#10729)
---
 .github/workflows/source-install.yml | 118 +++++++++++++++++++++++++++++++++++
 .requirements                        |   2 +-
 Makefile                             |  32 +++++++---
 ci/centos7-ci.sh                     |   5 +-
 ci/linux-install-openresty.sh        |   1 +
 ci/redhat-ci.sh                      |   7 +--
 docs/en/latest/building-apisix.md    |  12 +---
 docs/zh/latest/building-apisix.md    |  13 +---
 utils/install-dependencies.sh        |  79 ++++++++++++++++-------
 9 files changed, 211 insertions(+), 58 deletions(-)

diff --git a/.github/workflows/source-install.yml 
b/.github/workflows/source-install.yml
new file mode 100644
index 000000000..d2051aee8
--- /dev/null
+++ b/.github/workflows/source-install.yml
@@ -0,0 +1,118 @@
+name: Source Code Install
+
+on:
+  push:
+    branches: [master, 'release/**']
+    paths-ignore:
+      - 'docs/**'
+      - '**/*.md'
+  pull_request:
+    branches: [master, 'release/**']
+    paths-ignore:
+      - 'docs/**'
+      - '**/*.md'
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && 
github.run_number || github.ref }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  install-on-multi-platform:
+    strategy:
+      fail-fast: false
+      matrix:
+        platform:
+          - ubuntu-20.04
+        os_platform:
+          - centos7
+          - ubuntu
+          - redhat
+    services:
+      etcd:
+        image: bitnami/etcd:3.5.4
+        ports:
+          - 2379:2379
+          - 2380:2380
+        env:
+          ALLOW_NONE_AUTHENTICATION: yes
+          ETCD_ADVERTISE_CLIENT_URLS: http://0.0.0.0:2379
+      httpbin:
+        image: kennethreitz/httpbin
+        ports:
+          - 8088:80
+
+    runs-on: ${{ matrix.platform }}
+    timeout-minutes: 30
+
+    steps:
+      - name: Check out code
+        uses: actions/checkout@v4
+        with:
+          submodules: recursive
+
+      - name: Cache deps
+        uses: actions/cache@v3
+        env:
+          cache-name: cache-deps
+        with:
+          path: deps
+          key: ${{ runner.os }}-${{ env.cache-name }}-${{ matrix.os_platform 
}}-${{ hashFiles('apisix-master-0.rockspec') }}
+
+      - name: Install and start apisix on ${{ matrix.os_platform }}
+        env:
+          INSTALL_PLATFORM: ${{ matrix.os_platform }}
+        run: |
+          if [[ $INSTALL_PLATFORM == "ubuntu" ]]; then
+              sudo apt-get update
+              sudo apt-get install -y git sudo make
+              make deps
+              sudo make install
+              apisix start
+          elif [[ $INSTALL_PLATFORM == "redhat" ]]; then
+              docker run -itd -v ${{ github.workspace }}:/apisix --name ubi8 
--net="host" --dns 8.8.8.8 --dns-search apache.org 
registry.access.redhat.com/ubi8/ubi:8.6 /bin/bash
+              docker exec ubi8 bash -c "yum install -y git sudo make"
+              docker exec ubi8 bash -c "cd apisix && make deps"
+              docker exec ubi8 bash -c "cd apisix && make install"
+              docker exec ubi8 bash -c "cd apisix && apisix start"
+          elif [[ $INSTALL_PLATFORM == "centos7" ]]; then
+              docker run -itd -v ${{ github.workspace }}:/apisix --name 
centos7Instance --net="host" --dns 8.8.8.8 --dns-search apache.org 
docker.io/centos:7 /bin/bash
+              docker exec centos7Instance bash -c "yum install -y git sudo 
make"
+              docker exec centos7Instance bash -c "cd apisix && make deps"
+              docker exec centos7Instance bash -c "cd apisix && make install"
+              docker exec centos7Instance bash -c "cd apisix && apisix start"
+          fi
+          sleep 6
+
+      - name: Test apisix
+        run: |
+          curl http://127.0.0.1:9180/apisix/admin/routes/1 \
+            -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+            {
+              "uri": "/get",
+              "upstream": {
+                  "type": "roundrobin",
+                  "nodes": {
+                      "127.0.0.1:8088": 1
+                  }
+              }
+            }'
+          result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} 
http://127.0.0.1:9080/get`
+          if [[ $result_code -ne 200 ]]; then
+              printf "result_code: %s\n" "$result_code"
+              echo "===============access.log==============="
+              cat logs/access.log
+              echo "===============error.log==============="
+              cat logs/error.log
+              exit 125
+          fi
+
+      - name: Check error log
+        run: |
+          if grep -q '\[error\]' logs/error.log; then
+              echo "=====found error log====="
+              cat /usr/local/apisix/logs/error.log
+              exit 125
+          fi
diff --git a/.requirements b/.requirements
index 978772db5..b5d22118a 100644
--- a/.requirements
+++ b/.requirements
@@ -17,4 +17,4 @@
 
 APISIX_PACKAGE_NAME=apisix
 
-APISIX_RUNTIME=1.1.0
+APISIX_RUNTIME=1.1.1
diff --git a/Makefile b/Makefile
index e297f9014..7f285b91e 100644
--- a/Makefile
+++ b/Makefile
@@ -40,13 +40,17 @@ ENV_DOCKER             ?= docker
 ENV_DOCKER_COMPOSE     ?= docker-compose --project-directory $(CURDIR) -p 
$(project_name) -f $(project_compose_ci)
 ENV_NGINX              ?= $(ENV_NGINX_EXEC) -p $(CURDIR) -c 
$(CURDIR)/conf/nginx.conf
 ENV_NGINX_EXEC         := $(shell command -v openresty 2>/dev/null || command 
-v nginx 2>/dev/null)
-ENV_OPENSSL_PREFIX     ?= $(addprefix $(ENV_NGINX_PREFIX), openssl3)
+ENV_OPENSSL_PREFIX     ?= /usr/local/openresty/openssl3
 ENV_LUAROCKS           ?= luarocks
 ## These variables can be injected by luarocks
 ENV_INST_PREFIX        ?= /usr
 ENV_INST_LUADIR        ?= $(ENV_INST_PREFIX)/share/lua/5.1
 ENV_INST_BINDIR        ?= $(ENV_INST_PREFIX)/bin
 ENV_HOMEBREW_PREFIX    ?= /usr/local
+ENV_RUNTIME_VER             ?= $(shell $(ENV_NGINX_EXEC) -V 2>&1 | tr ' ' '\n' 
 | grep 'APISIX_RUNTIME_VER' | cut -d '=' -f2)
+
+-include .requirements
+export
 
 ifneq ($(shell whoami), root)
        ENV_LUAROCKS_FLAG_LOCAL := --local
@@ -56,10 +60,8 @@ ifdef ENV_LUAROCKS_SERVER
        ENV_LUAROCKS_SERVER_OPT := --server $(ENV_LUAROCKS_SERVER)
 endif
 
-# Execute only in the presence of ENV_NGINX_EXEC to avoid unexpected error 
output
-ifneq ($(ENV_NGINX_EXEC), )
+ifneq ($(shell test -d $(ENV_OPENSSL_PREFIX) && echo -n yes), yes)
        ENV_NGINX_PREFIX := $(shell $(ENV_NGINX_EXEC) -V 2>&1 | grep -Eo 
'prefix=(.*)/nginx\s+' | grep -Eo '/.*/')
-       # OpenResty 1.17.8 or higher version uses openssl3 as the openssl 
dirname.
        ifeq ($(shell test -d $(addprefix $(ENV_NGINX_PREFIX), openssl3) && 
echo -n yes), yes)
                ENV_OPENSSL_PREFIX := $(addprefix $(ENV_NGINX_PREFIX), openssl3)
        endif
@@ -126,12 +128,12 @@ endef
 .PHONY: runtime
 runtime:
 ifeq ($(ENV_NGINX_EXEC), )
-ifeq ("$(wildcard /usr/local/openresty-debug/bin/openresty)", "")
+ifeq ("$(wildcard /usr/local/openresty/bin/openresty)", "")
        @$(call func_echo_warn_status, "WARNING: OpenResty not found. You have 
to install OpenResty and add the binary file to PATH before install Apache 
APISIX.")
        exit 1
 else
-       $(eval ENV_NGINX_EXEC := /usr/local/openresty-debug/bin/openresty)
-       @$(call func_echo_status, "Use openresty-debug as default runtime")
+       $(eval ENV_NGINX_EXEC := /usr/local/openresty/bin/openresty)
+       @$(call func_echo_status, "Use openresty as default runtime")
 endif
 endif
 
@@ -153,7 +155,7 @@ help:
 
 ### deps : Installing dependencies
 .PHONY: deps
-deps: runtime
+deps: install-runtime
        $(eval ENV_LUAROCKS_VER := $(shell $(ENV_LUAROCKS) --version | grep -E 
-o "luarocks [0-9]+."))
        @if [ '$(ENV_LUAROCKS_VER)' = 'luarocks 3.' ]; then \
                mkdir -p ~/.luarocks; \
@@ -169,7 +171,7 @@ deps: runtime
 
 ### undeps : Uninstalling dependencies
 .PHONY: undeps
-undeps:
+undeps: uninstall-runtime
        @$(call func_echo_status, "$@ -> [ Start ]")
        $(ENV_LUAROCKS) purge --tree=deps
        @$(call func_echo_success_status, "$@ -> [ Done ]")
@@ -253,6 +255,18 @@ reload: runtime
        $(ENV_APISIX) reload
        @$(call func_echo_success_status, "$@ -> [ Done ]")
 
+.PHONY: install-runtime
+install-runtime:
+ifneq ($(ENV_RUNTIME_VER), $(APISIX_RUNTIME))
+       ./utils/install-dependencies.sh
+       @sudo $(ENV_INSTALL) /usr/local/openresty/bin/openresty 
$(ENV_INST_BINDIR)/openresty
+endif
+
+.PHONY: uninstall-runtime
+uninstall-runtime:
+       ./utils/install-dependencies.sh uninstall
+       rm -rf /usr/local/openresty
+       rm -f $(ENV_INST_BINDIR)/openresty
 
 ### install : Install the apisix (only for luarocks)
 .PHONY: install
diff --git a/ci/centos7-ci.sh b/ci/centos7-ci.sh
index f9961f758..344552e9f 100755
--- a/ci/centos7-ci.sh
+++ b/ci/centos7-ci.sh
@@ -25,7 +25,6 @@ install_dependencies() {
     # install build & runtime deps
     yum install -y wget tar gcc gcc-c++ automake autoconf libtool make unzip 
patch \
         git sudo openldap-devel which ca-certificates \
-        openresty-pcre-devel openresty-zlib-devel \
         epel-release  \
         cpanminus perl \
         openssl-devel
@@ -43,9 +42,9 @@ install_dependencies() {
 
     # install openresty to make apisix's rpm test work
     yum install -y yum-utils && yum-config-manager --add-repo 
https://openresty.org/package/centos/openresty.repo
-    export luajit_xcflags="-DLUAJIT_ASSERT -DLUAJIT_NUMMODE=2 
-DLUAJIT_ENABLE_LUA52COMPAT -O0"
-    export debug_args=--with-debug
+    yum install -y openresty-pcre-devel openresty-zlib-devel
 
+    export runtime_version=${APISIX_RUNTIME}
     wget 
"https://raw.githubusercontent.com/api7/apisix-build-tools/apisix-runtime/${APISIX_RUNTIME}/build-apisix-runtime.sh";
     chmod +x build-apisix-runtime.sh
     ./build-apisix-runtime.sh latest
diff --git a/ci/linux-install-openresty.sh b/ci/linux-install-openresty.sh
index bcb74a959..8d2433417 100755
--- a/ci/linux-install-openresty.sh
+++ b/ci/linux-install-openresty.sh
@@ -51,6 +51,7 @@ if [ "$OPENRESTY_VERSION" == "source" ]; then
     fi
 fi
 
+export runtime_version=${APISIX_RUNTIME}
 wget 
"https://raw.githubusercontent.com/api7/apisix-build-tools/apisix-runtime/${APISIX_RUNTIME}/build-apisix-runtime.sh";
 chmod +x build-apisix-runtime.sh
 ./build-apisix-runtime.sh latest
diff --git a/ci/redhat-ci.sh b/ci/redhat-ci.sh
index 97a0fe45b..c10e047d4 100755
--- a/ci/redhat-ci.sh
+++ b/ci/redhat-ci.sh
@@ -36,12 +36,9 @@ install_dependencies() {
 
     # install apisix-runtime to make apisix's rpm test work
     yum install -y yum-utils && yum-config-manager --add-repo 
https://openresty.org/package/centos/openresty.repo
-    rpm --import https://repos.apiseven.com/KEYS
-    yum -y install 
https://repos.apiseven.com/packages/centos/apache-apisix-repo-1.0-1.noarch.rpm
-
-    export luajit_xcflags="-DLUAJIT_ASSERT -DLUAJIT_NUMMODE=2 
-DLUAJIT_ENABLE_LUA52COMPAT -O0"
-    export debug_args=--with-debug
+    yum install -y openresty-pcre-devel openresty-zlib-devel
 
+    export runtime_version=${APISIX_RUNTIME}
     wget 
"https://raw.githubusercontent.com/api7/apisix-build-tools/apisix-runtime/${APISIX_RUNTIME}/build-apisix-runtime.sh";
     chmod +x build-apisix-runtime.sh
     ./build-apisix-runtime.sh latest
diff --git a/docs/en/latest/building-apisix.md 
b/docs/en/latest/building-apisix.md
index ba9c9c6d2..a2bf1604a 100644
--- a/docs/en/latest/building-apisix.md
+++ b/docs/en/latest/building-apisix.md
@@ -45,19 +45,13 @@ To build and package APISIX for a specific platform, see 
[apisix-build-tools](ht
 
 ## Building APISIX from source
 
-Install dependencies using the script provided by APISIX:
-
-```shell
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh
 -sL | bash -
-```
-
-Save the APISIX version to an environment variable to be used next:
+First of all, we need to specify the version `APISIX_VERSION` to be installed:
 
 ```shell
 APISIX_VERSION='3.7.0'
 ```
 
-Clone the APISIX source code of this version into a new directory 
`apisix-APISIX_VERSION`:
+Then, you can run the following command to clone the APISIX source code from 
Github:
 
 ```shell
 git clone --depth 1 --branch ${APISIX_VERSION} 
https://github.com/apache/apisix.git apisix-${APISIX_VERSION}
@@ -73,7 +67,7 @@ make deps
 make install
 ```
 
-This will install the runtime-dependent Lua libraries and the `apisix` CLI 
tool.
+This will install the runtime-dependent Lua libraries and `apisix-runtime` the 
`apisix` CLI tool.
 
 :::note
 
diff --git a/docs/zh/latest/building-apisix.md 
b/docs/zh/latest/building-apisix.md
index 40e48113e..0d39b6870 100644
--- a/docs/zh/latest/building-apisix.md
+++ b/docs/zh/latest/building-apisix.md
@@ -44,20 +44,13 @@ import TabItem from '@theme/TabItem';
 
 ## 源码安装 APISIX
 
-首先,你可以通过以下命令安装依赖项:
-
-```shell
-curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/install-dependencies.sh
 -sL | bash -
-```
-
-然后,创建一个目录并设置环境变量 `APISIX_VERSION`:
+首先,我们需要指定需要安装的版本`APISIX_VERSION`:
 
 ```shell
 APISIX_VERSION='3.7.0'
-mkdir apisix-${APISIX_VERSION}
 ```
 
-现在,你可以运行以下命令,从 Github 克隆 APISIX 源码:
+然后,你可以运行以下命令,从 Github 克隆 APISIX 源码:
 
 ```shell
 git clone --depth 1 --branch ${APISIX_VERSION} 
https://github.com/apache/apisix.git apisix-${APISIX_VERSION}
@@ -75,7 +68,7 @@ make deps
 make install
 ```
 
-该命令将安装 APISIX 运行时依赖的 Lua 库和 `apisix` 命令。
+该命令将安装 APISIX 运行时依赖的 Lua 库以及 `apisix-runtime` 和 `apisix` 命令。
 
 :::note
 
diff --git a/utils/install-dependencies.sh b/utils/install-dependencies.sh
index 530f19a54..bdf545984 100755
--- a/utils/install-dependencies.sh
+++ b/utils/install-dependencies.sh
@@ -45,31 +45,25 @@ function install_dependencies_with_aur() {
 # Install dependencies on centos and fedora
 function install_dependencies_with_yum() {
     sudo yum install -y yum-utils
-
-    local common_dep="curl wget git gcc openresty-openssl111-devel unzip pcre 
pcre-devel openldap-devel"
-    if [ "${1}" == "centos" ]; then
-        # add APISIX source
-        local apisix_pkg=apache-apisix-repo-1.0-1.noarch
-        rpm -q --quiet ${apisix_pkg} || sudo yum install -y 
https://repos.apiseven.com/packages/centos/${apisix_pkg}.rpm
-
-        # install apisix-runtime and some compilation tools
-        # shellcheck disable=SC2086
-        sudo yum install -y apisix-runtime $common_dep
-    else
-        # add OpenResty source
-        sudo yum-config-manager --add-repo 
"https://openresty.org/package/${1}/openresty.repo";
-
-        # install OpenResty and some compilation tools
-        # shellcheck disable=SC2086
-        sudo yum install -y openresty $common_dep
+    sudo yum-config-manager --add-repo 
"https://openresty.org/package/${1}/openresty.repo";
+    if [[ "${1}" == "centos" ]]; then
+        sudo yum -y install centos-release-scl
+        sudo yum -y install devtoolset-9 patch wget
+        set +eu
+        source scl_source enable devtoolset-9
+        set -eu
     fi
+    sudo yum install -y  \
+        gcc gcc-c++ curl wget unzip xz gnupg perl-ExtUtils-Embed cpanminus 
patch \
+        perl perl-devel pcre pcre-devel openldap-devel \
+        openresty-zlib-devel openresty-pcre-devel
 }
 
 # Install dependencies on ubuntu and debian
 function install_dependencies_with_apt() {
     # add OpenResty source
     sudo apt-get update
-    sudo apt-get -y install software-properties-common wget lsb-release
+    sudo apt-get -y install software-properties-common wget lsb-release gnupg 
patch
     wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
     arch=$(uname -m | tr '[:upper:]' '[:lower:]')
     arch_path=""
@@ -83,8 +77,8 @@ function install_dependencies_with_apt() {
     fi
     sudo apt-get update
 
-    # install OpenResty and some compilation tools
-    sudo apt-get install -y git openresty curl openresty-openssl111-dev make 
gcc libpcre3 libpcre3-dev libldap2-dev unzip
+    # install some compilation tools
+    sudo apt-get install -y curl make gcc g++ cpanminus libpcre3 libpcre3-dev 
libldap2-dev unzip openresty-zlib-dev openresty-pcre-dev
 }
 
 # Install dependencies on mac osx
@@ -97,6 +91,8 @@ function install_dependencies_on_mac_osx() {
 function multi_distro_installation() {
     if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
         install_dependencies_with_yum "centos"
+    elif grep -Eqi -e "Red Hat" -e "rhel" /etc/*-release; then
+        install_dependencies_with_yum "rhel"
     elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; 
then
         install_dependencies_with_yum "fedora"
     elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; 
then
@@ -107,12 +103,46 @@ function multi_distro_installation() {
         install_dependencies_with_aur
     else
         echo "Non-supported operating system version"
+        exit 1
+    fi
+    install_apisix_runtime
+}
+
+function multi_distro_uninstallation() {
+    if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
+        sudo yum autoremove -y openresty-zlib-devel openresty-pcre-devel
+    elif grep -Eqi -e "Red Hat" -e "rhel" /etc/*-release; then
+        sudo yum autoremove -y openresty-zlib-devel openresty-pcre-devel
+    elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; 
then
+        sudo yum autoremove -y openresty-zlib-devel openresty-pcre-devel
+    elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; 
then
+        sudo apt-get autoremove -y openresty-zlib-dev openresty-pcre-dev
+    elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; 
then
+        sudo apt-get autoremove -y openresty-zlib-dev openresty-pcre-dev
+    else
+        echo "Non-supported operating system version"
+        exit 1
     fi
 }
 
+function install_apisix_runtime() {
+    export runtime_version=${APISIX_RUNTIME:?}
+    wget 
"https://raw.githubusercontent.com/api7/apisix-build-tools/apisix-runtime/${APISIX_RUNTIME}/build-apisix-runtime.sh";
+    chmod +x build-apisix-runtime.sh
+    ./build-apisix-runtime.sh latest
+    rm build-apisix-runtime.sh
+}
+
 # Install LuaRocks
 function install_luarocks() {
-    curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
+    if [ -f "./utils/linux-install-luarocks.sh" ]; then
+        ./utils/linux-install-luarocks.sh
+    elif [ -f "./linux-install-luarocks.sh" ]; then
+        ./linux-install-luarocks.sh
+    else
+        echo "Installing luarocks from remote master branch"
+        curl 
https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh
 -sL | bash -
+    fi
 }
 
 # Entry
@@ -135,6 +165,13 @@ function main() {
         "install_luarocks")
             install_luarocks
         ;;
+        "uninstall")
+            if [[ "${OS_NAME}" == "linux" ]]; then
+                multi_distro_uninstallation
+            else
+                echo "Non-supported distribution"
+            fi
+        ;;
         *)
             echo "Unsupported method: ${case_opt}"
         ;;

Reply via email to