You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by mo...@apache.org on 2023/06/12 09:36:49 UTC

[apisix] branch master updated: feat: Add CI tests with Redhat UBI (#9552)

This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 36169610d feat: Add CI tests with Redhat UBI (#9552)
36169610d is described below

commit 36169610d27fd0d6b9eb18859c49d4ceabf81c04
Author: Ashish Tiwari <as...@gmail.com>
AuthorDate: Mon Jun 12 15:06:39 2023 +0530

    feat: Add CI tests with Redhat UBI (#9552)
---
 .github/workflows/redhat-ci.yaml | 157 +++++++++++++++++++++++++++++++++++++++
 ci/redhat-ci.sh                  | 107 ++++++++++++++++++++++++++
 2 files changed, 264 insertions(+)

diff --git a/.github/workflows/redhat-ci.yaml b/.github/workflows/redhat-ci.yaml
new file mode 100644
index 000000000..cf03ae002
--- /dev/null
+++ b/.github/workflows/redhat-ci.yaml
@@ -0,0 +1,157 @@
+name: CI Redhat UBI - Daily
+
+on:
+  schedule:
+    - cron: "0 0 * * *"
+  pull_request:
+    branches: [master]
+    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:
+  test_apisix:
+    name: run ci on redhat ubi
+    runs-on: ubuntu-20.04
+    timeout-minutes: 90
+    strategy:
+      fail-fast: false
+      matrix:
+        test_dir:
+          - t/plugin/[a-k]*
+          - t/plugin/[l-z]*
+          - t/admin t/cli t/config-center-yaml t/control t/core t/debug t/deployment t/discovery t/error_page t/misc
+          - t/node t/pubsub t/router t/script t/secret t/stream-node t/utils t/wasm t/xds-library
+
+    steps:
+    - name: Check out code
+      uses: actions/checkout@v3.2.0
+      with:
+        submodules: recursive
+
+    - name: Cache deps
+      uses: actions/cache@v3
+      env:
+        cache-name: cache-deps
+      with:
+        path: deps
+        key: ${{ runner.os }}-${{ env.cache-name }}-ubi8.6-${{ hashFiles('rockspec/apisix-master-0.rockspec') }}
+
+    - name: Extract branch name
+      if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
+      id: branch_env
+      shell: bash
+      run: |
+        echo "version=${GITHUB_REF##*/}" >>$GITHUB_OUTPUT
+
+    - name: Extract test type
+      shell: bash
+      id: test_env
+      run: |
+        test_dir="${{ matrix.test_dir }}"
+        if [[ $test_dir =~ 't/plugin' ]]; then
+          echo "type=plugin" >>$GITHUB_OUTPUT
+        fi
+        if [[ $test_dir =~ 't/admin ' ]]; then
+          echo "type=first" >>$GITHUB_OUTPUT
+        fi
+        if [[ $test_dir =~ ' t/xds-library' ]]; then
+          echo "type=last" >>$GITHUB_OUTPUT
+        fi
+
+    - name: Free disk space
+      run: |
+        bash ./ci/free_disk_space.sh
+
+    - name: Linux launch common services
+      run: |
+        make ci-env-up project_compose_ci=ci/pod/docker-compose.common.yml
+        sudo ./ci/init-common-test-service.sh
+
+    - name: Build rpm package
+      if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
+      run: |
+        export VERSION=${{ steps.branch_env.outputs.version }}
+        sudo gem install --no-document fpm
+        git clone --depth 1 https://github.com/api7/apisix-build-tools.git
+
+        # move codes under build tool
+        mkdir ./apisix-build-tools/apisix
+        for dir in `ls|grep -v "^apisix-build-tools$"`;do cp -r $dir ./apisix-build-tools/apisix/;done
+
+        cd apisix-build-tools
+        make package type=rpm app=apisix version=${VERSION} checkout=release/${VERSION} image_base=ubi image_tag=8.6 local_code_path=./apisix
+        cd ..
+        rm -rf $(ls -1 --ignore=apisix-build-tools --ignore=t --ignore=utils --ignore=ci --ignore=Makefile --ignore=rockspec)
+
+    - name: Build xDS library
+      if: steps.test_env.outputs.type == 'last'
+      run: |
+        cd t/xds-library
+        go build -o libxds.so -buildmode=c-shared main.go export.go
+
+    - name: Run redhat docker and mapping apisix into container
+      env:
+        TEST_FILE_SUB_DIR: ${{ matrix.test_dir }}
+      run: |
+        docker run -itd -v ${{ github.workspace }}:/apisix --env TEST_FILE_SUB_DIR="$TEST_FILE_SUB_DIR" --name ubiInstance --net="host" --dns 8.8.8.8 --dns-search apache.org registry.access.redhat.com/ubi8/ubi:8.6 /bin/bash
+
+    - name: Cache images
+      id: cache-images
+      uses: actions/cache@v3
+      env:
+        cache-name: cache-apisix-docker-images
+      with:
+        path: docker-images-backup
+        key: ${{ runner.os }}-${{ env.cache-name }}-${{ steps.test_env.outputs.type }}-${{ hashFiles(format('./ci/pod/docker-compose.{0}.yml', steps.test_env.outputs.type )) }}
+
+    - if: ${{ steps.cache-images.outputs.cache-hit == 'true' }}
+      name: Load saved docker images
+      run: |
+        if [[ -f docker-images-backup/apisix-images.tar ]]; then
+          [[ ${{ steps.test_env.outputs.type }} != first ]] && sudo ./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh before
+          docker load --input docker-images-backup/apisix-images.tar
+          rm docker-images-backup/apisix-images.tar
+          make ci-env-up project_compose_ci=ci/pod/docker-compose.${{ steps.test_env.outputs.type }}.yml
+          echo "loaded docker images"
+          if [[ ${{ steps.test_env.outputs.type }} != first ]]; then
+            sudo ./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh after
+          fi
+        fi
+    - if: ${{ steps.cache-images.outputs.cache-hit != 'true' }}
+      name: Linux launch services
+      run: |
+        [[ ${{ steps.test_env.outputs.type }} != first ]] && sudo ./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh before
+        [[ ${{ steps.test_env.outputs.type }} == plugin ]] && ./ci/pod/openfunction/build-function-image.sh
+        make ci-env-up project_compose_ci=ci/pod/docker-compose.${{ steps.test_env.outputs.type }}.yml
+        [[ ${{ steps.test_env.outputs.type }} != first ]] && sudo ./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh after
+        echo "Linux launch services, done."
+
+    - name: Install dependencies
+      run: |
+        docker exec ubiInstance bash -c "cd apisix && chmod +x ./ci/redhat-ci.sh && ./ci/redhat-ci.sh install_dependencies"
+
+    - name: Install rpm package
+      if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
+      run: |
+        docker exec ubiInstance bash -c "cd apisix && rpm -iv --prefix=/apisix ./apisix-build-tools/output/apisix-${{ steps.branch_env.outputs.version }}-0.ubi8.6.x86_64.rpm"
+        # Dependencies are attached with rpm, so revert `make deps`
+        docker exec ubiInstance bash -c "cd apisix && rm -rf deps"
+        docker exec ubiInstance bash -c "cd apisix && mv usr/bin . && mv usr/local/apisix/* ."
+
+    - name: Run test cases
+      run: |
+        docker exec ubiInstance bash -c "cd apisix && chmod +x ./ci/redhat-ci.sh && ./ci/redhat-ci.sh run_case"
+
+    - if: ${{ steps.cache-images.outputs.cache-hit != 'true' }}
+      name: Save docker images
+      run: |
+        echo "start backing up, $(date)"
+        bash ./ci/backup-docker-images.sh ${{ steps.test_env.outputs.type }}
+        echo "backup done, $(date)"
diff --git a/ci/redhat-ci.sh b/ci/redhat-ci.sh
new file mode 100755
index 000000000..c1bd6d8f0
--- /dev/null
+++ b/ci/redhat-ci.sh
@@ -0,0 +1,107 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./ci/common.sh
+install_dependencies() {
+    export_or_prefix
+
+    # install build & runtime deps
+    yum install -y --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms \
+    wget tar gcc automake autoconf libtool make unzip git sudo openldap-devel hostname \
+    which ca-certificates openssl-devel
+
+    # install newer curl
+    yum makecache
+    yum install -y libnghttp2-devel
+    install_curl
+
+    # 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
+    yum install -y openresty openresty-debug openresty-openssl111-debug-devel pcre pcre-devel xz
+
+    # install luarocks
+    ./utils/linux-install-luarocks.sh
+
+    # install etcdctl
+    ./ci/linux-install-etcd-client.sh
+
+    # install vault cli capabilities
+    install_vault_cli
+
+    # install test::nginx
+    yum install -y --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms cpanminus perl
+    cpanm --notest Test::Nginx IPC::Run > build.log 2>&1 || (cat build.log && exit 1)
+
+    # add go1.15 binary to the path
+    mkdir build-cache
+    pushd build-cache/
+    # Go is required inside the container.
+    wget -q https://golang.org/dl/go1.17.linux-amd64.tar.gz && tar -xf go1.17.linux-amd64.tar.gz
+    export PATH=$PATH:$(pwd)/go/bin
+    popd
+    # install and start grpc_server_example
+    pushd t/grpc_server_example
+
+    CGO_ENABLED=0 go build
+    ./grpc_server_example \
+        -grpc-address :50051 -grpcs-address :50052 -grpcs-mtls-address :50053 -grpc-http-address :50054 \
+        -crt ../certs/apisix.crt -key ../certs/apisix.key -ca ../certs/mtls_ca.crt \
+        > grpc_server_example.log 2>&1 || (cat grpc_server_example.log && exit 1)&
+
+    popd
+    # wait for grpc_server_example to fully start
+    sleep 3
+
+    # installing grpcurl
+    install_grpcurl
+
+    # install nodejs
+    install_nodejs
+
+    # install rust
+    install_rust
+
+    # grpc-web server && client
+    pushd t/plugin/grpc-web
+    ./setup.sh
+    # back to home directory
+    popd
+
+    # install dependencies
+    git clone https://github.com/openresty/test-nginx.git test-nginx
+    create_lua_deps
+}
+
+run_case() {
+    export_or_prefix
+    make init
+    set_coredns
+    # run test cases
+    FLUSH_ETCD=1 prove --timer -Itest-nginx/lib -I./ -r ${TEST_FILE_SUB_DIR} | tee /tmp/test.result
+    rerun_flaky_tests /tmp/test.result
+}
+
+case_opt=$1
+case $case_opt in
+    (install_dependencies)
+        install_dependencies
+        ;;
+    (run_case)
+        run_case
+        ;;
+esac