From ded10f4e0bfe83d9b4c7cb209324d31bd806cb50 Mon Sep 17 00:00:00 2001 From: TheR1sing3un <87409330+TheR1sing3un@users.noreply.github.com> Date: Fri, 17 Nov 2023 16:55:29 +0800 Subject: [PATCH] feat(store): add e2e action (#310) Signed-off-by: TheR1sing3un Signed-off-by: wangxye Co-authored-by: wangxye --- .github/workflows/build-ci.yml | 18 +- .github/workflows/pr-e2e-test.yml | 245 ++++++++++++++++++ distribution/docker/Dockerfile-ci | 2 +- .../templates/broker/statefulset.yaml | 4 +- .../charts/automq-for-rocketmq/values.yaml | 8 +- .../helm/deploy/helm_sample_values.yaml | 2 +- distribution/helm/deploy/mysql.yaml | 5 +- distribution/helm/test-ci.sh | 62 +++++ 8 files changed, 333 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/pr-e2e-test.yml create mode 100644 distribution/helm/test-ci.sh diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index fa81309e0..1ed107a59 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -1,4 +1,4 @@ -name: Build with Maven +name: BUILD-CI on: pull_request: @@ -24,5 +24,17 @@ jobs: uses: ScribeMD/docker-cache@0.3.6 with: key: docker-${{ runner.os }} - - name: Build with Maven - run: mvn clean install -U + - name: Build distribution tar + run: | + mvn -Prelease-all clean install -U + - uses: actions/upload-artifact@v3 + name: Upload distribution tar + with: + name: rocketmq + path: distribution/target/automq-for-rocketmq.zip + + pr-e2e: + name: PR e2e test + uses: ./.github/workflows/pr-e2e-test.yml + secrets: inherit + needs: dist-tar \ No newline at end of file diff --git a/.github/workflows/pr-e2e-test.yml b/.github/workflows/pr-e2e-test.yml new file mode 100644 index 000000000..4903c40ab --- /dev/null +++ b/.github/workflows/pr-e2e-test.yml @@ -0,0 +1,245 @@ +name: E2E test for pull request + +# read-write repo token +# access to secrets +#on: +# workflow_run: +# workflows: ["BUILD-CI"] +# types: +# - completed +# branches: ['**'] +on: + workflow_call: + + +env: + HELM_NAME: automq-for-rocketmq + DOCKER_REPO: automqinc/rocketmq_e2e + +jobs: + docker: + runs-on: ubuntu-latest + if: always() +# if: > +# github.event.workflow_run.event == 'pull_request' && +# github.event.workflow_run.conclusion == 'success' + timeout-minutes: 30 + strategy: + matrix: + java-version: ["17"] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: 'Download artifact' + uses: actions/download-artifact@v2 + with: + name: rocketmq + path: ${{github.workspace}}/distribution/target + - name: docker-login + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and save docker images + id: build-images + working-directory: ./distribution/docker + run: | + mkdir versionlist + full_node_version=$(git ls-remote --tags | awk -F '/' 'END{print $3}') + commit_version=$(git rev-parse --short HEAD) + version=${full_node_version}-${commit_version} + touch versionlist/"${version}" + echo "version=${version}" + ls versionlist/ + sh build-ci.sh ${DOCKER_REPO} ${version} + docker push ${DOCKER_REPO}:${version} + - uses: actions/upload-artifact@v3 + name: Upload distribution versionlist + with: + name: versionlist + path: ./distribution/docker/versionlist/* + + list-version: + if: always() + name: List version + needs: [docker] + runs-on: ubuntu-latest + timeout-minutes: 30 + outputs: + version-json: ${{ steps.show_versions.outputs.version-json }} + steps: + - uses: actions/download-artifact@v3 + name: Download versionlist + with: + name: versionlist + path: versionlist + - name: Show versions + id: show_versions + run: | + a=(`ls versionlist`) + printf '%s\n' "${a[@]}" | jq -R . | jq -s . + echo version-json=`printf '%s\n' "${a[@]}" | jq -R . | jq -s .` >> $GITHUB_OUTPUT + deploy: + if: ${{ success() }} + name: Deploy RocketMQ + needs: [list-version,docker] + runs-on: private-k3s + timeout-minutes: 60 + outputs: + namespace: ${{ steps.create_namespace.outputs.namespace }} + strategy: + matrix: + version: ${{ fromJSON(needs.list-version.outputs.version-json) }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: true + - name: Get kubeconfig + env: + KUBECONFIG_FILE: '${{ secrets.KUBE_CONFIG }}' + run: | + mkdir -p ~/.kube + echo $KUBECONFIG_FILE | base64 -d > ~/.kube/config + - name: Create Namespace + id: create_namespace + env: + JOB_INDEX: ${{ strategy.job-index }} + run: | + REPO_NAME=`echo ${GITHUB_REPOSITORY#*/} | sed -e "s/\//-/g" | cut -c1-36 | tr '[A-Z]' '[a-z]'` + NAMESPACE=${REPO_NAME}-${GITHUB_RUN_ID}-${JOB_INDEX} + kubectl create namespace $NAMESPACE + echo "namespace=$NAMESPACE" >> $GITHUB_OUTPUT + - name: Deploy RocketMQ + working-directory: distribution/helm + env: + NAMESPACE: ${{ steps.create_namespace.outputs.namespace }} + DOCKER_REPO: ${{ env.DOCKER_REPO }} + run: | + sh deploy-ci.sh ${DOCKER_REPO} ${{ matrix.version }} ${NAMESPACE} + + test-e2e-grpc-java: + if: ${{ success() }} + name: Test E2E grpc java + needs: [list-version, deploy] + runs-on: private-k3s + timeout-minutes: 60 + strategy: + matrix: + version: ${{ fromJSON(needs.list-version.outputs.version-json) }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install flatc + run: sudo bash install_flatc.sh + - name: Build rocketmq dependency + run: | + mvn clean install -U -DskipTests + - uses: actions/checkout@v3 + if: always() + with: + repository: AutoMQ/rocketmq-e2e + ref: master + path: rocketmq-e2e + token: ${{ secrets.PAT_E2E }} + - name: e2e test + env: + HELM_NAME: ${{ env.HELM_NAME }} + NAMESPACE: ${{ needs.deploy.outputs.namespace }} + run: | + cd rocketmq-e2e + cd java/e2e && mvn -B test -DnamesrvAddr=${HELM_NAME}-broker.${NAMESPACE}.svc.pve1.local:8081 -DendPoint=${HELM_NAME}-broker.${NAMESPACE}.svc.pve1.local:8081 + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + report_paths: '**/surefire-reports/TEST-*.xml' + annotate_only: true + include_passed: true + detailed_summary: true + - uses: actions/upload-artifact@v3 + if: always() + name: Upload test log + with: + name: test-e2e-grpc-java-log.txt + path: testlog.txt + + test-e2e-remoting-java: + if: ${{ success() }} + name: Test E2E remoting java + needs: [ list-version, deploy ] + runs-on: private-k3s + timeout-minutes: 60 + strategy: + matrix: + version: ${{ fromJSON(needs.list-version.outputs.version-json) }} + steps: + - name: Delay + env: + DELAY_SECONDS: 30 + run: | + sleep $DELAY_SECONDS + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install flatc + run: sudo bash install_flatc.sh + - name: Build rocketmq dependency + run: | + mvn clean install -U -DskipTests + - uses: actions/checkout@v3 + if: always() + with: + repository: AutoMQ/rocketmq-e2e + ref: master + path: rocketmq-e2e + token: ${{ secrets.PAT_E2E }} + - name: e2e test + env: + HELM_NAME: ${{ env.HELM_NAME }} + NAMESPACE: ${{ needs.deploy.outputs.namespace }} + run: | + cd rocketmq-e2e + cd java/e2e-v4 && mvn -B test -DnamesrvAddr=${HELM_NAME}-broker.${NAMESPACE}.svc.pve1.local:8081 + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + report_paths: '**/surefire-reports/TEST-*.xml' + annotate_only: true + include_passed: true + detailed_summary: true + - uses: actions/upload-artifact@v3 + if: always() + name: Upload test log + with: + name: test-e2e-remoting-java-log.txt + path: testlog.txt + + clean: + if: always() + name: Clean + needs: [deploy, list-version, test-e2e-grpc-java, test-e2e-remoting-java] + runs-on: private-k3s + timeout-minutes: 60 + strategy: + matrix: + version: ${{ fromJSON(needs.list-version.outputs.version-json) }} + steps: + - uses: apache/rocketmq-test-tool@7d84d276ad7755b1dc5cf9657a7a9bff6ae6d288 + name: clean + with: + action: "clean" + ask-config: "${{ secrets.KUBE_CONFIG }}" + test-version: "${{ matrix.version }}" + job-id: ${{ strategy.job-index }} + - name: clean Rocketmq + working-directory: distribution/helm + env: + NAMESPACE: ${{ needs.deploy.outputs.namespace }} + DOCKER_REPO: ${{ env.DOCKER_REPO }} + run: | + sh clean-ci.sh ${NAMESPACE} diff --git a/distribution/docker/Dockerfile-ci b/distribution/docker/Dockerfile-ci index 8f6c53838..3039688d4 100644 --- a/distribution/docker/Dockerfile-ci +++ b/distribution/docker/Dockerfile-ci @@ -34,7 +34,7 @@ ENV ROCKETMQ_VERSION ${version} ARG ROCKETMQ_DIR ENV ROCKETMQ_NAME automq-for-rocketmq -ENV ROCKETMQ_HOME /home/rocketmq/${ROCKETMQ_NAME}-${ROCKETMQ_VERSION} +ENV ROCKETMQ_HOME /home/rocketmq/${ROCKETMQ_NAME} WORKDIR ${ROCKETMQ_HOME} diff --git a/distribution/helm/charts/automq-for-rocketmq/templates/broker/statefulset.yaml b/distribution/helm/charts/automq-for-rocketmq/templates/broker/statefulset.yaml index 2be096120..2af464242 100644 --- a/distribution/helm/charts/automq-for-rocketmq/templates/broker/statefulset.yaml +++ b/distribution/helm/charts/automq-for-rocketmq/templates/broker/statefulset.yaml @@ -38,7 +38,7 @@ spec: imagePullPolicy: {{ $.Values.broker.image.pullPolicy }} {{- end }} command: [ "/bin/sh" ] - args: [ "-c", "./run-server.sh com.automq.rocketmq.broker.BrokerStartup -c /home/rocketmq/automq-for-rocketmq-5.1.3/conf/broker/$(CLUSTER_NAME)-$(POD_NAME)" ] + args: [ "-c", "./run-server.sh com.automq.rocketmq.broker.BrokerStartup -c /home/rocketmq/automq-for-rocketmq/conf/broker/$(CLUSTER_NAME)-$(POD_NAME)" ] env: - name: POD_NAME valueFrom: @@ -81,7 +81,7 @@ spec: resources: {{- toYaml .Values.broker.resources | nindent 12 }} volumeMounts: - - mountPath: /home/rocketmq/automq-for-rocketmq-5.1.3/conf/broker + - mountPath: /home/rocketmq/automq-for-rocketmq/conf/broker name: broker-config - mountPath: /root/logs/rocketmqlogs name: broker-storage diff --git a/distribution/helm/charts/automq-for-rocketmq/values.yaml b/distribution/helm/charts/automq-for-rocketmq/values.yaml index a4bcf755a..52ff961bc 100644 --- a/distribution/helm/charts/automq-for-rocketmq/values.yaml +++ b/distribution/helm/charts/automq-for-rocketmq/values.yaml @@ -76,11 +76,11 @@ broker: jvmMemory: " -Xms4g -Xmx4g -Xmn2g -XX:MaxDirectMemorySize=8g " resources: limits: - cpu: 2 - memory: 4Gi + cpu: 4 + memory: 8Gi requests: - cpu: 2 - memory: 4Gi + cpu: 4 + memory: 8Gi nodeSelector: { } diff --git a/distribution/helm/deploy/helm_sample_values.yaml b/distribution/helm/deploy/helm_sample_values.yaml index 3d7c4f2ff..5000de5d8 100644 --- a/distribution/helm/deploy/helm_sample_values.yaml +++ b/distribution/helm/deploy/helm_sample_values.yaml @@ -14,7 +14,7 @@ # limitations under the License. broker: - replicaCount: 2 + replicaCount: 1 conf: clusterNameOverride: "automq" s3Stream: diff --git a/distribution/helm/deploy/mysql.yaml b/distribution/helm/deploy/mysql.yaml index cc5be129a..b35d677e2 100644 --- a/distribution/helm/deploy/mysql.yaml +++ b/distribution/helm/deploy/mysql.yaml @@ -21,7 +21,8 @@ image: auth: rootPassword: "passward" - database: "metadata" + createDatabase: true + database: metadata service: type: LoadBalancer @@ -33,4 +34,4 @@ primary: extraVolumes: | - name: init configMap: - name: mysql-initdb-config + name: mysql-initdb-config \ No newline at end of file diff --git a/distribution/helm/test-ci.sh b/distribution/helm/test-ci.sh new file mode 100644 index 000000000..dacec8abd --- /dev/null +++ b/distribution/helm/test-ci.sh @@ -0,0 +1,62 @@ +#!/bin/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. + +VERSION=$1 +TEST_CODE_GIT=$2 +TEST_CODE_BRANCH=$3 +TEST_CODE_PATH=$4 +TEST_CMD_BASE=$5 + +ASK_CONFIG=$6 +JOB_INDEX=$7 + +export REPO_NAME=`echo ${GITHUB_REPOSITORY#*/} | sed -e "s/\//-/g" | cut -c1-36 | tr '[A-Z]' '[a-z]'` +export WORKFLOW_NAME=${GITHUB_WORKFLOW} +export RUN_ID=${GITHUB_RUN_ID} +export TEST_CODE_GIT +export TEST_CODE_BRANCH +export TEST_CODE_PATH + + +echo "Start test version: ${GITHUB_REPOSITORY}@${VERSION}" + +echo "************************************" +echo "* Set config... *" +echo "************************************" +mkdir -p ${HOME}/.kube +kube_config=$(echo "${ASK_CONFIG}" | base64 -d) +echo "${kube_config}" > ${HOME}/.kube/config +export KUBECONFIG="${HOME}/.kube/config" + +env_uuid=${REPO_NAME}-${GITHUB_RUN_ID}-${JOB_INDEX} + +echo "************************************" +echo "* E2E Test local... *" +echo "************************************" + +ns=${env_uuid} + +echo namespace: $ns +echo $TEST_CODE_GIT +echo $TEST_CMD_BASE + + +cd ${TEST_CODE_PATH} +${TEST_CMD} +exit_code=$? + +exit ${exit_code} \ No newline at end of file