Setup GitLab-CI for btrfs-progs
diff mbox series

Message ID 20190930165622.GA25114@giis.co.in
State New
Headers show
Series
  • Setup GitLab-CI for btrfs-progs
Related show

Commit Message

Lakshmipathi.G Sept. 30, 2019, 4:56 p.m. UTC
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

Signed-off-by: Lakshmipathi.G <lakshmipathi.ganapathi@collabora.com>
---
 .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

Comments

Philipp Hahn Oct. 1, 2019, 6:02 a.m. UTC | #1
Hi,

I'm not yet a GitLab expert myself, but AFAIK ...

Am 30.09.19 um 18:56 schrieb Lakshmipathi.G:
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> new file mode 100644
> index 0000000..2afde50
> --- /dev/null
> +++ b/.gitlab-ci.yml
> @@ -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:

You already have a "variables" section above - merge them?

> +  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

You already have "services" defined globally - no need to repeat that
here again.

> +  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

dito

> +  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

dito

> +  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

> +  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

dito

> +  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

> +  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

dito

> +  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

> +  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

> +  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
Lakshmipathi.G Oct. 7, 2019, 3:25 a.m. UTC | #2
On Tue, Oct 01, 2019 at 08:02:29AM +0200, Philipp Hahn wrote:
> 
> You already have a "variables" section above - merge them?
> 
> > +  services:
> > +    - docker:18.09.7-dind
> 
> You 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
David Sterba Oct. 7, 2019, 5:52 p.m. UTC | #3
On Mon, Sep 30, 2019 at 10:26:54PM +0530, Lakshmipathi.G wrote:
> 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!

> More details can be found at https://github.com/kdave/btrfs-progs/issues/171
> 
> Signed-off-by: Lakshmipathi.G <lakshmipathi.ganapathi@collabora.com>
> ---
>  .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.

>  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.
Lakshmipathi.G Oct. 14, 2019, 6:02 p.m. UTC | #4
On Mon, Oct 07, 2019 at 07:52:35PM +0200, David Sterba wrote:
> 
> 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.

> 
> 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

Patch
diff mbox series

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..2afde50
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -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"
+
diff --git a/gitlab-ci/Dockerfile b/gitlab-ci/Dockerfile
new file mode 100644
index 0000000..356a21f
--- /dev/null
+++ b/gitlab-ci/Dockerfile
@@ -0,0 +1,3 @@ 
+FROM debian:stretch-slim
+
+RUN apt-get update && apt-get install -y --no-install-recommends ovmf qemu-system qemu-efi
diff --git a/gitlab-ci/btrfs-progs-tests.service b/gitlab-ci/btrfs-progs-tests.service
new file mode 100644
index 0000000..d255d77
--- /dev/null
+++ b/gitlab-ci/btrfs-progs-tests.service
@@ -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
diff --git a/gitlab-ci/build_or_run_btrfs-progs.sh b/gitlab-ci/build_or_run_btrfs-progs.sh
new file mode 100755
index 0000000..081e83c
--- /dev/null
+++ b/gitlab-ci/build_or_run_btrfs-progs.sh
@@ -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
diff --git a/gitlab-ci/kernel_build.sh b/gitlab-ci/kernel_build.sh
new file mode 100755
index 0000000..189dec1
--- /dev/null
+++ b/gitlab-ci/kernel_build.sh
@@ -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
diff --git a/gitlab-ci/run_tests.sh b/gitlab-ci/run_tests.sh
new file mode 100755
index 0000000..c53d09e
--- /dev/null
+++ b/gitlab-ci/run_tests.sh
@@ -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" 
diff --git a/gitlab-ci/setup_image.sh b/gitlab-ci/setup_image.sh
new file mode 100755
index 0000000..1e0418a
--- /dev/null
+++ b/gitlab-ci/setup_image.sh
@@ -0,0 +1,42 @@ 
+#!/usr/bin/env bash
+#
+# Setup debian image via debootstrap and include systemd service file.
+set -x
+
+apt-get update
+apt-get -y install debootstrap wget unzip
+
+# Setup rootfs
+IMG="/qemu-image.img"
+DIR="/target"
+truncate -s2G $IMG
+mkfs.ext4 $IMG
+mkdir -p $DIR
+for i in {0..7};do
+mknod -m 0660 "/dev/loop$i" b 7 "$i"
+done
+
+# mount the image file
+mount -o loop $IMG $DIR
+
+# Install required pacakges
+debootstrap --arch=amd64  --include=git,autoconf,automake,gcc,make,pkg-config,e2fslibs-dev,libblkid-dev,zlib1g-dev,liblzo2-dev,asciidoc,xmlto,libzstd-dev,python3.5,python3.5-dev,python3-dev,python3-setuptools,python-setuptools,xz-utils,acl,attr stretch $DIR http://ftp.de.debian.org/debian/
+
+## Setup 9p mount
+echo "btrfs-progs /mnt           9p             trans=virtio    0       0" > $DIR/etc/fstab
+
+#Setup autologin 
+sed -i 's/9600/9600 --autologin root/g' $DIR/lib/systemd/system/serial-getty@.service
+
+# Setup systemd service
+cp -v /repo/gitlab-ci/build_or_run_btrfs-progs.sh $DIR/usr/bin/
+cp -v /repo/gitlab-ci/btrfs-progs-tests.service $DIR/etc/systemd/system/
+
+## Enable service
+ln -s $DIR/etc/systemd/system/btrfs-progs-tests.service $DIR/etc/systemd/system/getty.target.wants/btrfs-progs-tests.service 
+
+cd /
+umount $DIR
+rmdir $DIR
+
+cp -v $IMG /repo