Skip to content

Chris' Laboratory

chrislee.kr – Personal blog as bookshelves

Menu
  • Home
  • Github
  • Contact Me
Menu

How to setup Gitlab runner with KVM enabled

Posted on 21/08/202221/08/2022 by Chris Lee
Read Time:2 Minute, 35 Second

To implement the CI pipeline for the Android project, I need to run Gitlab CI, in which KVM is enabled.

TL; TR

  1. Enable VTx virtualization technology in your server BIOS
  2. Pass /dev/kvm to Gitlab runner

Sample .gitlab-ci.yml

Test - E2E:
  stage: Testing
  image: reactnativecommunity/react-native-android:latest
  before_script:
    - apt update && apt install -y cpu-checker && apt auto-remove
    - kvm-ok
    - npm i -g envinfo detox-cli && envinfo
    # Increase file watcher limit, see more here: https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details
    - echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p
    - mkdir -p /root/.android && touch /root/.android/repositories.cfg
    - echo yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --channel=0 --verbose "system-images;android-28;default;x86_64"    
    - echo no | $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager --verbose create avd --force --name "Pixel_API_28" --device "Pixel_API_28_AOSP" -d pixel --package 'system-images;android-28;default;x86_64'

However, the pipeline was failing with the following error.

$ kvm-ok
INFO: /dev/kvm does not exist
HINT:   sudo modprobe kvm_intel
/usr/sbin/kvm-ok: 89: modprobe: not found

Enable VTx virtualization technology

First, I had to configure my server to enable VTx Virtualization Technology. To enable VTx, I followed the below steps.

  1. Turn off/on the server
  2. Access to BIOS (In my case, F10)
  3. Go to Security -> System Security
  4. Enable Virtualization technology (VTx)
  5. Click F10 to accept the change
  6. Save the change and hard power off and power it back on

Once you reboot the server, make sure you run kvm-ok to confirm the KVM virtualization is enabled.

Update Gitlab runner

Now, to allow Gitlab runner to use KVM, I made some changes on my docker-compose.yml for Gitlab runner.

services:
  ... other services ...
  gitlab-runner-1:
    container_name: gitlab-runner-1
    image: gitlab/gitlab-runner:latest
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /dev/kvm:/dev/kvm

  gitlab-runner-1-register:
    container_name: gitlab-runner-1-register
    image: gitlab/gitlab-runner:latest
    restart: "no"
    volumes:
      - gitlab_runner_1_config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      - gitlab-runner-1
    command: >
      register
        ... other parameters ...
        --docker-devices=/dev/kvm
        --docker-volumes=/var/run/docker.sock:/var/run/docker.sock

volumes:
  gitlab_runner_1_config:

Or if you are using config.toml

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "docker-runner-1"
  url = "<url>"
  token = "<token>"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "docker:stable"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    devices = ["/dev/kvm"]
    volumes = ["/var/run/docker.sock","/cache"]
    shm_size = 0

Note that make sure you deregister existing runners from Gitlab before adding new runners with /dev/kvm.

And Voila!

Once you restart the CI pipeline, the kvm-ok will show the result as below:

$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

Share

Facebook
Twitter
LinkedIn
Email

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • Databases (11)
    • MongoDB (4)
    • MS-SQL (1)
    • MySQL (6)
  • E-Commerce (8)
    • Magento (8)
  • Finance (2)
  • Frameworks (84)
    • Adobe Flex (1)
    • Angular (ngx) (3)
    • Codeigniter (6)
    • CSS (5)
    • Django (2)
    • Javascript (13)
    • Node.js (6)
    • PHP (17)
    • React Native (4)
    • React.js (1)
    • Sencha Touch (4)
    • Terraform (1)
    • Vue.js (1)
    • WordPress (4)
    • Yii2 (3)
  • General Documents (15)
  • Marketing (3)
  • Mobile Development (33)
    • Android (20)
    • iPhone (13)
  • Platforms (21)
    • Arduino (2)
    • Docker (5)
    • Google App Engine (5)
    • Raspberry Pi (5)
    • Samsung Smart TV (4)
  • Security (17)
  • Server (30)
    • Linux (12)
  • Tools (14)
    • SVN (7)
  • Uncategorized (2)

Search

Recent Posts

  • Taint all resources in the one module
  • Alpine – Plugin caching_sha2_password could not be loaded
  • npm link with peerDependencies
  • How to setup Gitlab runner with KVM enabled
  • Failed to transform bcprov-jdk15on-1.68.jar

Recent Comments

  • Obayed on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Ari on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Mida ali on Binance Auto Trading Bot – Buy low/Sell high with stop loss limit/Trade multiple coins
  • Chris Lee on How to install memcache.so/memcached.so for MAMP Pro (Mac)
  • Chris Lee on Setting Up A VPN Server On OSX 10.6

Tags

1 ajax amazon android android-addpart browser chrislee-kr codeigniter codeigniter-tcpdf com-apple-net-racoon CSS CSS history hack delpaigmail-com entity-addpart-double exception-printing-is-disabled-by-default-for-security-reasons ext-plugins-listpagingplugin ext-plugins-listpagingplugin-example f iphone javascript jquery-defaultchecked jquery-samsung-smart-tv listpagingplugin mac magento-exception-printing-is-disabled-by-default-for-security-reasons magento-sample-data-exception-printing-is-disabled-by-default-for-security-reasons nu-vot null-core-errors-confignotfound-config-mk9engine-ini php samsung-smart-tv-jquery samsung-smart-tv-sdk-ajax samsung-smart-tv-sdk-jquery samsung-tv-sdk samsung-tv-sdk-jquery samsung tv sencha-smart-tv sencha-touch-list-paging smart-tv-jquery sqlite subversion svn tcedook tcpdf-codeigniter uilinebreakmodecharacterwrap-is-deprecated unknown-column-link-area

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2023 Chris' Laboratory | Powered by Minimalist Blog WordPress Theme