Skip to content

Commit

Permalink
feat: Install apisix and apisix-runtime from source code (#10729)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vacant2333 authored Jan 3, 2024
1 parent 55f8a20 commit bf9e9f8
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 58 deletions.
118 changes: 118 additions & 0 deletions .github/workflows/source-install.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .requirements
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

APISIX_PACKAGE_NAME=apisix

APISIX_RUNTIME=1.1.0
APISIX_RUNTIME=1.1.1
32 changes: 23 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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; \
Expand All @@ -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 ]")
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions ci/centos7-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions ci/linux-install-openresty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions ci/redhat-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions docs/en/latest/building-apisix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down
13 changes: 3 additions & 10 deletions docs/zh/latest/building-apisix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -75,7 +68,7 @@ make deps
make install
```

该命令将安装 APISIX 运行时依赖的 Lua 库和 `apisix` 命令。
该命令将安装 APISIX 运行时依赖的 Lua 库以及 `apisix-runtime` `apisix` 命令。

:::note

Expand Down
Loading

0 comments on commit bf9e9f8

Please sign in to comment.