From 29bbe91f2d019bae65fbac7b08dfac9d73c4adf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 16:08:59 +0800 Subject: [PATCH 1/8] feat: update to cross-compile on minideb --- .github/workflows/push-apisix-base-image.yml | 2 +- build-apisix-base.sh | 1 + dockerfiles/Dockerfile.apisix-base.minideb | 113 +++++++++++++++++++ utils/build-common.sh | 8 ++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 dockerfiles/Dockerfile.apisix-base.minideb diff --git a/.github/workflows/push-apisix-base-image.yml b/.github/workflows/push-apisix-base-image.yml index ca795cef7..d536692bf 100644 --- a/.github/workflows/push-apisix-base-image.yml +++ b/.github/workflows/push-apisix-base-image.yml @@ -45,4 +45,4 @@ jobs: run: | docker buildx build -t api7/apisix-base:${{ steps.tag_env.outputs.version }} --push \ --build-arg VERSION=${{ steps.tag_env.outputs.version }} --platform linux/amd64,linux/arm64 \ - -f ./dockerfiles/Dockerfile.apisix-base.apk . + -f ./dockerfiles/Dockerfile.apisix-base.minideb . diff --git a/build-apisix-base.sh b/build-apisix-base.sh index 108f435fb..556732327 100755 --- a/build-apisix-base.sh +++ b/build-apisix-base.sh @@ -88,6 +88,7 @@ cd apisix-nginx-module/patch || exit 1 cd ../.. cd wasm-nginx-module || exit 1 +if [ "${TARGETARCH}" = "arm64" ] ; then sed -i 's/x86_64/aarch64/g' ./install-wasmtime.sh; fi ./install-wasmtime.sh cd .. diff --git a/dockerfiles/Dockerfile.apisix-base.minideb b/dockerfiles/Dockerfile.apisix-base.minideb new file mode 100644 index 000000000..47b568c8b --- /dev/null +++ b/dockerfiles/Dockerfile.apisix-base.minideb @@ -0,0 +1,113 @@ +FROM --platform=amd64 bitnami/minideb:bullseye as build + +COPY ./utils/build-common.sh \ + ./utils/install-common.sh \ + build-apisix-base.sh \ + ./utils/determine-dist.sh \ + /tmp/ + +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="" +ARG VERSION +ARG TARGETARCH + +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 dpkg --add-architecture ${TARGETARCH} \ + && install_packages ca-certificates \ + curl \ + wget \ + git \ + gettext-base \ + patch \ + xz-utils \ + sudo \ + make \ + perl \ + unzip \ + libgd-dev:${TARGETARCH} \ + libgeoip-dev:${TARGETARCH} \ + libncurses5-dev:${TARGETARCH} \ + libperl-dev:${TARGETARCH} \ + libreadline-dev:${TARGETARCH} \ + libxslt1-dev:${TARGETARCH} \ + zlib1g-dev:${TARGETARCH} \ + && if [ "${TARGETARCH}" = "amd64" ] ; then install_packages gcc g++; fi \ + && if [ "${TARGETARCH}" = "arm64" ] ; then \ + install_packages gcc-aarch64-linux-gnu g++-aarch64-linux-gnu; \ + ln /usr/bin/aarch64-linux-gnu-gcc /usr/bin/cc; \ + ln /usr/bin/aarch64-linux-gnu-gcc /usr/bin/gcc; \ + ln /usr/bin/aarch64-linux-gnu-ar /usr/bin/ar; \ + ln /usr/bin/aarch64-linux-gnu-ranlib /usr/bin/ranlib; \ + ln /usr/bin/aarch64-linux-gnu-g++ /usr/bin/g++; \ + fi \ + && gcc -v \ + && g++ -v + +RUN echo ${TARGETARCH} \ + && 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 \ + && if [ "${TARGETARCH}" = "arm64" ] ; then export MACHINE=aarch64; fi \ + && ./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 echo ${TARGETARCH} \ + && cd /tmp \ + && curl -fSL https://downloads.sourceforge.net/project/pcre/pcre/${RESTY_PCRE_VERSION}/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 + +ENV version=${VERSION} +ENV TARGETARCH=${TARGETARCH} + +RUN echo ${TARGETARCH} \ + && cd /tmp \ + && curl --version \ + && ./build-common.sh build_apisix_base_minideb \ + && ./install-common.sh install_lua \ + && ./install-common.sh install_luarocks \ + && /usr/local/openresty/bin/openresty -V + +FROM bitnami/minideb:bullseye as prod + +COPY --from=build /usr/local/openresty /usr/local/openresty + +RUN install_packages libgd3 \ + libgeoip1 \ + libxslt1.1 \ + zlib1g \ + && rm /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.a + +ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin + +CMD /bin/sh \ No newline at end of file diff --git a/utils/build-common.sh b/utils/build-common.sh index 505651884..81780edb1 100755 --- a/utils/build-common.sh +++ b/utils/build-common.sh @@ -31,6 +31,11 @@ build_apisix_base_deb() { ./build-apisix-base.sh } +build_apisix_base_minideb() { + export_openresty_variables + ./build-apisix-base.sh +} + build_apisix_base_apk() { export_openresty_variables ./build-apisix-base.sh @@ -55,6 +60,9 @@ build_apisix_base_rpm) build_apisix_base_deb) build_apisix_base_deb ;; +build_apisix_base_minideb) + build_apisix_base_minideb + ;; build_apisix_base_apk) build_apisix_base_apk ;; From 3b760458525fb21618b74b872696db62abfe38f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 16:21:26 +0800 Subject: [PATCH 2/8] feat: clean libwasmtime.a --- dockerfiles/Dockerfile.apisix-base.minideb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/Dockerfile.apisix-base.minideb b/dockerfiles/Dockerfile.apisix-base.minideb index 47b568c8b..f82469718 100644 --- a/dockerfiles/Dockerfile.apisix-base.minideb +++ b/dockerfiles/Dockerfile.apisix-base.minideb @@ -106,7 +106,7 @@ RUN install_packages libgd3 \ libgeoip1 \ libxslt1.1 \ zlib1g \ - && rm /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.a + && rm -f /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.a ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin From b1fcfbadbadc4d3180b73fc8c4bc0436f8a74198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 17:06:26 +0800 Subject: [PATCH 3/8] fix: apk build failed --- build-apisix-base.sh | 1 + dockerfiles/Dockerfile.apisix-base.minideb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build-apisix-base.sh b/build-apisix-base.sh index 556732327..0feb0c511 100755 --- a/build-apisix-base.sh +++ b/build-apisix-base.sh @@ -88,6 +88,7 @@ cd apisix-nginx-module/patch || exit 1 cd ../.. cd wasm-nginx-module || exit 1 +if [ -z ${TARGETARCH} ] ; then export TARGETARCH=amd64; fi if [ "${TARGETARCH}" = "arm64" ] ; then sed -i 's/x86_64/aarch64/g' ./install-wasmtime.sh; fi ./install-wasmtime.sh cd .. diff --git a/dockerfiles/Dockerfile.apisix-base.minideb b/dockerfiles/Dockerfile.apisix-base.minideb index f82469718..ab5e794ec 100644 --- a/dockerfiles/Dockerfile.apisix-base.minideb +++ b/dockerfiles/Dockerfile.apisix-base.minideb @@ -96,6 +96,7 @@ RUN echo ${TARGETARCH} \ && ./build-common.sh build_apisix_base_minideb \ && ./install-common.sh install_lua \ && ./install-common.sh install_luarocks \ + && rm -f /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.a \ && /usr/local/openresty/bin/openresty -V FROM bitnami/minideb:bullseye as prod @@ -105,8 +106,7 @@ COPY --from=build /usr/local/openresty /usr/local/openresty RUN install_packages libgd3 \ libgeoip1 \ libxslt1.1 \ - zlib1g \ - && rm -f /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.a + zlib1g ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin From 12a199c44ed59cdabd7e0dd1a07cfcd0e99068a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 17:07:11 +0800 Subject: [PATCH 4/8] feat: add back alpine image build --- .github/workflows/push-apisix-base-image.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/push-apisix-base-image.yml b/.github/workflows/push-apisix-base-image.yml index d536692bf..3d6527614 100644 --- a/.github/workflows/push-apisix-base-image.yml +++ b/.github/workflows/push-apisix-base-image.yml @@ -44,5 +44,8 @@ jobs: if: ${{ startsWith(steps.tag_type.outputs.version, 'apisix-base/') }} run: | docker buildx build -t api7/apisix-base:${{ steps.tag_env.outputs.version }} --push \ + --build-arg VERSION=${{ steps.tag_env.outputs.version }} --platform linux/amd64,linux/arm64 \ + -f ./dockerfiles/Dockerfile.apisix-base.apk . + docker buildx build -t api7/apisix-base:${{ steps.tag_env.outputs.version }}-debian --push \ --build-arg VERSION=${{ steps.tag_env.outputs.version }} --platform linux/amd64,linux/arm64 \ -f ./dockerfiles/Dockerfile.apisix-base.minideb . From e9638056f33f3d71536eb8cf776e388b92886510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 17:18:22 +0800 Subject: [PATCH 5/8] fix: update env access --- build-apisix-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-apisix-base.sh b/build-apisix-base.sh index 0feb0c511..4685bfed3 100755 --- a/build-apisix-base.sh +++ b/build-apisix-base.sh @@ -88,8 +88,8 @@ cd apisix-nginx-module/patch || exit 1 cd ../.. cd wasm-nginx-module || exit 1 -if [ -z ${TARGETARCH} ] ; then export TARGETARCH=amd64; fi -if [ "${TARGETARCH}" = "arm64" ] ; then sed -i 's/x86_64/aarch64/g' ./install-wasmtime.sh; fi +if [ -z $TARGETARCH ] ; then export TARGETARCH=amd64; fi +if [ "$TARGETARCH" = "arm64" ] ; then sed -i 's/x86_64/aarch64/g' ./install-wasmtime.sh; fi ./install-wasmtime.sh cd .. From b5bbc3710076377978fb760f882bcb45acd3216d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 17:25:19 +0800 Subject: [PATCH 6/8] fix --- build-apisix-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-apisix-base.sh b/build-apisix-base.sh index 4685bfed3..f30caf088 100755 --- a/build-apisix-base.sh +++ b/build-apisix-base.sh @@ -88,7 +88,7 @@ cd apisix-nginx-module/patch || exit 1 cd ../.. cd wasm-nginx-module || exit 1 -if [ -z $TARGETARCH ] ; then export TARGETARCH=amd64; fi +if [ -z $TARGETARCH ] ; then export TARGETARCH="amd64"; fi if [ "$TARGETARCH" = "arm64" ] ; then sed -i 's/x86_64/aarch64/g' ./install-wasmtime.sh; fi ./install-wasmtime.sh cd .. From 8b9dadd6402e1f6b27fb8d2f631a687def56e649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 17:41:55 +0800 Subject: [PATCH 7/8] fix: add default env --- dockerfiles/Dockerfile.apisix-base.apk | 2 ++ dockerfiles/Dockerfile.apisix-base.deb | 2 ++ dockerfiles/Dockerfile.apisix-base.rpm | 2 ++ 3 files changed, 6 insertions(+) diff --git a/dockerfiles/Dockerfile.apisix-base.apk b/dockerfiles/Dockerfile.apisix-base.apk index cc6527fb2..9870c263b 100644 --- a/dockerfiles/Dockerfile.apisix-base.apk +++ b/dockerfiles/Dockerfile.apisix-base.apk @@ -17,6 +17,7 @@ ARG RESTY_PCRE_VERSION="8.44" ARG RESTY_J="1" ARG RESTY_EVAL_PRE_CONFIGURE="" ARG VERSION +ARG TARGETARCH LABEL resty_image_base="${RESTY_IMAGE_BASE}" LABEL resty_image_tag="${IMAGE_TAG}" @@ -85,6 +86,7 @@ RUN cd /tmp \ && make -j${RESTY_J} install ENV version=${VERSION} +ENV TARGETARCH=${TARGETARCH} RUN cd /tmp \ && curl --version \ && source /root/.cargo/env \ diff --git a/dockerfiles/Dockerfile.apisix-base.deb b/dockerfiles/Dockerfile.apisix-base.deb index 0887e7dff..e4ba81bae 100644 --- a/dockerfiles/Dockerfile.apisix-base.deb +++ b/dockerfiles/Dockerfile.apisix-base.deb @@ -12,10 +12,12 @@ WORKDIR /tmp ARG VERSION ARG IMAGE_BASE ARG IMAGE_TAG +ARG TARGETARCH ENV IMAGE_BASE=${IMAGE_BASE} ENV IMAGE_TAG=${IMAGE_TAG} ENV version=${VERSION} +ENV TARGETARCH=${TARGETARCH} RUN ./build-common.sh build_apisix_base_deb \ # determine dist and write it into /tmp/dist file diff --git a/dockerfiles/Dockerfile.apisix-base.rpm b/dockerfiles/Dockerfile.apisix-base.rpm index 051314bc9..1118aaefa 100644 --- a/dockerfiles/Dockerfile.apisix-base.rpm +++ b/dockerfiles/Dockerfile.apisix-base.rpm @@ -12,10 +12,12 @@ WORKDIR /tmp ARG VERSION ARG IMAGE_BASE ARG IMAGE_TAG +ARG TARGETARCH ENV IMAGE_BASE=${IMAGE_BASE} ENV IMAGE_TAG=${IMAGE_TAG} ENV version=${VERSION} +ENV TARGETARCH=${TARGETARCH} RUN ./build-common.sh build_apisix_base_rpm \ # determine dist and write it into /tmp/dist file From 0210a213525b84f371b5edd37462f0859023adac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B3=BD=E5=B9=B3?= Date: Thu, 13 Jan 2022 18:45:43 +0800 Subject: [PATCH 8/8] chore: add EOL --- dockerfiles/Dockerfile.apisix-base.minideb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/Dockerfile.apisix-base.minideb b/dockerfiles/Dockerfile.apisix-base.minideb index ab5e794ec..2a4252557 100644 --- a/dockerfiles/Dockerfile.apisix-base.minideb +++ b/dockerfiles/Dockerfile.apisix-base.minideb @@ -110,4 +110,4 @@ RUN install_packages libgd3 \ ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin -CMD /bin/sh \ No newline at end of file +CMD /bin/sh