diff --git a/.github/workflows/package-apisix-base-apk.yml b/.github/workflows/package-apisix-base-apk.yml new file mode 100644 index 000000000..6223dd9d7 --- /dev/null +++ b/.github/workflows/package-apisix-base-apk.yml @@ -0,0 +1,29 @@ +name: package apisix-base apk + +on: + push: + branches: [ openresty/* ] + tags: + - "v*" + paths-ignore: + - '*.md' + pull_request: + branches: [ master ] + paths-ignore: + - '*.md' + +jobs: + build: + runs-on: ubuntu-latest + env: + BUILD_APISIX_BASE_VERSION: 1.19.3.2.0 + steps: + - uses: actions/checkout@v2 + + - name: install dependencies + run: | + sudo apt-get install -y make ruby ruby-dev rubygems build-essential + + - name: build apisix-base apk + run: | + make package version=${BUILD_APISIX_BASE_VERSION} image_base=alpine image_tag=3.12 app=apisix-base type=apk diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..723ef36f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/Makefile b/Makefile index 98d18fcb4..5de07ed4d 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ image_tag="7" iteration=0 local_code_path=0 openresty="openresty" +openresty_version="1.19.3.2.0" artifact="0" apisix_repo="https://github.com/apache/apisix" dashboard_repo="https://github.com/apache/apisix-dashboard" @@ -67,6 +68,34 @@ define build endef endif +### function for building image +### $(1) is name +### $(2) is dockerfile filename +### $(3) is package type +### $(4) is openresty image name +### $(5) is openresty image version +### $(6) is code path +ifneq ($(buildx), True) +define build-image + docker build -t apache/$(1)-$(3):$(version) \ + --build-arg OPENRESTY_NAME=$(4) \ + --build-arg OPENRESTY_VERSION=$(5) \ + --build-arg CODE_PATH=$(6) \ + -f ./dockerfiles/Dockerfile.$(2).$(3) . +endef +else +define build-image + docker buildx build -t apache/$(1)-$(3):$(version) \ + --build-arg OPENRESTY_NAME=$(4) \ + --build-arg OPENRESTY_VERSION=$(5) \ + --build-arg CODE_PATH=$(6) \ + --load \ + --cache-from=$(cache_from) \ + --cache-to=$(cache_to) \ + -f ./dockerfiles/Dockerfile.$(2).$(3) . +endef +endif + ### function for packing ### $(1) is name ### $(2) is package type @@ -155,6 +184,10 @@ build-apisix-base-rpm: build-apisix-base-deb: $(call build,apisix-base,apisix-base,deb,$(local_code_path)) +.PHONY: build-apisix-base-apk +build-apisix-base-apk: + $(call build,apisix-base,apisix-base,apk,$(local_code_path)) + ### build rpm for apisix-base: .PHONY: package-apisix-base-rpm package-apisix-base-rpm: @@ -180,10 +213,10 @@ build-fpm: endif ifeq ($(filter $(app),apisix dashboard apisix-base),) -$(info the app's value have to be apisix or dashboard!) +$(info the app's value have to be apisix, dashboard or apisix-base!) -else ifeq ($(filter $(type),rpm deb),) -$(info the type's value have to be rpm or deb!) +else ifeq ($(filter $(type),rpm deb apk),) +$(info the type's value have to be rpm, deb or apk!) else ifeq ($(version), 0) $(info you have to input a version value!) @@ -198,6 +231,9 @@ package: build-fpm package: build-apisix-base-deb package: package-apisix-base-deb +else ifeq ($(app)_$(type),apisix-base_apk) +package: build-apisix-base-apk + else ifeq ($(checkout), 0) $(info you have to input a checkout value!) diff --git a/build-apisix-base.sh b/build-apisix-base.sh index 90d0a964c..d02f153f0 100755 --- a/build-apisix-base.sh +++ b/build-apisix-base.sh @@ -29,6 +29,17 @@ or_ver="1.19.3.2" wget --no-check-certificate https://openresty.org/download/openresty-${or_ver}.tar.gz tar -zxvpf openresty-${or_ver}.tar.gz +if [ "$repo" == wasm-nginx-module ]; then + cp -r "$prev_workdir" . +else + git clone --depth=1 $wasm_nginx_module_ver \ + https://github.com/api7/wasm-nginx-module.git +fi + +cd wasm-nginx-module || exit 1 +./install-wasmtime.sh +cd .. + if [ "$repo" == ngx_multi_upstream_module ]; then cp -r "$prev_workdir" . else @@ -50,12 +61,7 @@ else https://github.com/api7/apisix-nginx-module.git fi -if [ "$repo" == wasm-nginx-module ]; then - cp -r "$prev_workdir" . -else - git clone --depth=1 $wasm_nginx_module_ver \ - https://github.com/api7/wasm-nginx-module.git -fi + if [ "$repo" == lua-var-nginx-module ]; then cp -r "$prev_workdir" . @@ -72,9 +78,6 @@ cd apisix-nginx-module/patch || exit 1 ./patch.sh ../../openresty-${or_ver} cd ../.. -cd wasm-nginx-module || exit 1 -./install-wasmtime.sh -cd .. version=${version:-0.0.0} cc_opt=${cc_opt:-} diff --git a/dockerfiles/Dockerfile.apisix-base.apk b/dockerfiles/Dockerfile.apisix-base.apk new file mode 100644 index 000000000..ef483709a --- /dev/null +++ b/dockerfiles/Dockerfile.apisix-base.apk @@ -0,0 +1,94 @@ +ARG IMAGE_BASE="alpine" +ARG IMAGE_TAG="3.12" + +FROM ${IMAGE_BASE}:${IMAGE_TAG} + +COPY ./utils/build-common.sh /tmp/build-common.sh +COPY build-apisix-base.sh /tmp/build-apisix-base.sh +COPY ./utils/determine-dist.sh /tmp/determine-dist.sh + + +ARG RESTY_OPENSSL_VERSION="1.1.1g" +ARG RESTY_OPENSSL_PATCH_VERSION="1.1.1f" +ARG RESTY_OPENSSL_URL_BASE="https://www.openssl.org/source" +ARG RESTY_PCRE_VERSION="8.44" +ARG RESTY_J="1" +ARG RESTY_EVAL_PRE_CONFIGURE="" + +LABEL resty_image_base="${RESTY_IMAGE_BASE}" +LABEL resty_image_tag="${IMAGE_TAG}" +LABEL resty_openssl_version="${RESTY_OPENSSL_VERSION}" +LABEL resty_openssl_patch_version="${RESTY_OPENSSL_PATCH_VERSION}" +LABEL resty_openssl_url_base="${RESTY_OPENSSL_URL_BASE}" +LABEL resty_pcre_version="${RESTY_PCRE_VERSION}" +LABEL resty_eval_pre_configure="${RESTY_EVAL_PRE_CONFIGURE}" + + +RUN apk add --no-cache --virtual .build-deps \ + build-base \ + coreutils \ + curl \ + gd-dev \ + geoip-dev \ + libxslt-dev \ + linux-headers \ + make \ + perl-dev \ + readline-dev \ + zlib-dev \ + && apk add --no-cache \ + gd \ + geoip \ + libxslt \ + zlib \ + bash \ + git \ + sudo \ + curl \ + build-base \ + libstdc++ + +RUN cd /tmp \ + && GLIBC_VER="2.29-r0" && \ + wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \ + wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk && \ + wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk && \ + wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk && \ + apk add glibc-bin-${GLIBC_VER}.apk glibc-i18n-${GLIBC_VER}.apk glibc-${GLIBC_VER}.apk && \ + /usr/glibc-compat/sbin/ldconfig + +RUN cd /tmp \ + && if [ -n "${RESTY_EVAL_PRE_CONFIGURE}" ]; then eval $(echo ${RESTY_EVAL_PRE_CONFIGURE}); fi \ + && cd /tmp \ + && curl -fSL "${RESTY_OPENSSL_URL_BASE}/openssl-${RESTY_OPENSSL_VERSION}.tar.gz" -o openssl-${RESTY_OPENSSL_VERSION}.tar.gz \ + && tar xzf openssl-${RESTY_OPENSSL_VERSION}.tar.gz \ + && cd openssl-${RESTY_OPENSSL_VERSION} \ + && echo 'patching OpenSSL 1.1.1 for OpenResty' \ + && curl -s https://raw.githubusercontent.com/openresty/openresty/master/patches/openssl-${RESTY_OPENSSL_PATCH_VERSION}-sess_set_get_cb_yield.patch | patch -p1 \ + && ./config \ + no-threads shared zlib -g \ + enable-ssl3 enable-ssl3-method \ + --prefix=/usr/local/openresty/openssl111 \ + --libdir=lib \ + -Wl,-rpath,/usr/local/openresty/openssl111/lib \ + && make -j${RESTY_J} \ + && make -j${RESTY_J} install_sw + +RUN cd /tmp \ + && curl -fSL https://ftp.pcre.org/pub/pcre/pcre-${RESTY_PCRE_VERSION}.tar.gz -o pcre-${RESTY_PCRE_VERSION}.tar.gz \ + && tar xzf pcre-${RESTY_PCRE_VERSION}.tar.gz \ + && cd /tmp/pcre-${RESTY_PCRE_VERSION} \ + && ./configure \ + --prefix=/usr/local/openresty/pcre \ + --disable-cpp \ + --enable-jit \ + --enable-utf \ + --enable-unicode-properties \ + && make -j${RESTY_J} \ + && make -j${RESTY_J} install + +RUN cd /tmp \ + && curl --version \ + && ./build-common.sh build_apisix_base_apk + +CMD /bin/sh \ No newline at end of file diff --git a/dockerfiles/Dockerfile.apisix.alpine b/dockerfiles/Dockerfile.apisix.alpine new file mode 100644 index 000000000..5d11ef831 --- /dev/null +++ b/dockerfiles/Dockerfile.apisix.alpine @@ -0,0 +1,55 @@ +ARG ENABLE_PROXY=false +ARG OPENRESTY_VERSION +ARG OPENRESTY_NAME + +FROM apache/${OPENRESTY_NAME}:${OPENRESTY_VERSION} AS production-stage + +ARG APISIX_VERSION=2.9 +LABEL apisix_version="${APISIX_VERSION}" + +ARG ENABLE_PROXY +RUN set -x \ + && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \ + && apk add --no-cache --virtual .builddeps \ + automake \ + autoconf \ + libtool \ + pkgconfig \ + cmake \ + git \ + pcre \ + pcre-dev \ + && mkdir ~/.luarocks \ + && luarocks config variables.OPENSSL_LIBDIR /usr/local/openresty/openssl/lib \ + && luarocks config variables.OPENSSL_INCDIR /usr/local/openresty/openssl/include \ + && luarocks install https://github.com/apache/apisix/raw/master/rockspec/apisix-${APISIX_VERSION}-0.rockspec --tree=/usr/local/apisix/deps \ + && cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/${APISIX_VERSION}-0/bin/apisix /usr/bin/ \ + && (if [ "$APISIX_VERSION" = "master" ] || [ "$APISIX_VERSION" \> "2.2" ]; then echo 'use shell ';else bin='#! /usr/local/openresty/luajit/bin/luajit\npackage.path = "/usr/local/apisix/?.lua;" .. package.path'; sed -i "1s@.*@$bin@" /usr/bin/apisix ; fi;) \ + && mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \ + && apk del .builddeps build-base make unzip + +FROM alpine:3.13 AS last-stage + +ARG ENABLE_PROXY +# add runtime for Apache APISIX +RUN set -x \ + && (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \ + && apk add --no-cache bash libstdc++ curl tzdata + +WORKDIR /usr/local/apisix + +COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/ +COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/ +COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix + +# forward request and error logs to docker log collector +RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \ + && ln -sf /dev/stderr /usr/local/apisix/logs/error.log + +ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin + +EXPOSE 9080 9443 + +CMD ["sh", "-c", "/usr/bin/apisix init && /usr/bin/apisix init_etcd && /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'"] + +STOPSIGNAL SIGQUIT diff --git a/utils/build-common.sh b/utils/build-common.sh index d92eab931..505651884 100755 --- a/utils/build-common.sh +++ b/utils/build-common.sh @@ -31,10 +31,16 @@ build_apisix_base_deb() { ./build-apisix-base.sh } +build_apisix_base_apk() { + export_openresty_variables + ./build-apisix-base.sh +} + export_openresty_variables() { export openssl_prefix=/usr/local/openresty/openssl111 export zlib_prefix=/usr/local/openresty/zlib export pcre_prefix=/usr/local/openresty/pcre + export OR_PREFIX=/usr/local/openresty export cc_opt="-DNGX_LUA_ABORT_AT_PANIC -I${zlib_prefix}/include -I${pcre_prefix}/include -I${openssl_prefix}/include" export ld_opt="-L${zlib_prefix}/lib -L${pcre_prefix}/lib -L${openssl_prefix}/lib -Wl,-rpath,${zlib_prefix}/lib:${pcre_prefix}/lib:${openssl_prefix}/lib" @@ -49,4 +55,7 @@ build_apisix_base_rpm) build_apisix_base_deb) build_apisix_base_deb ;; +build_apisix_base_apk) + build_apisix_base_apk + ;; esac