Setup GitLab-CI for btrfs-progs
PATCH 1/1 Setup GitLab-CI for btrfs-progs
Make use of GitLab-CI nested virutal environment to start QEMU instance inside containers and perform btrfs-progs build, execute unit test cases and save the logs.
More details can be found at https://github.com/kdave/btrfs-progs/issues/171
--- .gitlab-ci.yml | 181 ++++++++++++++++++++++++++++++++++ gitlab-ci/Dockerfile | 3 + gitlab-ci/btrfs-progs-tests.service | 13 +++ gitlab-ci/build_or_run_btrfs-progs.sh | 37 +++++++ gitlab-ci/kernel_build.sh | 30 ++++++ gitlab-ci/run_tests.sh | 9 ++ gitlab-ci/setup_image.sh | 42 ++++++++ 7 files changed, 315 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 gitlab-ci/Dockerfile create mode 100644 gitlab-ci/btrfs-progs-tests.service create mode 100755 gitlab-ci/build_or_run_btrfs-progs.sh create mode 100755 gitlab-ci/kernel_build.sh create mode 100755 gitlab-ci/run_tests.sh create mode 100755 gitlab-ci/setup_image.sh
.gitlab-ci.yml new file +181 -0
@@ -0,0 +1,181 @@ +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License v2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 021110-1307, USA. +# + +image: docker:18.09.7 + +services: + - docker:18.09.7-dind + +variables: + DOCKER_DRIVER: overlay2 + +stages: + - build + - btrfs-progs build + - test + +variables: + DOCKER_DRIVER: overlay2 + IMAGE_TAG: registry.gitlab.com/$CI_PROJECT_NAMESPACE/btrfs-progs:gitlab-ci + +before_script: + - docker login --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD $CI_REGISTRY + +docker build: + stage: build + script: + - cd gitlab-ci + - docker pull $IMAGE_TAG > /dev/null && echo "Downloaded image" || ( docker build -t $IMAGE_TAG . && docker push $IMAGE_TAG ) + - cd .. + +## To enable or disable Kernel Build set BUILD_KERNEL: "1" or BUILD_KERNEL: "0" +## If you disable Kernel Build, make sure PREBUILT_KERNEL_ID points to previously built the kernel job id. + +kernel build: + variables: + BUILD_KERNEL: "1" + PREBUILT_KERNEL_ID: "288159334" + before_script: + - apk add curl unzip + stage: build + services: + - docker:18.09.7-dind + script: + - if [ "$BUILD_KERNEL" == "1" ]; then + docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/kernel_build.sh; + else + curl -o bzImage.zip --location --header "JOB-TOKEN:$CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$PREBUILT_KERNEL_ID/artifacts" && unzip bzImage.zip; + fi; + artifacts: + when: always + paths: + - bzImage + +# To enable or disable image build update BUILD_IMAGE value to "1" or "0". +# If you disable Image Build, make sure PREBUILT_IMAGE_ID points to previously built rootfs job id. + +image build: + variables: + BUILD_IMAGE: "1" + PREBUILT_IMAGE_ID: "288506168" + before_script: + - apk add curl unzip + stage: build + services: + - docker:18.09.7-dind + script: + - if [ "$BUILD_IMAGE" == "1" ]; then + docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/setup_image.sh; + else + curl -o qemu-image.img.zip --location --header "JOB-TOKEN:$CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$PREBUILT_IMAGE_ID/artifacts" && unzip qemu-image.img.zip; + fi; + artifacts: + when: always + paths: + - qemu-image.img + +btrfs-progs build: + stage: btrfs-progs build + services: + - docker:18.09.7-dind + script: + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + artifacts: + expire_in: 1 week + when: always + paths: + - qemu-image.img + +cli tests: + stage: test + services: + - docker:18.09.7-dind + script: + - echo "./cli-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 # If result doesn't exists, job failed. + artifacts: + when: always + paths: + - "*tests-results.txt" + +convert tests: + only: + - devel + stage: test + services: + - docker:18.09.7-dind + script: + - echo "./convert-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + +fsck tests: + stage: test + services: + - docker:18.09.7-dind + script: + - echo "./fsck-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + - error.log + +fuzz tests: + stage: test + services: + - docker:18.09.7-dind + script: + - echo "./fuzz-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + +misc tests: + stage: test + services: + - docker:18.09.7-dind + script: + - echo "./misc-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + +mkfs tests: + stage: test + services: + - docker:18.09.7-dind + script: + - echo "./mkfs-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" +
gitlab-ci/Dockerfile new file +3 -0
@@ -0,0 +1,3 @@ +FROM debian:stretch-slim + +RUN apt-get update && apt-get install -y --no-install-recommends ovmf qemu-system qemu-efi
gitlab-ci/btrfs-progs-tests.service new file +13 -0
@@ -0,0 +1,13 @@ +[Unit] +Description=Execute build_or_run_btrfs-progs.sh on console + +[Service] +ExecStart=/usr/bin/build_or_run_btrfs-progs.sh +StandardInput=tty +StandardOutput=tty +TTYPath=/dev/ttyS0 +Type=idle + +[Install] +WantedBy=getty.target +After=multi-user.target
gitlab-ci/build_or_run_btrfs-progs.sh new file +37 -0
@@ -0,0 +1,37 @@ +#!/bin/bash +# +# Build or Run btrfs-progs tests. +# +set -x + +BTRFS_BIN="btrfs" +MNT_DIR="/mnt/" +BUILD_DIR="/btrfs/" +test_cmd=$(cat ${MNT_DIR}/cmd) + +rm -f ${MNT_DIR}/result +${BTRFS_BIN} --version + +if [ $? -ne 0 ] +then + echo "=========================== Builb btrfs-progs ================" + echo " Image doesn't have ${BTRFS_BIN} - start build process" + cd ${MNT_DIR} && ./autogen.sh && ./configure --disable-documentation --disable-backtrace && make -j`nproc` && make install && make testsuite + echo "================= Prepare Testsuite ==========================" + mkdir -p ${BUILD_DIR} + cp tests/btrfs-progs-tests.tar.gz ${BUILD_DIR} + poweroff +else + echo "================= Run Tests =================================" + cd ${BUILD_DIR} && tar -xvf btrfs-progs-tests.tar.gz && ${test_cmd} + + # check test result status + if [ $? -ne 0 ]; then + cd ${BUILD_DIR} && cp *tests-results.txt ${MNT_DIR} + poweroff + else + cd ${BUILD_DIR} && cp *tests-results.txt ${MNT_DIR} + touch ${MNT_DIR}/result + poweroff + fi +fi
gitlab-ci/kernel_build.sh new file +30 -0
@@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# Setup BTRFS kernel options and build kernel +set -x + +apt-get update +apt-get -y install build-essential libncurses-dev bison flex libssl-dev libelf-dev unzip wget bc + +# Build kernel +wget https://github.com/kdave/btrfs-devel/archive/misc-next.zip +unzip -qq misc-next.zip +cd btrfs-devel-misc-next/ && make x86_64_defconfig && make kvmconfig + +# BTRFS specific entires +cat <<EOF >> .config +CONFIG_BTRFS_FS=y +CONFIG_BTRFS_FS_POSIX_ACL=y +CONFIG_BTRFS_FS_CHECK_INTEGRITY=n +CONFIG_BTRFS_FS_RUN_SANITY_TESTS=n +CONFIG_BTRFS_DEBUG=y +CONFIG_BTRFS_ASSERT=y +CONFIG_BTRFS_FS_REF_VERIFY=y +CONFIG_RAID6_PQ_BENCHMARK=y +CONFIG_LIBCRC32C=y +EOF + +make -j8 + +# Store file to shared dir +cp -v arch/x86/boot/bzImage /repo
gitlab-ci/run_tests.sh new file +9 -0
@@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# +# Install and start qemu instance with custom kernel while exporting btrfs-progs src over 9p +# +set -x + +qemu-system-x86_64 -m 512 -nographic -kernel /repo/bzImage -drive file=/repo/qemu-image.img,index=0,media=disk,format=raw \ +-fsdev local,id=btrfs-progs,path=/repo,security_model=mapped -device virtio-9p-pci,fsdev=btrfs-progs,mount_tag=btrfs-progs \ +-append "console=tty1 root=/dev/sda rw"
gitlab-ci/setup_image.sh new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.7.4
Hi,
I'm not yet a GitLab expert myself, but AFAIK ...
Am 30.09.19 um 18:56 schrieb Lakshmipathi.G:
Quoted 25 lines
.gitlab-ci.yml new file +19
-0@@ -0,0 +1,181 @@ +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License v2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 021110-1307, USA. +# + +image: docker:18.09.7 + +services: + - docker:18.09.7-dind
.gitlab-ci.yml line 29
Quoted 10 lines
.gitlab-ci.yml new file +10
-0+ +variables: + DOCKER_DRIVER: overlay2 + +stages: + - build + - btrfs-progs build + - test + +variables:
You already have a "variables" section above - merge them?
Quoted 15 lines
.gitlab-ci.yml new file +15
-0+ DOCKER_DRIVER: overlay2 + IMAGE_TAG: registry.gitlab.com/$CI_PROJECT_NAMESPACE/btrfs-progs:gitlab-ci + +before_script: + - docker login --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD $CI_REGISTRY + +docker build: + stage: build + script: + - cd gitlab-ci + - docker pull $IMAGE_TAG > /dev/null && echo "Downloaded image" || ( docker build -t $IMAGE_TAG . && docker push $IMAGE_TAG ) + - cd .. + +## To enable or disable Kernel Build set BUILD_KERNEL: "1" or BUILD_KERNEL: "0" +## If you disable Kernel Build, make sure PREBUILT_KERNEL_ID points to previously built the kernel job id.
.gitlab-ci.yml line 54
Quoted 10 lines
.gitlab-ci.yml new file +10
-0+ +kernel build: + variables: + BUILD_KERNEL: "1" + PREBUILT_KERNEL_ID: "288159334" + before_script: + - apk add curl unzip + stage: build + services: + - docker:18.09.7-dind
You already have "services" defined globally - no need to repeat that here again.
Quoted 13 lines
.gitlab-ci.yml new file +13
-0+ script: + - if [ "$BUILD_KERNEL" == "1" ]; then + docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/kernel_build.sh; + else + curl -o bzImage.zip --location --header "JOB-TOKEN:$CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$PREBUILT_KERNEL_ID/artifacts" && unzip bzImage.zip; + fi; + artifacts: + when: always + paths: + - bzImage + +# To enable or disable image build update BUILD_IMAGE value to "1" or "0". +# If you disable Image Build, make sure PREBUILT_IMAGE_ID points to previously built rootfs job id.
.gitlab-ci.yml line 77
Quoted 10 lines
.gitlab-ci.yml new file +10
-0+ +image build: + variables: + BUILD_IMAGE: "1" + PREBUILT_IMAGE_ID: "288506168" + before_script: + - apk add curl unzip + stage: build + services: + - docker:18.09.7-dind
dito
Quoted 5 lines
.gitlab-ci.yml new file +5
-0+ script: + - if [ "$BUILD_IMAGE" == "1" ]; then + docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/setup_image.sh; + else + curl -o qemu-image.img.zip --location --header "JOB-TOKEN:$CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$PREBUILT_IMAGE_ID/artifacts" && unzip qemu-image.img.zip;
.gitlab-ci.yml line 92
Quoted 10 lines
.gitlab-ci.yml new file +10
-0+ fi; + artifacts: + when: always + paths: + - qemu-image.img + +btrfs-progs build: + stage: btrfs-progs build + services: + - docker:18.09.7-dind
dito
.gitlab-ci.yml line 104
Quoted 12 lines
.gitlab-ci.yml new file +12
-0+ script: + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + artifacts: + expire_in: 1 week + when: always + paths: + - qemu-image.img + +cli tests: + stage: test + services: + - docker:18.09.7-dind
dito
Quoted 5 lines
.gitlab-ci.yml new file +5
-0+ script: + - echo "./cli-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 # If result doesn't exists, job failed. + artifacts:
.gitlab-ci.yml line 119
Quoted 10 lines
.gitlab-ci.yml new file +10
-0+ when: always + paths: + - "*tests-results.txt" + +convert tests: + only: + - devel + stage: test + services: + - docker:18.09.7-dind
dito
.gitlab-ci.yml line 132
Quoted 13 lines
.gitlab-ci.yml new file +13
-0+ script: + - echo "./convert-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + +fsck tests: + stage: test + services: + - docker:18.09.7-dind
dito
Quoted 4 lines
.gitlab-ci.yml new file +4
-0+ script: + - echo "./fsck-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1
.gitlab-ci.yml line 146
Quoted 10 lines
.gitlab-ci.yml new file +10
-0+ artifacts: + when: always + paths: + - "*tests-results.txt" + - error.log + +fuzz tests: + stage: test + services: + - docker:18.09.7-dind
dito
.gitlab-ci.yml line 159
Quoted 13 lines
.gitlab-ci.yml new file +13
-0+ script: + - echo "./fuzz-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + +misc tests: + stage: test + services: + - docker:18.09.7-dind
dito
.gitlab-ci.yml line 172
Quoted 13 lines
.gitlab-ci.yml new file +13
-0+ script: + - echo "./misc-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" + +mkfs tests: + stage: test + services: + - docker:18.09.7-dind
dito
.gitlab-ci.yml line 181
Quoted 9 lines
.gitlab-ci.yml new file +9
-0+ script: + - echo "./mkfs-tests.sh" > $PWD/cmd + - docker run --cap-add SYS_PTRACE --cap-add sys_admin --privileged --device=/dev/kvm -v $PWD:/repo $IMAGE_TAG /repo/gitlab-ci/run_tests.sh + - test -e "result" || exit 1 + artifacts: + when: always + paths: + - "*tests-results.txt" +
Philipp
Quoted 9 lines · Philipp Hahn
You already have a "variables" section above - merge them?
Review
Quoted 2 lines
(quoted diff) +2
-0+ services: + - docker:18.09.7-dindYou already have "services" defined globally - no need to repeat that here again.
Hi Philipp,
Thanks for the comments. I ran into some issue while using global section so started using job section. Let me try placing them in global and update the results. thanks.
Cheers.
Lakshmipathi.G
Quoted 2 lines · Lakshmipathi.G
Make use of GitLab-CI nested virutal environment to start QEMU instance inside containers and perform btrfs-progs build, execute unit test cases and save the logs.
This looks good, thanks!
Quoted 11 lines
More details can be found at https://github.com/kdave/btrfs-progs/issues/171
Signed-off-by Lakshmipathi.G <[email protected]>--- .gitlab-ci.yml | 181 ++++++++++++++++++++++++++++++++++ gitlab-ci/Dockerfile | 3 + gitlab-ci/btrfs-progs-tests.service | 13 +++ gitlab-ci/build_or_run_btrfs-progs.sh | 37 +++++++ gitlab-ci/kernel_build.sh | 30 ++++++ gitlab-ci/run_tests.sh | 9 ++ gitlab-ci/setup_image.sh | 42 ++++++++
Is it possible to move the files to ci/gitlab? .gitlab-ci.yml must be probably in the top-level dir but that's acceptable.
Quoted 8 lines
7 files changed, 315 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 gitlab-ci/Dockerfile create mode 100644 gitlab-ci/btrfs-progs-tests.service create mode 100755 gitlab-ci/build_or_run_btrfs-progs.sh create mode 100755 gitlab-ci/kernel_build.sh create mode 100755 gitlab-ci/run_tests.sh create mode 100755 gitlab-ci/setup_image.sh
The scripts look good to me but I have limited knowledge of the CI environment so I don't have objections against merging the patch. I'll spend some time experimenting but overall this seems in a good shape and we'll get further coverage (due to the new kernel) than what travis provides. Thanks.
Quoted 4 lines · David Sterba
Is it possible to move the files to ci/gitlab? .gitlab-ci.yml must be probably in the top-level dir but that's acceptable.
Ok added these changes to Patch V2.
Quoted 6 lines
The scripts look good to me but I have limited knowledge of the CI environment so I don't have objections against merging the patch. I'll spend some time experimenting but overall this seems in a good shape and we'll get further coverage (due to the new kernel) than what travis provides. Thanks.
Yes, please experiment with it. There are some failures in tests
https://gitlab.com/giis/btrfs-progs/pipelines/88716001 and I'm not sure whether its due to environment or missing packages or something else. Let me know, if something needs to be updated or fixed. thanks!
Cheers.
Lakshmipathi.G