diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml new file mode 100644 index 000000000..7478b8228 --- /dev/null +++ b/.github/workflows/driver_ci.yaml @@ -0,0 +1,135 @@ +name: Driver Build +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master +jobs: + prepare_env: + name: "Prepare env" + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9.7' + - uses: FranzDiebold/github-env-vars-action@v2 + - name: Setup dependencies + id: setup_dependencies + run: | + scripts/ci/github_actions/driver/setup_ci_dependencies.sh + env: + build_number: "${{ github.run_number }}" + - uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: ${{ env.pythonLocation }}-${{ hashFiles('dev-requirements.txt') }} + - name: Save dependencies files + uses: actions/upload-artifact@v2 + with: + name: ci-dependencies + path: | + /home/runner/.bash_profile + retention-days: 1 + outputs: + docker_image_branch_tag: "${{ steps.setup_dependencies.outputs.docker_image_branch_tag }}" + driver_images_specific_tag: "${{ steps.setup_dependencies.outputs.driver_images_specific_tag }}" + + csi_controller_static_code_analysis: + runs-on: ubuntu-latest + name: "CSI controller static code analysis" + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: CSI-controller- static code analysis + run: | + ./scripts/run_static_code_analysis.sh + + unit_testing_coverage: + runs-on: ubuntu-latest + name: "Unit testing + coverage ${{ matrix.csiblock-component }}" + strategy: + matrix: + include: + - csiblock-component: controller + command-to-run: "./scripts/run_unitests.sh" + - csiblock-component: node + command-to-run: "make test-xunit-in-container" + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: CSI-${{ matrix.csiblock-component }}- Unit testing + coverage + run: | + mkdir -p build/reports && chmod 777 build/reports + $command_to_run `pwd`/build/reports + env: + command_to_run: ${{ matrix.command-to-run }} + + k8s_yamls_validation: + runs-on: ubuntu-latest + name: "Deployment k8s yamls validation" + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: CSI-deployment- k8s yamls validation + run: | + ./scripts/run_yamlcheck.sh + + csi_build_and_push_images: + runs-on: ubuntu-latest + name: "Build and push images" + needs: + - CSI_controller_static_code_analysis + - Unit_testing_coverage + - k8s_yamls_validation + - Prepare_env + strategy: + matrix: + image_type: ['node', 'controller'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1.3.0 + - uses: FranzDiebold/github-env-vars-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: '${{ secrets.CSIBLOCK_DOCKERHUB_USERNAME }}' + password: '${{ secrets.CSIBLOCK_DOCKERHUB_PASSWORD }}' + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-${{ matrix.image_type }} + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Build and push ${{ matrix.image_type }} + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/ppc64le,linux/s390x + push: true + tags: | + ${{ secrets.CSIBLOCK_DOCKERHUB_USERNAME }}/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.driver_images_specific_tag }} + ${{ secrets.CSIBLOCK_DOCKERHUB_USERNAME }}/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.docker_image_branch_tag }} + file: Dockerfile-csi-${{ matrix.image_type }} + cache-from: type=local,src=/tmp/.buildx-${{ matrix.image_type }} + cache-to: type=local,dest=/tmp/.buildx-new-${{ matrix.image_type }} + # Temp fix + # CSI-3164 + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache + run: | + [[ -G /tmp/.buildx-${{ matrix.image_type }} ]] && rm -rf /tmp/.buildx-${{ matrix.image_type }} + mv /tmp/.buildx-new-${{ matrix.image_type }} /tmp/.buildx-${{ matrix.image_type }} diff --git a/scripts/ci/Jenkinsfile b/scripts/ci/Jenkinsfile index 1758d59e2..644132c30 100644 --- a/scripts/ci/Jenkinsfile +++ b/scripts/ci/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { sh 'make test-xunit-in-container' } } - stage ('CSI-deployment: k8s yamls validation') { + stage ('k8s yamls validation') { steps { sh './scripts/run_yamlcheck.sh' } diff --git a/scripts/ci/build_push_images.sh b/scripts/ci/build_push_images.sh index 9b1f251d5..f34cdd9bd 100755 --- a/scripts/ci/build_push_images.sh +++ b/scripts/ci/build_push_images.sh @@ -7,8 +7,8 @@ for envi in $MANDATORY_ENVS; do done # Prepare specific tag for the image -branch=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch}" +tags=`scripts/ci/get_image_tags_from_branch.sh ${GIT_BRANCH} ${IMAGE_VERSION} ${BUILD_NUMBER} ${GIT_COMMIT}` +specific_tag=`echo $tags | awk '{print$1}'` # Set latest tag only if its from develop branch or master and prepare tags [ "$GIT_BRANCH" = "develop" -o "$GIT_BRANCH" = "origin/develop" -o "$GIT_BRANCH" = "master" ] && tag_latest="true" || tag_latest="false" diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh new file mode 100755 index 000000000..4e4f13c80 --- /dev/null +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -0,0 +1,9 @@ +#!/bin/bash -xe +GIT_BRANCH=$1 +IMAGE_VERSION=$2 +BUILD_NUMBER=$3 +COMMIT_HASH=${4:0:7} +branch_image_tag=$(echo $GIT_BRANCH| sed 's|/|.|g') #not sure if docker accept / in the version +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${COMMIT_HASH}_${branch_image_tag}" +echo $specific_tag +echo $branch_image_tag diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh new file mode 100755 index 000000000..399c694d6 --- /dev/null +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -0,0 +1,29 @@ +#!/bin/bash -xe +set +o pipefail + +install_ci_dependencies (){ + scripts/ci/github_actions/setup_yq.sh + source /home/runner/.bash_profile + python -m pip install --upgrade pip==21.2.4 + echo docker-hub==2.2.0 > dev-requirements.txt + pip install -r dev-requirements.txt +} + +get_driver_version (){ + yq eval .identity.version common/config.yaml +} + +install_ci_dependencies +driver_version=$(get_driver_version) +triggering_branch=${CI_ACTION_REF_NAME} +driver_image_tags=$(scripts/ci/get_image_tags_from_branch.sh ${triggering_branch} ${driver_version} ${build_number} ${GITHUB_SHA}) +driver_images_specific_tag=$(echo $driver_image_tags | awk '{print$1}') + +if [ "$triggering_branch" == "develop" ]; then + docker_image_branch_tag=latest +else + docker_image_branch_tag=$(echo $driver_image_tags | awk '{print$2}') +fi + +echo "::set-output name=driver_images_specific_tag::${driver_images_specific_tag}" +echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" diff --git a/scripts/ci/github_actions/setup_yq.sh b/scripts/ci/github_actions/setup_yq.sh new file mode 100755 index 000000000..71966a5c2 --- /dev/null +++ b/scripts/ci/github_actions/setup_yq.sh @@ -0,0 +1,8 @@ +#!/bin/bash -xe +set +o pipefail + +cat >>/home/runner/.bash_profile <<'EOL' +yq() { + docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" +} +EOL