From a32bc502f254475fb9a69203b6c71749862e8541 Mon Sep 17 00:00:00 2001 From: Sn0rt Date: Thu, 26 Oct 2023 11:33:20 +0800 Subject: [PATCH] feat: support new package APISIX-runtime (#342) Signed-off-by: Sn0rt --- .circleci/config.yml | 98 ++++++++- ...package-apisix-runtime-deb-ubuntu20.04.yml | 64 ++++++ .../package-apisix-runtime-rpm-el7.yml | 59 +++++ .../package-apisix-runtime-rpm-el8.yml | 66 ++++++ .../package-apisix-runtime-rpm-ubi.yml | 59 +++++ .github/workflows/publish-deb.yml | 16 +- .github/workflows/publish.yml | 16 +- .../workflows/push-apisix-runtime-image.yml | 48 +++++ Makefile | 40 +++- README.md | 55 +++-- build-apisix-runtime-debug-centos7.sh | 19 ++ build-apisix-runtime.sh | 202 ++++++++++++++++++ dockerfiles/Dockerfile.apisix-runtime.apk | 117 ++++++++++ dockerfiles/Dockerfile.apisix-runtime.deb | 30 +++ dockerfiles/Dockerfile.apisix-runtime.rpm | 33 +++ dockerfiles/Dockerfile.package.apisix-runtime | 24 +++ package-apisix-runtime.sh | 57 +++++ package-apisix.sh | 60 ++++-- post-install-apisix-runtime.sh | 3 + utils/build-common.sh | 71 ++++++ 20 files changed, 1097 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/package-apisix-runtime-deb-ubuntu20.04.yml create mode 100644 .github/workflows/package-apisix-runtime-rpm-el7.yml create mode 100644 .github/workflows/package-apisix-runtime-rpm-el8.yml create mode 100644 .github/workflows/package-apisix-runtime-rpm-ubi.yml create mode 100644 .github/workflows/push-apisix-runtime-image.yml create mode 100755 build-apisix-runtime-debug-centos7.sh create mode 100755 build-apisix-runtime.sh create mode 100644 dockerfiles/Dockerfile.apisix-runtime.apk create mode 100644 dockerfiles/Dockerfile.apisix-runtime.deb create mode 100644 dockerfiles/Dockerfile.apisix-runtime.rpm create mode 100644 dockerfiles/Dockerfile.package.apisix-runtime create mode 100755 package-apisix-runtime.sh create mode 100644 post-install-apisix-runtime.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 52431df45..6f0cebda3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,6 +22,10 @@ jobs: name: package apisix-base command: | make package type=deb app=apisix-base version=${TEST_VERSION} + - run: + name: package apisix-runtime + command: | + make package type=deb app=apisix-runtime version=${TEST_VERSION} - run: name: package apisx command: | @@ -73,6 +77,27 @@ jobs: --build-arg VERSION=dev --build-arg BUILD_LATEST=latest \ -f ./dockerfiles/Dockerfile.apisix-base.deb . + build-and-push-apisix-runtime-dev-arm: + machine: + image: ubuntu-2004:202101-01 + resource_class: arm.medium + + steps: + - checkout + - run: + name: submodule + command: | + git submodule sync + git submodule update --init + + - run: + name: Build and Push Docker Image + command: | + echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + docker buildx build -t api7/apisix-runtime:dev-arm64 --push \ + --build-arg VERSION=dev --build-arg BUILD_LATEST=latest \ + -f ./dockerfiles/Dockerfile.apisix-runtime.deb . + build-and-push-apisix-base-dev-x86: machine: image: ubuntu-2004:202101-01 @@ -94,13 +119,34 @@ jobs: --build-arg VERSION=dev --build-arg BUILD_LATEST=latest \ -f ./dockerfiles/Dockerfile.apisix-base.deb . - upload-manifest: + build-and-push-apisix-runtime-dev-x86: + machine: + image: ubuntu-2004:202101-01 + resource_class: medium + + steps: + - checkout + - run: + name: submodule + command: | + git submodule sync + git submodule update --init + + - run: + name: Build and Push Docker Image + command: | + echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + docker buildx build -t api7/apisix-runtime:dev-x86_64 --push \ + --build-arg VERSION=dev --build-arg BUILD_LATEST=latest \ + -f ./dockerfiles/Dockerfile.apisix-runtime.deb . + + upload-manifest-apisix-base-dev: docker: - image: cimg/python:3.8.2 steps: - checkout - deploy: - name: "Upload manifest to registry" + name: "Upload apisix-base manifest to registry" command: | set -eu export DOCKER_CLI_EXPERIMENTAL=enabled @@ -110,6 +156,22 @@ jobs: api7/apisix-base:dev-x86_64 docker manifest push api7/apisix-base:dev + upload-manifest-apisix-runtime-dev: + docker: + - image: cimg/python:3.8.2 + steps: + - checkout + - deploy: + name: "Upload apisix-runtime manifest to registry" + command: | + set -eu + export DOCKER_CLI_EXPERIMENTAL=enabled + echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + docker manifest create api7/apisix-runtime:dev \ + api7/apisix-runtime:dev-arm64 \ + api7/apisix-runtime:dev-x86_64 + docker manifest push api7/apisix-runtime:dev + build-arm64-package: parameters: var_os: @@ -178,6 +240,21 @@ jobs: - store_artifacts: path: /tmp/output + - when: + condition: + matches: { pattern: "^apisix-runtime/(.*)\\d+$", value: << pipeline.git.tag >> } + steps: + - run: + name: build apisix-runtime package + command: | + APISIX_RUNTIME_TAG_VERSION=$(echo ${CIRCLE_TAG##*/}) + echo "apisix-runtime version: $APISIX_RUNTIME_TAG_VERSION" + make package type=${PACK_TYPE} app=apisix-runtime checkout=${APISIX_RUNTIME_TAG_VERSION} version=${APISIX_RUNTIME_TAG_VERSION} image_base=<< parameters.var_os >> image_tag=<< parameters.var_os_release >> + mv ./output/apisix-runtime*.${PACK_TYPE} ${VAR_WORKBENCH_DIR} + + - store_artifacts: + path: /tmp/output + # Invoke jobs via workflows # See: https://circleci.com/docs/2.0/configuration-reference/#workflows workflows: @@ -198,10 +275,25 @@ workflows: jobs: - build-and-push-apisix-base-dev-arm - build-and-push-apisix-base-dev-x86 - - upload-manifest: + - upload-manifest-apisix-base-dev: requires: - build-and-push-apisix-base-dev-arm - build-and-push-apisix-base-dev-x86 + build-and-push-apisix-runtime-dev: + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - master + jobs: + - build-and-push-apisix-runtime-dev-arm + - build-and-push-apisix-runtime-dev-x86 + - upload-manifest-apisix-runtime-dev: + requires: + - build-and-push-apisix-runtime-dev-arm + - build-and-push-apisix-runtime-dev-x86 build-mutil-platform-arm64-apckage: jobs: - build-arm64-package: diff --git a/.github/workflows/package-apisix-runtime-deb-ubuntu20.04.yml b/.github/workflows/package-apisix-runtime-deb-ubuntu20.04.yml new file mode 100644 index 000000000..5cd5478db --- /dev/null +++ b/.github/workflows/package-apisix-runtime-deb-ubuntu20.04.yml @@ -0,0 +1,64 @@ +name: package apisix-runtime deb for ubuntu 20.04(Focal Fossa) + +on: + push: + branches: [ master ] + tags: + - "v*" + paths-ignore: + - '*.md' + pull_request: + branches: [ master ] + paths-ignore: + - '*.md' + schedule: + - cron: '0 0 * * *' + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + BUILD_APISIX_RUNTIME_VERSION: 1.0.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-runtime deb + run: | + make package type=deb app=apisix-runtime version=${BUILD_APISIX_RUNTIME_VERSION} image_base=ubuntu image_tag=20.04 + + - name: run ubuntu 20.04 docker and mapping apisix-runtime deb into container + run: | + docker run -itd -v /home/runner/work/apisix-build-tools/apisix-build-tools/output:/output --name ubuntu20.04Instance --net="host" docker.io/ubuntu:20.04 /bin/bash + + - name: install dependencies in container + run: | + docker exec ubuntu20.04Instance bash -c "DEBIAN_FRONTEND=noninteractive apt-get update" + docker exec ubuntu20.04Instance bash -c "DEBIAN_FRONTEND=noninteractive apt-get install -y libreadline-dev lsb-release libssl-dev perl build-essential" + docker exec ubuntu20.04Instance bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends wget gnupg ca-certificates" + docker exec ubuntu20.04Instance bash -c "wget -O - https://openresty.org/package/pubkey.gpg | apt-key add -" + docker exec ubuntu20.04Instance bash -c 'echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list' + docker exec ubuntu20.04Instance bash -c "DEBIAN_FRONTEND=noninteractive apt-get update" + docker exec ubuntu20.04Instance bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y install openresty-openssl111 openresty-pcre openresty-zlib" + + - name: install deb in container + run: | + docker exec ubuntu20.04Instance bash -c "dpkg -i /output/apisix-runtime_${BUILD_APISIX_RUNTIME_VERSION}-0~ubuntu20.04_amd64.deb" + + - name: check and ensure apisix-runtime is installed + run: | + docker exec ubuntu20.04Instance bash -c "/usr/local/openresty/bin/etcdctl -h" || exit 1 + export APISIX_RUNTIME_VER=$(docker exec ubuntu20.04Instance bash -c "openresty -V" 2>&1 | awk '/-O2 -DAPISIX_RUNTIME_VER=/{print $5}' | awk -v FS="=" '{print $2}') + if [ "$APISIX_RUNTIME_VER" != "${BUILD_APISIX_RUNTIME_VERSION}" ]; then exit 1; fi + + - name: Publish Artifact + uses: actions/upload-artifact@v2.2.4 + with: + name: apisix-runtime_${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0~ubuntu20.04_amd64.deb + path: output/apisix-runtime_${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0~ubuntu20.04_amd64.deb + retention-days: 5 + if-no-files-found: error diff --git a/.github/workflows/package-apisix-runtime-rpm-el7.yml b/.github/workflows/package-apisix-runtime-rpm-el7.yml new file mode 100644 index 000000000..69c0d1548 --- /dev/null +++ b/.github/workflows/package-apisix-runtime-rpm-el7.yml @@ -0,0 +1,59 @@ +name: package apisix-runtime rpm for el7 + +on: + push: + branches: [ master ] + tags: + - "v*" + paths-ignore: + - '*.md' + pull_request: + branches: [ master ] + paths-ignore: + - '*.md' + schedule: + - cron: '0 0 * * *' + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + BUILD_APISIX_RUNTIME_VERSION: 1.0.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-runtime rpm + run: | + make package type=rpm app=apisix-runtime version=${BUILD_APISIX_RUNTIME_VERSION} image_base=centos image_tag=7 + + - name: run centos7 docker and mapping apisix-runtime rpm into container + run: | + docker run -itd -v /home/runner/work/apisix-build-tools/apisix-build-tools/output:/output --name centos7Instance --net="host" docker.io/centos:7 /bin/bash + + - name: install dependencies in container + run: | + docker exec centos7Instance bash -c "yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo" + docker exec centos7Instance bash -c "yum -y install openresty-openssl111 openresty-pcre openresty-zlib" + + - name: install rpm in container + run: | + docker exec centos7Instance bash -c "yum -y localinstall /output/apisix-runtime-${BUILD_APISIX_RUNTIME_VERSION}-0.el7.x86_64.rpm" + + - name: check and ensure apisix-runtime is installed + run: | + docker exec centos7Instance bash -c "/usr/local/openresty/bin/etcdctl -h" || exit 1 + export APISIX_RUNTIME_VER=$(docker exec centos7Instance bash -c "openresty -V" 2>&1 | awk '/-O2 -DAPISIX_RUNTIME_VER=/{print $5}' | awk -v FS="=" '{print $2}') + if [ "$APISIX_RUNTIME_VER" != "${BUILD_APISIX_RUNTIME_VERSION}" ]; then exit 1; fi + + - name: Publish Artifact + uses: actions/upload-artifact@v2.2.4 + with: + name: apisix-runtime-${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0.el7.x86_64.rpm + path: output/apisix-runtime-${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0.el7.x86_64.rpm + retention-days: 5 + if-no-files-found: error diff --git a/.github/workflows/package-apisix-runtime-rpm-el8.yml b/.github/workflows/package-apisix-runtime-rpm-el8.yml new file mode 100644 index 000000000..6cba1dee4 --- /dev/null +++ b/.github/workflows/package-apisix-runtime-rpm-el8.yml @@ -0,0 +1,66 @@ +name: package apisix-runtime rpm for el8 + +on: + push: + branches: [ master ] + tags: + - "v*" + paths-ignore: + - '*.md' + pull_request: + branches: [ master ] + paths-ignore: + - '*.md' + schedule: + - cron: '0 0 * * *' + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + BUILD_APISIX_RUNTIME_VERSION: 1.0.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-runtime rpm + run: | + make package type=rpm app=apisix-runtime version=${BUILD_APISIX_RUNTIME_VERSION} image_base=centos image_tag=8 + + - name: run centos8 docker and mapping apisix-runtime rpm into container + run: | + docker run -itd -v /home/runner/work/apisix-build-tools/apisix-build-tools/output:/output --name centos8Instance --net="host" docker.io/centos:8 /bin/bash + + - name: install dependencies in container + run: | + docker exec centos8Instance bash -c "sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*" + docker exec centos8Instance bash -c "sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*" + docker exec centos8Instance bash -c "dnf install -y centos-release-stream" + docker exec centos8Instance bash -c "dnf swap -y centos-{linux,stream}-repos" + docker exec centos8Instance bash -c "dnf distro-sync -y" + + docker exec centos8Instance bash -c "dnf install -y yum-utils" + docker exec centos8Instance bash -c "yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo" + docker exec centos8Instance bash -c "yum -y install openresty-openssl111 openresty-pcre openresty-zlib" + + - name: install rpm in container + run: | + docker exec centos8Instance bash -c "yum -y localinstall /output/apisix-runtime-${BUILD_APISIX_RUNTIME_VERSION}-0.el8.x86_64.rpm" + + - name: check and ensure apisix-runtime is installed + run: | + docker exec centos8Instance bash -c "/usr/local/openresty/bin/etcdctl -h" || exit 1 + export APISIX_RUNTIME_VER=$(docker exec centos8Instance bash -c "openresty -V" 2>&1 | awk '/-O2 -DAPISIX_RUNTIME_VER=/{print $5}' | awk -v FS="=" '{print $2}') + if [ "$APISIX_RUNTIME_VER" != "${BUILD_APISIX_RUNTIME_VERSION}" ]; then exit 1; fi + + - name: Publish Artifact + uses: actions/upload-artifact@v2.2.4 + with: + name: apisix-runtime-${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0.el8.x86_64.rpm + path: output/apisix-runtime-${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0.el8.x86_64.rpm + retention-days: 5 + if-no-files-found: error diff --git a/.github/workflows/package-apisix-runtime-rpm-ubi.yml b/.github/workflows/package-apisix-runtime-rpm-ubi.yml new file mode 100644 index 000000000..66754382e --- /dev/null +++ b/.github/workflows/package-apisix-runtime-rpm-ubi.yml @@ -0,0 +1,59 @@ +name: package apisix-runtime rpm for ubi + +on: + push: + branches: [ master ] + tags: + - "v*" + paths-ignore: + - '*.md' + pull_request: + branches: [ master ] + paths-ignore: + - '*.md' + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + BUILD_APISIX_RUNTIME_VERSION: 1.0.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-runtime rpm + run: | + make package type=rpm app=apisix-runtime version=${BUILD_APISIX_RUNTIME_VERSION} image_base=registry.access.redhat.com/ubi8/ubi image_tag=8.6 + + - name: run ubi8 docker and mapping apisix-runtime rpm into container + run: | + docker run -itd -v /home/runner/work/apisix-build-tools/apisix-build-tools/output:/output --name ubiInstance --net="host" registry.access.redhat.com/ubi8/ubi:8.6 /bin/bash + + - name: install dependencies in container + run: | + docker exec ubiInstance bash -c "dnf install -y yum-utils" + docker exec ubiInstance bash -c "yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo" + docker exec ubiInstance bash -c "yum -y install openresty-openssl111 openresty-pcre openresty-zlib" + + - name: install rpm in container + run: | + docker exec ubiInstance bash -c "ls -la /output" + docker exec ubiInstance bash -c "yum -y localinstall /output/apisix-runtime-${BUILD_APISIX_RUNTIME_VERSION}-0.ubi8.6.x86_64.rpm" + + - name: check and ensure apisix-runtime is installed + run: | + docker exec ubiInstance bash -c "/usr/local/openresty/bin/etcdctl -h" || exit 1 + export APISIX_RUNTIME_VER=$(docker exec ubiInstance bash -c "openresty -V" 2>&1 | awk '/-O2 -DAPISIX_RUNTIME_VER=/{print $5}' | awk -v FS="=" '{print $2}') + if [ "$APISIX_RUNTIME_VER" != "${BUILD_APISIX_RUNTIME_VERSION}" ]; then exit 1; fi + + - name: Publish Artifact + uses: actions/upload-artifact@v2.2.4 + with: + name: apisix-runtime-${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0.ubi8.6.x86_64.rpm + path: output/apisix-runtime-${{ env.BUILD_APISIX_RUNTIME_VERSION }}-0.ubi8.6.x86_64.rpm + retention-days: 5 + if-no-files-found: error diff --git a/.github/workflows/publish-deb.yml b/.github/workflows/publish-deb.yml index 16c3e0bc4..7988757ce 100644 --- a/.github/workflows/publish-deb.yml +++ b/.github/workflows/publish-deb.yml @@ -1,4 +1,4 @@ -name: Build and Publish Package +name: Build and Publish DEB Package on: create: @@ -41,12 +41,13 @@ jobs: echo "TAG_TYPE=${type}" >> "$GITHUB_ENV" - name: Check Tags Type - if: ${{ env.TAG_TYPE != 'apisix' && env.TAG_TYPE != 'apisix-base' }} + if: ${{ env.TAG_TYPE != 'apisix' && env.TAG_TYPE != 'apisix-base' && env.TAG_TYPE != 'apisix-runtime' }} run: | echo "##[error]Tag type is not correct, please check it." exit 1 - - name: Build apisix/apisix-base deb Package + - name: Build apisix or apisix-base deb Package + if: ${{ env.TAG_TYPE == 'apisix' || env.TAG_TYPE == 'apisix-base' }} run: | echo build ${TAG_TYPE} deb package echo version ${TAG_VERSION} @@ -54,6 +55,15 @@ jobs: make package type=deb app=${TAG_TYPE} checkout=${TAG_VERSION} version=${TAG_VERSION} image_base=${VAR_OS} image_tag=${VAR_OS_RELEASE} openresty=apisix-base mv ./output/${TAG_TYPE}_${TAG_VERSION}-0~${VAR_OS}${VAR_OS_RELEASE}_amd64.deb ${VAR_DEB_WORKBENCH_DIR} + - name: Build apisix-runtime deb Package + if: ${{ env.TAG_TYPE == 'apisix-runtime' }} + run: | + echo build ${TAG_TYPE} deb package + echo version ${TAG_VERSION} + + make package type=deb app=${TAG_TYPE} checkout=${TAG_VERSION} version=${TAG_VERSION} image_base=${VAR_OS} image_tag=${VAR_OS_RELEASE} openresty=apisix-runtime + mv ./output/${TAG_TYPE}_${TAG_VERSION}-0~${VAR_OS}${VAR_OS_RELEASE}_amd64.deb ${VAR_DEB_WORKBENCH_DIR} + - name: Upload apisix/apisix-base Artifact uses: actions/upload-artifact@v2.2.3 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 08739741f..707280fdb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Build and Publish Package +name: Build and Publish RPM Package on: create: @@ -74,6 +74,20 @@ jobs: mv ./output/apisix-base-${APISIX_BASE_TAG_VERSION}-0.{el7,el8,ubi8.6}.x86_64.rpm ${VAR_RPM_WORKBENCH_DIR} echo "TARGET_APP=apisix-base" >> "$GITHUB_ENV" + - name: Build apisix-runtime RPM Package + if: ${{ startsWith(steps.tag_type.outputs.version, 'apisix-runtime/') }} + env: + APISIX_RUNTIME_TAG_VERSION: ${{ steps.tag_env.outputs.version}} + run: | + # build apisix-runtime + echo ${{ steps.tag_env.outputs.version}} + echo ${{ steps.tag_type.outputs.version}} + make package type=rpm app=apisix-runtime checkout=${APISIX_RUNTIME_TAG_VERSION} version=${APISIX_RUNTIME_TAG_VERSION} image_base=centos image_tag=7 + make package type=rpm app=apisix-runtime checkout=${APISIX_RUNTIME_TAG_VERSION} version=${APISIX_RUNTIME_TAG_VERSION} image_base=centos image_tag=8 + make package type=rpm app=apisix-runtime checkout=${APISIX_RUNTIME_TAG_VERSION} version=${APISIX_RUNTIME_TAG_VERSION} image_base=registry.access.redhat.com/ubi8/ubi image_tag=8.6 + mv ./output/apisix-runtime-${APISIX_RUNTIME_TAG_VERSION}-0.{el7,el8,ubi8.6}.x86_64.rpm ${VAR_RPM_WORKBENCH_DIR} + echo "TARGET_APP=apisix-runtime" >> "$GITHUB_ENV" + - name: Build apisix-dashboard RPM Package if: ${{ startsWith(steps.tag_type.outputs.version, 'dashboard/') }} env: diff --git a/.github/workflows/push-apisix-runtime-image.yml b/.github/workflows/push-apisix-runtime-image.yml new file mode 100644 index 000000000..0f9b3a15c --- /dev/null +++ b/.github/workflows/push-apisix-runtime-image.yml @@ -0,0 +1,48 @@ +name: Build and Push apisix-runtime image + +on: + create + +jobs: + publish_image: + name: Build and Push apisix-runtime image + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2.3.5 + with: + submodules: recursive + + - name: Extract Tags name + if: ${{ startsWith(github.ref, 'refs/tags/') }} + id: tag_env + shell: bash + run: | + echo "##[set-output name=version;]$(echo ${GITHUB_REF##*/})" + + - name: Extract Tags Type + if: ${{ startsWith(github.ref, 'refs/tags/') }} + id: tag_type + shell: bash + run: | + echo "##[set-output name=version;]$(echo ${GITHUB_REF#refs/tags/})" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + if: ${{ startsWith(steps.tag_type.outputs.version, 'apisix-runtime/') }} + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push Docker Image + if: ${{ startsWith(steps.tag_type.outputs.version, 'apisix-runtime/') }} + run: | + docker buildx build -t api7/apisix-runtime:${{ steps.tag_env.outputs.version }} --push \ + --build-arg VERSION=${{ steps.tag_env.outputs.version }} --platform linux/amd64,linux/arm64 \ + -f ./dockerfiles/Dockerfile.apisix-runtime.apk . diff --git a/Makefile b/Makefile index 2adcde89a..bf6f51b2c 100644 --- a/Makefile +++ b/Makefile @@ -174,6 +174,29 @@ package-dashboard-rpm: package-dashboard-deb: $(call package,apisix-dashboard,deb) +### build apisix-runtime: +.PHONY: build-apisix-runtime-rpm +build-apisix-runtime-rpm: + $(call build,apisix-runtime,apisix-runtime,rpm,$(local_code_path)) + +.PHONY: build-apisix-runtime-deb +build-apisix-runtime-deb: + $(call build,apisix-runtime,apisix-runtime,deb,$(local_code_path)) + +.PHONY: build-apisix-runtime-apk +build-apisix-runtime-apk: + $(call build,apisix-runtime,apisix-runtime,apk,$(local_code_path)) + +### build rpm for apisix-runtime: +.PHONY: package-apisix-runtime-rpm +package-apisix-runtime-rpm: + $(call package,apisix-runtime,rpm) + +### build deb for apisix-runtime: +.PHONY: package-apisix-runtime-deb +package-apisix-runtime-deb: + $(call package,apisix-runtime,deb) + ### build apisix-base: .PHONY: build-apisix-base-rpm build-apisix-base-rpm: @@ -211,8 +234,8 @@ build-fpm: -t api7/fpm - < ./dockerfiles/Dockerfile.fpm endif -ifeq ($(filter $(app),apisix dashboard apisix-base),) -$(info the app's value have to be apisix, dashboard or apisix-base!) +ifeq ($(filter $(app),apisix dashboard apisix-base apisix-runtime),) +$(info the app's value have to be apisix, dashboard, apisix-base and apisix-runtime!) else ifeq ($(filter $(type),rpm deb apk),) $(info the type's value have to be rpm, deb or apk!) @@ -230,6 +253,19 @@ package: build-fpm package: build-apisix-base-deb package: package-apisix-base-deb +else ifeq ($(app)_$(type),apisix-runtime_deb) +package: build-fpm +package: build-apisix-runtime-deb +package: package-apisix-runtime-deb + +else ifeq ($(app)_$(type),apisix-runtime_rpm) +package: build-fpm +package: build-apisix-runtime-rpm +package: package-apisix-runtime-rpm + +else ifeq ($(app)_$(type),apisix-runtime_apk) +package: build-apisix-runtime-apk + else ifeq ($(app)_$(type),apisix-base_apk) package: build-apisix-base-apk diff --git a/README.md b/README.md index bf751bb16..6fdb82354 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,23 @@ - rpm (if your host system is Ubuntu, should install rpmbuild by `sudo apt-get install rpm`) ## Parameters -|Parameter |Required |Description |Example| -|---------|---------|----|-----------| -|type |True |it can be `deb` or `rpm` or `apk`|type=rpm| -|app |True |it can be `apisix`, `dashboard` or `apisix-base`|app=apisix| -|checkout |True |the code branch or tag of the app which you want to package|checkout=2.1 or checkout=v2.1| -|version |True |the version of the package|version=10.10| -|local_code_path |False | the path of local code diretory of apisix or dashboard, which depends on the app parameter|local_code_path=/home/vagrant/apisix| -|openresty |False |the openresty type that apisix depends on, its value can be `openresty` or `apisix-base`, the default is `openresty`|openresty=apisix-base| -|artifact |False |the final name of the generated artifact, if not specified, this will be the same as `app`|artifact=apisix| -|image_base|False |the environment for packaging, if type is `rpm` the default image_base is `centos`, if type is `deb` the default image_base is `ubuntu`|image_base=centos| -|image_tag|False |the environment for packaging, it's value can be `16.04\|18.04\|20.04\|6\|7\|8`, if type is `rpm` the default image_tag is `7`, if type is `deb` the default image_tag is `20.04`|image_tag=7| -|buildx|False|if `True`, use buildx to build docker images, which may speed up GitHub Actions|buildx=True| +| Parameter | Required | Description | Example | +|-----------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------| +| type | True | it can be `deb` or `rpm` or `apk` | type=rpm | +| app | True | it can be `apisix`, `dashboard`, `apisix-base` or `apisix-runtime` | app=apisix | +| checkout | True | the code branch or tag of the app which you want to package | checkout=2.1 or checkout=v2.1 | +| version | True | the version of the package | version=10.10 | +| local_code_path | False | the path of local code diretory of apisix or dashboard, which depends on the app parameter | local_code_path=/home/vagrant/apisix | +| openresty | False | the openresty type that apisix depends on, its value can be `openresty`, `apisix-base` or `apisix-runtime`, the default is `openresty` | openresty=apisix-base | +| artifact | False | the final name of the generated artifact, if not specified, this will be the same as `app` | artifact=apisix | +| image_base | False | the environment for packaging, if type is `rpm` the default image_base is `centos`, if type is `deb` the default image_base is `ubuntu` | image_base=centos | +| image_tag | False | the environment for packaging, it's value can be `16.04\|18.04\|20.04\|6\|7\|8`, if type is `rpm` the default image_tag is `7`, if type is `deb` the default image_tag is `20.04` | image_tag=7 | +| buildx | False | if `True`, use buildx to build docker images, which may speed up GitHub Actions | buildx=True | ## Example + +### build APISIX + Packaging a Centos 7 package of Apache APISIX ```sh make package type=rpm app=apisix version=2.2 checkout=2.2 image_base=centos image_tag=7 @@ -47,6 +50,8 @@ ls output/ apisix_2.2-0~ubuntu20.04_amd64.deb ``` +### build dashboard + Packaging a Centos 7 package of Apache APISIX Dashboard ```sh make package type=rpm app=dashboard version=2.4 checkout=v2.4 image_base=centos image_tag=7 @@ -61,6 +66,8 @@ ls output/ apisix-dashboard_2.2-0~ubuntu20.04_amd64.deb ``` +### build apisix-base + Packaging a Centos 7 package of APISIX's OpenResty distribution ```sh make package type=rpm app=apisix-base version=1.0.0 image_base=centos image_tag=7 @@ -83,6 +90,30 @@ REPOSITORY TAG apache/apisix-base-apk 1.19.3.2.1 ``` +### build APISIX-runtime + +Packaging a Centos 7 package of APISIX's OpenResty distribution +```sh +make package type=rpm app=apisix-runtime version=1.0.0 image_base=centos image_tag=7 +ls output/ +apisix-runtime-1.0.0-0.el7.x86_64.rpm +``` + +Packaging an Ubuntu 20.04 package of Apache APISIX's OpenResty distribution +```sh +make package type=deb app=apisix-runtime version=1.0.0 +ls output/ +apisix-runtime_1.0.0-0~ubuntu20.04_amd64.deb +``` + +Packaging an Alpine docker image of Apache APISIX's OpenResty distribution +```sh +make package type=apk app=apisix-runtime version=1.0.0 image_base=golang image_tag=1.19-alpine +docker images +REPOSITORY TAG IMAGE ID CREATED SIZE +apache/apisix-runtime-apk 1.0.0 cd456bf03d1c 9 seconds ago 504MB +``` + ## Details - `Makefile` the entrance of the packager diff --git a/build-apisix-runtime-debug-centos7.sh b/build-apisix-runtime-debug-centos7.sh new file mode 100755 index 000000000..e7071423d --- /dev/null +++ b/build-apisix-runtime-debug-centos7.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail +set -x + +yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo +yum -y install gcc gcc-c++ patch wget git make sudo +yum -y install openresty-openssl111-debug-devel openresty-pcre-devel openresty-zlib-devel + +export openssl_prefix=/usr/local/openresty-debug/openssl111 +export zlib_prefix=/usr/local/openresty/zlib +export pcre_prefix=/usr/local/openresty/pcre + +export cc_opt="-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -I${zlib_prefix}/include -I${pcre_prefix}/include -I${openssl_prefix}/include -O0" +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" +export luajit_xcflags="-DLUAJIT_ASSERT -DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT -O0" +export OR_PREFIX=/usr/local/openresty-debug +export debug_args=--with-debug + +./build-apisix-runtime.sh diff --git a/build-apisix-runtime.sh b/build-apisix-runtime.sh new file mode 100755 index 000000000..9b395f204 --- /dev/null +++ b/build-apisix-runtime.sh @@ -0,0 +1,202 @@ +#!/usr/bin/env bash +set -euo pipefail +set -x + +version=${version:-0.0.0} + +OPENRESTY_VERSION=${OPENRESTY_VERSION:-1.21.4.2} +if [ "$OPENRESTY_VERSION" == "source" ] || [ "$OPENRESTY_VERSION" == "default" ]; then + OPENRESTY_VERSION="1.21.4.2" +fi + +if ([ $# -gt 0 ] && [ "$1" == "latest" ]) || [ "$version" == "latest" ]; then + ngx_multi_upstream_module_ver="master" + mod_dubbo_ver="master" + apisix_nginx_module_ver="main" + wasm_nginx_module_ver="main" + lua_var_nginx_module_ver="master" + grpc_client_nginx_module_ver="main" + debug_args="--with-debug" + OR_PREFIX=${OR_PREFIX:="/usr/local/openresty-debug"} +else + ngx_multi_upstream_module_ver="1.1.1" + mod_dubbo_ver="1.0.2" + apisix_nginx_module_ver="1.15.0" + wasm_nginx_module_ver="0.6.5" + lua_var_nginx_module_ver="v0.5.3" + grpc_client_nginx_module_ver="v0.4.4" + debug_args=${debug_args:-} + OR_PREFIX=${OR_PREFIX:="/usr/local/openresty"} +fi + +prev_workdir="$PWD" +repo=$(basename "$prev_workdir") +workdir=$(mktemp -d) +cd "$workdir" || exit 1 + +wget --no-check-certificate https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz +tar -zxvpf openresty-${OPENRESTY_VERSION}.tar.gz > /dev/null + +if [ "$repo" == ngx_multi_upstream_module ]; then + cp -r "$prev_workdir" ./ngx_multi_upstream_module-${ngx_multi_upstream_module_ver} +else + git clone --depth=1 -b $ngx_multi_upstream_module_ver \ + https://github.com/api7/ngx_multi_upstream_module.git \ + ngx_multi_upstream_module-${ngx_multi_upstream_module_ver} +fi + +if [ "$repo" == mod_dubbo ]; then + cp -r "$prev_workdir" ./mod_dubbo-${mod_dubbo_ver} +else + git clone --depth=1 -b $mod_dubbo_ver \ + https://github.com/api7/mod_dubbo.git \ + mod_dubbo-${mod_dubbo_ver} +fi + +if [ "$repo" == apisix-nginx-module ]; then + cp -r "$prev_workdir" ./apisix-nginx-module-${apisix_nginx_module_ver} +else + git clone --depth=1 -b $apisix_nginx_module_ver \ + https://github.com/api7/apisix-nginx-module.git \ + apisix-nginx-module-${apisix_nginx_module_ver} +fi + +if [ "$repo" == wasm-nginx-module ]; then + cp -r "$prev_workdir" ./wasm-nginx-module-${wasm_nginx_module_ver} +else + git clone --depth=1 -b $wasm_nginx_module_ver \ + https://github.com/api7/wasm-nginx-module.git \ + wasm-nginx-module-${wasm_nginx_module_ver} +fi + +if [ "$repo" == lua-var-nginx-module ]; then + cp -r "$prev_workdir" ./lua-var-nginx-module-${lua_var_nginx_module_ver} +else + git clone --depth=1 -b $lua_var_nginx_module_ver \ + https://github.com/api7/lua-var-nginx-module \ + lua-var-nginx-module-${lua_var_nginx_module_ver} +fi + +if [ "$repo" == grpc-client-nginx-module ]; then + cp -r "$prev_workdir" ./grpc-client-nginx-module-${grpc_client_nginx_module_ver} +else + git clone --depth=1 -b $grpc_client_nginx_module_ver \ + https://github.com/api7/grpc-client-nginx-module \ + grpc-client-nginx-module-${grpc_client_nginx_module_ver} +fi + +cd ngx_multi_upstream_module-${ngx_multi_upstream_module_ver} || exit 1 +./patch.sh ../openresty-${OPENRESTY_VERSION} +cd .. + +cd apisix-nginx-module-${apisix_nginx_module_ver}/patch || exit 1 +./patch.sh ../../openresty-${OPENRESTY_VERSION} +cd ../.. + +cd wasm-nginx-module-${wasm_nginx_module_ver} || exit 1 +./install-wasmtime.sh +cd .. + +cc_opt=${cc_opt:-} +ld_opt=${ld_opt:-} +luajit_xcflags=${luajit_xcflags:="-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT"} +no_pool_patch=${no_pool_patch:-} +# TODO: remove old NGX_HTTP_GRPC_CLI_ENGINE_PATH once we have released a new +# version of grpc-client-nginx-module +grpc_engine_path="-DNGX_GRPC_CLI_ENGINE_PATH=$OR_PREFIX/libgrpc_engine.so -DNGX_HTTP_GRPC_CLI_ENGINE_PATH=$OR_PREFIX/libgrpc_engine.so" + +cd openresty-${OPENRESTY_VERSION} || exit 1 + +if [[ "$OPENRESTY_VERSION" == 1.21.4.1 ]] || [[ "$OPENRESTY_VERSION" == 1.19.* ]]; then +# FIXME: remove this once 1.21.4.2 is released +rm -rf bundle/LuaJIT-2.1-20220411 +lj_ver=2.1-20230119 +wget "https://github.com/openresty/luajit2/archive/v$lj_ver.tar.gz" -O "LuaJIT-$lj_ver.tar.gz" +tar -xzf LuaJIT-$lj_ver.tar.gz +mv luajit2-* bundle/LuaJIT-2.1-20220411 +fi + +or_limit_ver=0.08 +if [ ! -d "bundle/lua-resty-limit-traffic-$or_limit_ver" ]; then + echo "ERROR: the official repository of lua-resty-limit-traffic has been updated, please sync to API7's repository." >&2 + exit 1 +else + rm -rf bundle/lua-resty-limit-traffic-$or_limit_ver + limit_ver=1.0.0 + wget "https://github.com/api7/lua-resty-limit-traffic/archive/refs/tags/v$limit_ver.tar.gz" -O "lua-resty-limit-traffic-$limit_ver.tar.gz" + tar -xzf lua-resty-limit-traffic-$limit_ver.tar.gz + mv lua-resty-limit-traffic-$limit_ver bundle/lua-resty-limit-traffic-$or_limit_ver +fi + +./configure --prefix="$OR_PREFIX" \ + --with-cc-opt="-DAPISIX_RUNTIME_VER=$version $grpc_engine_path $cc_opt" \ + --with-ld-opt="-Wl,-rpath,$OR_PREFIX/wasmtime-c-api/lib $ld_opt" \ + $debug_args \ + --add-module=../mod_dubbo-${mod_dubbo_ver} \ + --add-module=../ngx_multi_upstream_module-${ngx_multi_upstream_module_ver} \ + --add-module=../apisix-nginx-module-${apisix_nginx_module_ver} \ + --add-module=../apisix-nginx-module-${apisix_nginx_module_ver}/src/stream \ + --add-module=../apisix-nginx-module-${apisix_nginx_module_ver}/src/meta \ + --add-module=../wasm-nginx-module-${wasm_nginx_module_ver} \ + --add-module=../lua-var-nginx-module-${lua_var_nginx_module_ver} \ + --add-module=../grpc-client-nginx-module-${grpc_client_nginx_module_ver} \ + --with-poll_module \ + --with-pcre-jit \ + --without-http_rds_json_module \ + --without-http_rds_csv_module \ + --without-lua_rds_parser \ + --with-stream \ + --with-stream_ssl_module \ + --with-stream_ssl_preread_module \ + --with-http_v2_module \ + --without-mail_pop3_module \ + --without-mail_imap_module \ + --without-mail_smtp_module \ + --with-http_stub_status_module \ + --with-http_realip_module \ + --with-http_addition_module \ + --with-http_auth_request_module \ + --with-http_secure_link_module \ + --with-http_random_index_module \ + --with-http_gzip_static_module \ + --with-http_sub_module \ + --with-http_dav_module \ + --with-http_flv_module \ + --with-http_mp4_module \ + --with-http_gunzip_module \ + --with-threads \ + --with-compat \ + --with-luajit-xcflags="$luajit_xcflags" \ + $no_pool_patch \ + -j`nproc` + +make -j`nproc` +sudo make install +cd .. + +cd apisix-nginx-module-${apisix_nginx_module_ver} || exit 1 +sudo OPENRESTY_PREFIX="$OR_PREFIX" make install +cd .. + +cd wasm-nginx-module-${wasm_nginx_module_ver} || exit 1 +sudo OPENRESTY_PREFIX="$OR_PREFIX" make install +cd .. + +cd grpc-client-nginx-module-${grpc_client_nginx_module_ver} || exit 1 +sudo OPENRESTY_PREFIX="$OR_PREFIX" make install +cd .. + +# package etcdctl +ETCD_ARCH="amd64" +ETCD_VERSION=${ETCD_VERSION:-'3.5.4'} +ARCH=${ARCH:-$(uname -m | tr '[:upper:]' '[:lower:]')} + +if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then + ETCD_ARCH="arm64" +fi + +wget -q https://github.com/etcd-io/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}.tar.gz +tar xf etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}.tar.gz +# ship etcdctl under the same bin dir of openresty so we can package it easily +sudo cp etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH}/etcdctl "$OR_PREFIX"/bin/ +rm -rf etcd-v${ETCD_VERSION}-linux-${ETCD_ARCH} diff --git a/dockerfiles/Dockerfile.apisix-runtime.apk b/dockerfiles/Dockerfile.apisix-runtime.apk new file mode 100644 index 000000000..cbaa45bf6 --- /dev/null +++ b/dockerfiles/Dockerfile.apisix-runtime.apk @@ -0,0 +1,117 @@ +ARG IMAGE_BASE="alpine" +ARG IMAGE_TAG="3.15" + +FROM ${IMAGE_BASE}:${IMAGE_TAG} as build + +COPY ./utils/build-common.sh \ + ./utils/install-common.sh \ + build-apisix-runtime.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 + +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}" + + +ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin + +RUN apk add --no-cache \ + build-base \ + coreutils \ + curl \ + gd \ + gd-dev \ + geoip \ + geoip-dev \ + libxslt \ + libxslt-dev \ + linux-headers \ + make \ + perl-dev \ + readline-dev \ + zlib \ + zlib-dev \ + unzip \ + git \ + sudo \ + bash \ + libstdc++ + +# install latest Rust to build wasmtime +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + +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://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} +RUN cd /tmp \ + && curl --version \ + && source /root/.cargo/env \ + && ./build-common.sh build_apisix_runtime_apk \ + && rm /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.a \ + && rm /usr/local/openresty/wasmtime-c-api/lib/libwasmtime.d \ + && /usr/local/openresty/bin/openresty -V + + +FROM ${IMAGE_BASE}:${IMAGE_TAG} as prod + +COPY --from=build /usr/local/openresty /usr/local/openresty + +RUN apk add --no-cache \ + gd \ + geoip \ + libxslt \ + zlib \ + libstdc++ \ + && apk add --no-cache --virtual .build-deps \ + curl \ + make \ + sudo \ + && curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | sh - \ + && apk del .build-deps + + +ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin + +CMD /bin/sh diff --git a/dockerfiles/Dockerfile.apisix-runtime.deb b/dockerfiles/Dockerfile.apisix-runtime.deb new file mode 100644 index 000000000..6a560c781 --- /dev/null +++ b/dockerfiles/Dockerfile.apisix-runtime.deb @@ -0,0 +1,30 @@ +ARG IMAGE_BASE="debian" +ARG IMAGE_TAG="bullseye-slim" + +FROM ${IMAGE_BASE}:${IMAGE_TAG} as build + +COPY ./utils/build-common.sh /tmp/build-common.sh +COPY build-apisix-runtime.sh /tmp/build-apisix-runtime.sh +COPY ./utils/determine-dist.sh /tmp/determine-dist.sh + +WORKDIR /tmp + +ARG VERSION +ARG IMAGE_BASE +ARG IMAGE_TAG +ARG BUILD_LATEST + +ENV IMAGE_BASE=${IMAGE_BASE} +ENV IMAGE_TAG=${IMAGE_TAG} +ENV version=${VERSION} +ENV build_latest=${BUILD_LATEST:-} + +RUN ./build-common.sh build_apisix_runtime_deb ${build_latest} \ + # determine dist and write it into /tmp/dist file + && /tmp/determine-dist.sh + +FROM ${IMAGE_BASE}:${IMAGE_TAG} as prod + +COPY --from=build /usr/local /usr/local +COPY --from=build /tmp/dist /tmp/dist +COPY --from=build /tmp/codename /tmp/codename diff --git a/dockerfiles/Dockerfile.apisix-runtime.rpm b/dockerfiles/Dockerfile.apisix-runtime.rpm new file mode 100644 index 000000000..a5154a1c9 --- /dev/null +++ b/dockerfiles/Dockerfile.apisix-runtime.rpm @@ -0,0 +1,33 @@ +ARG IMAGE_BASE="centos" +ARG IMAGE_TAG="7" + +FROM ${IMAGE_BASE}:${IMAGE_TAG} + +# Note: The duplication around the rpm series dockerfile here +# is used for reuse the container layer cache +RUN if [[ $(rpm --eval '%{centos_ver}') == "8" ]]; then \ + sed -re "s/^#?\s*(mirrorlist)/#\1/g" \ + -e "s|^#?\s*baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" \ + -i /etc/yum.repos.d/CentOS-Linux-*; \ + dnf install -y centos-release-stream; \ + dnf swap -y centos-{linux,stream}-repos; \ + dnf distro-sync -y; \ + fi + +COPY ./utils/build-common.sh /tmp/build-common.sh +COPY build-apisix-runtime.sh /tmp/build-apisix-runtime.sh +COPY ./utils/determine-dist.sh /tmp/determine-dist.sh + +WORKDIR /tmp + +ARG VERSION +ARG IMAGE_BASE +ARG IMAGE_TAG + +ENV IMAGE_BASE=${IMAGE_BASE} +ENV IMAGE_TAG=${IMAGE_TAG} +ENV version=${VERSION} + +RUN ./build-common.sh build_apisix_runtime_rpm \ + # determine dist and write it into /tmp/dist file + && /tmp/determine-dist.sh diff --git a/dockerfiles/Dockerfile.package.apisix-runtime b/dockerfiles/Dockerfile.package.apisix-runtime new file mode 100644 index 000000000..2a6513510 --- /dev/null +++ b/dockerfiles/Dockerfile.package.apisix-runtime @@ -0,0 +1,24 @@ +ARG VERSION +ARG PACKAGE_TYPE + +FROM apache/apisix-runtime-${PACKAGE_TYPE}:${VERSION} AS APISIX-RUNTIME +FROM api7/fpm + +ARG ITERATION +ARG PACKAGE_VERSION +ARG PACKAGE_TYPE +ARG ARTIFACT + +ENV ITERATION=${ITERATION} +ENV PACKAGE_VERSION=${PACKAGE_VERSION} +ENV PACKAGE_TYPE=${PACKAGE_TYPE} +ENV ARTIFACT=${ARTIFACT} + +COPY --from=APISIX-RUNTIME /usr/local/openresty /tmp/build/output/openresty +COPY --from=APISIX-RUNTIME /tmp/dist /tmp/dist +COPY --from=APISIX-RUNTIME /tmp/codename /tmp/codename +COPY package-apisix-runtime.sh /package-apisix-runtime.sh +COPY post-install-apisix-runtime.sh /post-install-apisix-runtime.sh +COPY usr /usr + +RUN /package-apisix-runtime.sh diff --git a/package-apisix-runtime.sh b/package-apisix-runtime.sh new file mode 100755 index 000000000..2dbc2ffe9 --- /dev/null +++ b/package-apisix-runtime.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -euo pipefail +set -x +mkdir /output +dist=$(cat /tmp/dist) +codename=$(cat /tmp/codename) + +# Determine the name of artifact +# The defaut is apisix-runtime +artifact="apisix-runtime" +if [ "$ARTIFACT" != "0" ]; then + artifact=${ARTIFACT} +fi + +ARCH=${ARCH:-`(uname -m | tr '[:upper:]' '[:lower:]')`} + +openresty_zlib_version="1.2.12-1" +openresty_openssl111_version="1.1.1n-1" +openresty_pcre_version="8.45-1" +if [ "$PACKAGE_TYPE" == "deb" ]; then + pkg_suffix="${codename}1" + openresty_zlib_version="$openresty_zlib_version~$pkg_suffix" + openresty_openssl111_version="$openresty_openssl111_version~$pkg_suffix" + openresty_pcre_version="$openresty_pcre_version~$pkg_suffix" +fi + +fpm -f -s dir -t "$PACKAGE_TYPE" \ + --"$PACKAGE_TYPE"-dist "$dist" \ + -n "$artifact" \ + -a "$(uname -i)" \ + -v "$PACKAGE_VERSION" \ + --iteration "$ITERATION" \ + -x openresty/zlib \ + -x openresty/openssl111 \ + -x openresty/pcre \ + -d "openresty-zlib >= $openresty_zlib_version" \ + -d "openresty-openssl111 >= $openresty_openssl111_version" \ + -d "openresty-pcre >= $openresty_pcre_version" \ + --post-install post-install-apisix-runtime.sh \ + --description "APISIX's OpenResty distribution." \ + --license "ASL 2.0" \ + -C /tmp/build/output \ + -p /output \ + --url 'http://apisix.apache.org/' \ + --conflicts openresty \ + --config-files usr/lib/systemd/system/openresty.service \ + --prefix=/usr/local + +PACKAGE_ARCH="amd64" +if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then + PACKAGE_ARCH="arm64" +fi + +if [ "$PACKAGE_TYPE" == "deb" ]; then + # Rename deb file with adding $DIST section + mv /output/apisix-runtime_"${PACKAGE_VERSION}"-"${ITERATION}"_"${PACKAGE_ARCH}".deb /output/apisix-runtime_"${PACKAGE_VERSION}"-"${ITERATION}"~"${dist}"_"${PACKAGE_ARCH}".deb +fi diff --git a/package-apisix.sh b/package-apisix.sh index ab597624b..1f9a93e0f 100755 --- a/package-apisix.sh +++ b/package-apisix.sh @@ -48,25 +48,47 @@ then artifact=${ARTIFACT} fi -fpm -f -s dir -t "$PACKAGE_TYPE" \ - --"$PACKAGE_TYPE"-dist "$dist" \ - -n "$artifact" \ - -a "$(uname -i)" \ - -v "$PACKAGE_VERSION" \ - --iteration "$ITERATION" \ - -d "$OPENRESTY >= $min_or_version" \ - -d "$OPENRESTY < $max_or_version" \ - -d "$dep_ldap" \ - -d "$dep_pcre" \ - -d "$dep_which" \ - --description 'Apache APISIX is a distributed gateway for APIs and Microservices, focused on high performance and reliability.' \ - --license "ASL 2.0" \ - -C /tmp/build/output/apisix \ - -p /output \ - --url 'http://apisix.apache.org/' \ - --config-files usr/lib/systemd/system/apisix.service \ - --config-files usr/local/apisix/conf/config.yaml \ - --config-files usr/local/apisix/conf/config-default.yaml +if [ "$OPENRESTY" == "apisix-runtime" ] +then + fpm -f -s dir -t "$PACKAGE_TYPE" \ + --"$PACKAGE_TYPE"-dist "$dist" \ + -n "$artifact" \ + -a "$(uname -i)" \ + -v "$PACKAGE_VERSION" \ + --iteration "$ITERATION" \ + -d "$OPENRESTY == $VERSION" \ + -d "$dep_ldap" \ + -d "$dep_pcre" \ + -d "$dep_which" \ + --description 'Apache APISIX is a distributed gateway for APIs and Microservices, focused on high performance and reliability.' \ + --license "ASL 2.0" \ + -C /tmp/build/output/apisix \ + -p /output \ + --url 'http://apisix.apache.org/' \ + --config-files usr/lib/systemd/system/apisix.service \ + --config-files usr/local/apisix/conf/config.yaml \ + --config-files usr/local/apisix/conf/config-default.yaml +else + fpm -f -s dir -t "$PACKAGE_TYPE" \ + --"$PACKAGE_TYPE"-dist "$dist" \ + -n "$artifact" \ + -a "$(uname -i)" \ + -v "$PACKAGE_VERSION" \ + --iteration "$ITERATION" \ + -d "$OPENRESTY >= $min_or_version" \ + -d "$OPENRESTY < $max_or_version" \ + -d "$dep_ldap" \ + -d "$dep_pcre" \ + -d "$dep_which" \ + --description 'Apache APISIX is a distributed gateway for APIs and Microservices, focused on high performance and reliability.' \ + --license "ASL 2.0" \ + -C /tmp/build/output/apisix \ + -p /output \ + --url 'http://apisix.apache.org/' \ + --config-files usr/lib/systemd/system/apisix.service \ + --config-files usr/local/apisix/conf/config.yaml \ + --config-files usr/local/apisix/conf/config-default.yaml +fi PACKAGE_ARCH="amd64" if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then diff --git a/post-install-apisix-runtime.sh b/post-install-apisix-runtime.sh new file mode 100644 index 000000000..1f91343d0 --- /dev/null +++ b/post-install-apisix-runtime.sh @@ -0,0 +1,3 @@ +#!/bin/bash +ln -sf /usr/local/openresty/bin/resty /usr/bin/resty +ln -sf /usr/local/openresty/bin/openresty /usr/bin/openresty \ No newline at end of file diff --git a/utils/build-common.sh b/utils/build-common.sh index e4a9096a9..7f868fe91 100755 --- a/utils/build-common.sh +++ b/utils/build-common.sh @@ -67,6 +67,68 @@ build_apisix_base_apk() { ${BUILD_PATH}/build-apisix-base.sh } +build_apisix_runtime_rpm() { + if [[ $(rpm --eval '%{centos_ver}') == "7" ]]; then + yum -y install centos-release-scl + yum -y install devtoolset-9 patch wget git make sudo + set +eu + source scl_source enable devtoolset-9 + set -eu + elif [[ $(rpm --eval '%{centos_ver}') == "8" ]]; then + dnf install -y gcc-toolset-9-toolchain patch wget git make sudo + dnf install -y yum-utils + set +eu + source /opt/rh/gcc-toolset-9/enable + set -eu + else + dnf install -y yum-utils + yum -y install --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms gcc gcc-c++ patch wget git make sudo xz + fi + + command -v gcc + gcc --version + + yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo + yum -y install openresty-openssl111-devel openresty-pcre-devel openresty-zlib-devel + + export_openresty_variables + ${BUILD_PATH}/build-apisix-runtime.sh +} + +build_apisix_runtime_deb() { + arch_path="" + if [[ $ARCH == "arm64" ]] || [[ $ARCH == "aarch64" ]]; then + arch_path="arm64/" + fi + DEBIAN_FRONTEND=noninteractive apt-get update --fix-missing + DEBIAN_FRONTEND=noninteractive apt-get install -y sudo git libreadline-dev lsb-release libssl-dev perl build-essential + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends wget gnupg ca-certificates + wget -O - https://openresty.org/package/pubkey.gpg | apt-key add - + + if [[ $IMAGE_BASE == "ubuntu" ]]; then + echo "deb http://openresty.org/package/${arch_path}ubuntu $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/openresty.list + fi + + if [[ $IMAGE_BASE == "debian" ]]; then + echo "deb http://openresty.org/package/${arch_path}debian $(lsb_release -sc) openresty" | tee /etc/apt/sources.list.d/openresty.list + fi + + DEBIAN_FRONTEND=noninteractive apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y openresty-openssl111-dev openresty-pcre-dev openresty-zlib-dev + + export_openresty_variables + # fix OR_PREFIX + if [[ $build_latest == "latest" ]]; then + unset OR_PREFIX + fi + ${BUILD_PATH}/build-apisix-runtime.sh ${build_latest} +} + +build_apisix_runtime_apk() { + export_openresty_variables + ${BUILD_PATH}/build-apisix-runtime.sh +} + export_openresty_variables() { export openssl_prefix=/usr/local/openresty/openssl111 export zlib_prefix=/usr/local/openresty/zlib @@ -89,4 +151,13 @@ build_apisix_base_deb) build_apisix_base_apk) build_apisix_base_apk ;; +build_apisix_runtime_rpm) + build_apisix_runtime_rpm + ;; +build_apisix_runtime_deb) + build_apisix_runtime_deb + ;; +build_apisix_runtime_apk) + build_apisix_runtime_apk + ;; esac