Skip to content

Commit 892d566

Browse files
authored
feat(ci): support build apisix under arm64 (#188)
1 parent 79b6f67 commit 892d566

File tree

5 files changed

+108
-11
lines changed

5 files changed

+108
-11
lines changed

.circleci/config.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,47 @@ jobs:
1111
machine:
1212
image: ubuntu-2004:202101-01
1313
resource_class: arm.medium
14+
environment:
15+
- TEST_VERSION: 0-latest
1416
steps:
1517
- checkout
1618
- run:
17-
name: "build apisix base deb"
19+
name: install dependencies
1820
command: |
19-
sudo BUILD_PATH=~/project version=latest ./utils/build-common.sh build_apisix_base_deb
21+
sudo apt-get install -y make
2022
- run:
21-
name: "echo openresty version"
23+
name: package apisix-base
2224
command: |
23-
/usr/local/openresty/bin/openresty -V
25+
make package type=deb app=apisix-base version=${TEST_VERSION}
26+
- run:
27+
name: package apisx
28+
command: |
29+
make package type=deb app=apisix version=${TEST_VERSION} checkout=master image_base=ubuntu image_tag=20.04
30+
- run:
31+
name: install apisix deb into container
32+
command: |
33+
docker build -t apache/apisix:${TEST_VERSION}-deb-test --build-arg APISIX_VERSION=${TEST_VERSION} -f test/apisix/Dockerfile.test.apisix.arm64.ubuntu20.04 .
34+
- run:
35+
name: start apisix and test
36+
command: |
37+
docker run -d --rm --name apisix-${TEST_VERSION}-deb-test -v $(pwd)/test/apisix/config.yaml:/usr/local/apisix/conf/config.yaml -p 9080:9080 -p 9443:9443 apache/apisix:${TEST_VERSION}-deb-test
38+
sleep 20
39+
curl http://127.0.0.1:9080/apisix/admin/routes/1 \
40+
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
41+
{
42+
"uri": "/get",
43+
"upstream": {
44+
"type": "roundrobin",
45+
"nodes": {
46+
"httpbin.org:80": 1
47+
}
48+
}
49+
}'
50+
result_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://127.0.0.1:9080/get`
51+
if [[ $result_code -ne 200 ]]; then
52+
printf "result_code: %s\n" "$result_code"
53+
exit 125
54+
fi
2455
2556
# Invoke jobs via workflows
2657
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows

package-apisix-base.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ if [ "$ARTIFACT" != "0" ]; then
1111
artifact=${ARTIFACT}
1212
fi
1313

14+
ARCH=${ARCH:-`(uname -m | tr '[:upper:]' '[:lower:]')`}
15+
1416
openresty_zlib_version="1.2.11-3"
1517
openresty_openssl111_version="1.1.1n"
1618
openresty_pcre_version="8.44-1"
@@ -41,7 +43,12 @@ fpm -f -s dir -t "$PACKAGE_TYPE" \
4143
--config-files usr/lib/systemd/system/openresty.service \
4244
--prefix=/usr/local
4345

46+
PACKAGE_ARCH="amd64"
47+
if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
48+
PACKAGE_ARCH="arm64"
49+
fi
50+
4451
if [ "$PACKAGE_TYPE" == "deb" ]; then
4552
# Rename deb file with adding $DIST section
46-
mv /output/apisix-base_"${PACKAGE_VERSION}"-"${ITERATION}"_amd64.deb /output/apisix-base_"${PACKAGE_VERSION}"-"${ITERATION}"~"${dist}"_amd64.deb
53+
mv /output/apisix-base_"${PACKAGE_VERSION}"-"${ITERATION}"_"${PACKAGE_ARCH}".deb /output/apisix-base_"${PACKAGE_VERSION}"-"${ITERATION}"~"${dist}"_"${PACKAGE_ARCH}".deb
4754
fi

package-apisix.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -x
44
mkdir /output
55
dist=$(cat /tmp/dist)
66

7+
ARCH=${ARCH:-`(uname -m | tr '[:upper:]' '[:lower:]')`}
8+
79
# Determine the dependencies
810
dep_ldap="openldap-devel"
911
if [ "$PACKAGE_TYPE" == "deb" ]
@@ -61,8 +63,13 @@ fpm -f -s dir -t "$PACKAGE_TYPE" \
6163
--config-files usr/local/apisix/conf/config.yaml \
6264
--config-files usr/local/apisix/conf/config-default.yaml
6365

66+
PACKAGE_ARCH="amd64"
67+
if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
68+
PACKAGE_ARCH="arm64"
69+
fi
70+
6471
# Rename deb file with adding $DIST section
6572
if [ "$PACKAGE_TYPE" == "deb" ]
6673
then
67-
mv /output/apisix_${PACKAGE_VERSION}-${ITERATION}_amd64.deb /output/apisix_${PACKAGE_VERSION}-${ITERATION}~${dist}_amd64.deb
74+
mv /output/apisix_${PACKAGE_VERSION}-${ITERATION}_"${PACKAGE_ARCH}".deb /output/apisix_${PACKAGE_VERSION}-${ITERATION}~${dist}_"${PACKAGE_ARCH}".deb
6875
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
ARG IMAGE_BASE="ubuntu"
2+
ARG IMAGE_TAG="20.04"
3+
4+
FROM ${IMAGE_BASE}:${IMAGE_TAG}
5+
6+
ARG ETCD_VERSION="v3.4.18"
7+
ARG APISIX_VERSION
8+
ARG IMAGE_BASE
9+
ARG IMAGE_TAG
10+
11+
ENV RUNNING_ETCD_VERSION=${ETCD_VERSION}
12+
13+
COPY ./output/apisix_${APISIX_VERSION}-0~${IMAGE_BASE}${IMAGE_TAG}_arm64.deb /apisix_${APISIX_VERSION}-0~${IMAGE_BASE}${IMAGE_TAG}_arm64.deb
14+
COPY ./output/apisix-base_"${APISIX_VERSION}"-0~"${IMAGE_BASE}${IMAGE_TAG}"_arm64.deb /apisix-base_"${APISIX_VERSION}"-0~"${IMAGE_BASE}${IMAGE_TAG}"_arm64.deb
15+
COPY ./utils/install-common.sh /install-common.sh
16+
17+
18+
RUN set -x \
19+
&& apt-get update \
20+
&& apt-get install -y sudo git libreadline-dev lsb-release libssl-dev perl build-essential \
21+
&& apt-get -y install --no-install-recommends wget gnupg ca-certificates \
22+
&& wget -O - https://openresty.org/package/pubkey.gpg | apt-key add - \
23+
&& echo "deb http://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list \
24+
&& apt-get update \
25+
&& apt-get install -y openresty-openssl111-dev openresty-pcre-dev openresty-zlib-dev \
26+
&& dpkg -i /apisix-base_"${APISIX_VERSION}"-0~"${IMAGE_BASE}${IMAGE_TAG}"_arm64.deb
27+
28+
29+
# install apisix
30+
RUN set -x \
31+
&& /install-common.sh install_etcd \
32+
&& apt install -y libldap2-dev \
33+
&& dpkg -i --ignore-depends=openresty /apisix_${APISIX_VERSION}-0~${IMAGE_BASE}${IMAGE_TAG}_arm64.deb
34+
35+
# start etcd and test
36+
CMD ["sh", "-c", "(ETCD_UNSUPPORTED_ARCH=arm64 nohup etcd-$RUNNING_ETCD_VERSION-linux-arm64/etcd >/tmp/etcd.log 2>&1 &) && sleep 10 && apisix start && sleep 3600"]
37+
38+
EXPOSE 9080 9443

utils/install-common.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
set -euo pipefail
33
set -x
44

5+
ARCH=${ARCH:-`(uname -m | tr '[:upper:]' '[:lower:]')`}
6+
57
install_apisix_dependencies_deb() {
68
install_dependencies_deb
79
install_openresty_deb
@@ -29,11 +31,15 @@ install_dependencies_deb() {
2931

3032
install_openresty_deb() {
3133
# install openresty and openssl111
34+
arch_path=""
35+
if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
36+
arch_path="arm64/"
37+
fi
3238
DEBIAN_FRONTEND=noninteractive apt-get update
3339
DEBIAN_FRONTEND=noninteractive apt-get install -y libreadline-dev lsb-release libpcre3 libpcre3-dev libldap2-dev libssl-dev perl build-essential
3440
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends wget gnupg ca-certificates
3541
wget -O - https://openresty.org/package/pubkey.gpg | apt-key add -
36-
echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list
42+
echo "deb http://openresty.org/package/${arch_path}ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list
3743
DEBIAN_FRONTEND=noninteractive apt-get update
3844
DEBIAN_FRONTEND=noninteractive apt-get install -y openresty-openssl111-dev openresty
3945
}
@@ -51,8 +57,12 @@ install_luarocks() {
5157
}
5258

5359
install_etcd() {
54-
wget https://github.com/etcd-io/etcd/releases/download/"${RUNNING_ETCD_VERSION}"/etcd-"${RUNNING_ETCD_VERSION}"-linux-amd64.tar.gz
55-
tar -zxvf etcd-"${RUNNING_ETCD_VERSION}"-linux-amd64.tar.gz
60+
ETCD_ARCH="amd64"
61+
if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
62+
ETCD_ARCH="arm64"
63+
fi
64+
wget https://github.com/etcd-io/etcd/releases/download/"${RUNNING_ETCD_VERSION}"/etcd-"${RUNNING_ETCD_VERSION}"-linux-"${ETCD_ARCH}".tar.gz
65+
tar -zxvf etcd-"${RUNNING_ETCD_VERSION}"-linux-"${ETCD_ARCH}".tar.gz
5666
}
5767

5868
version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
@@ -106,8 +116,12 @@ install_apisix() {
106116
}
107117

108118
install_golang() {
109-
wget https://dl.google.com/go/go1.16.linux-amd64.tar.gz
110-
tar -xzf go1.16.linux-amd64.tar.gz
119+
GO_ARCH="amd64"
120+
if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then
121+
GO_ARCH="arm64"
122+
fi
123+
wget https://dl.google.com/go/go1.16.linux-"${GO_ARCH}".tar.gz
124+
tar -xzf go1.16.linux-"${GO_ARCH}".tar.gz
111125
mv go /usr/local
112126
}
113127

0 commit comments

Comments
 (0)