Running android emulator during jenkins build - jenkins

I have installed Jenkins and configured a build job with emulator running during build. But when I execute the job, I get error message that jenkins user doesn't have permission to run kvm. How can I fix it.
$ android list target
[android] Using Android SDK: /opt/android/sdk
$ adb start-server
* daemon not running. starting it now on port 5973 *
* daemon started successfully *
$ adb start-server
[android] Starting Android emulator
[android] Erasing existing emulator data...
$ emulator -ports 5971,5972 -prop persist.sys.language=en -prop persist.sys.country=US -avd hudson_en-US_160_1024x768_android-15_x86 -no-snapshot-load -no-snapshot-save -wipe-data
emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm).
[android] Emulator did not appear to start; giving up
$ adb disconnect localhost:5972
[android] Stopping Android emulator
$ adb kill-server
Permissions
$ ls -l /dev/kvm
crw-rw----+ 1 root root 10, 232 May 6 13:46 /dev/kvm
$ groups jenkins
jenkins : jenkins

I have managed to fix the problem.
Install Qemu-KVM and cpu-checker:
sudo apt install qemu-kvm cpu-checker
Check if KVM is available (as jenkins user):
$ kvm-okINFO: /dev/kvm existsKVM acceleration can be used
Create group kvm and add jenkins to this group:
addgroup kvmusermod -a -G kvm jenkins
Change group ownership for /dev/kvm:
chgrp kvm /dev/kvm
Create udev rule:
$ sudo nano /etc/udev/rules.d/60-qemu-kvm.rules
KERNEL=="kvm", GROUP="kvm", MODE="0660"
Reboot

On my CI (gitlab) this was missing on Ubuntu
usermod -a -G kvm gitlab-runner
or with Jenkins
usermod -a -G kvm jenkins

Related

Rancher desktop, docker file shell commands are not working on mac m1 chip

hi following are my docker file commands
ARG debianVersion=10.2
FROM debian:${debianVersion}
ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000
ARG AGENT_WORKDIR=/home/${user}/agent
USER root
RUN apt-get update
RUN groupadd -g ${gid} ${group}
RUN useradd -c "Jenkins user" -d /home/${user} -u ${uid} -g ${gid} -m ${user}
I am using rancher desktop on mac m1 chip.
On executing following command I a getting error
docker build -t test --platform linux/x86_64 .
Error message is as follows
[Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
---> Running in 7778b2303192
-c: 0: Can't open apt-get update
The command '/bin/sh -c apt-get update' returned a non-zero code: 127
Found that none of the shell commands are working getting error a non-zero code: 127 how to fix this?
Using rancher version 1.5.0
Using container runtime dockerd(moby)
Using Kubernetes version v1.21.14
Downgrade to Rancher Desktop 1.4.1.
This works but if downgrading is not an option there are workarounds on the Rancher Desktop Issues site for similar problems like this:
qemu workaround
As a temporary workaround, as root in the VM:
Create /etc/conf.d/qemu-binfmt, with contents binfmt_flags="POCF"
Run rc-update --update
Run rc-service qemu-binfmt restart
Easy way to connect to the VM and run those commands is (source):
docker run -it --rm --privileged --pid=host justincormack/nsenter1
Dockerfile:
…
FROM --platform=linux/arm64 debian:${debianVersion}
…
Build command:
docker build -t test --platform linux/arm64 .
As far as I understand it dockerd runtime can only emulate other platform types (in the above case --platform=linux/amd64) on the m1 chip macs using Docker Desktop.
Try using the built in nerdctl that comes packaged with Rancher Desktop:
nerdctl build -t test --platform linux/amd64 .
nerdctl build -t test --platform linux/x86_64 .
N.B. I have found that even with emulation, some --platform linux/x86_64 (linux/amd64) images still cannot be built, recently experienced that with official selenium set, but had no problem with wso2 & mailcatcher images

Failed to connect to bus: Host is down in ubuntu

"sudo systemctl enable --now docker" while running this command I'm getting an error like "System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down"
How can I fix this and I'm new to Ubuntu commands.
Please refer to Latest Docker Documentation; Older versions of Docker don't play nicely.
The trick is to uninstall sudo apt-get remove docker docker.io containderd, etc... And add the docker GPG key and setup the repository (documented in link). Then install sudo apt-get install docker-ce docker-ce-cli containerd.io instead.
Once you've removed old docker from your Ubuntu installation, you can then go sudo service docker start to have docker daemon running without systemctl and use service instead.
I am using ubuntu:20.04 Image.
I encountered the same error while trying to use systemctl command inside the ubuntu docker container, since the system has not been booted with systemd as init system (PID 1) as the error says so in order to fix that you will need to start you container using this
docker run -ti -d ubuntu:20.04 "/sbin/init"
In fact, running the container will cause an error:
I have solvedcontroller_1 | Failed to mount tmpfs at /run: Operation not permitted
container_1 | Failed to mount tmpfs at /run/lock: Operation not permitted
container_1 | [!!!!!!] Failed to mount API filesystems.
container_1 | Freezing execution.
By default, the container is not authorized to access any device, but a container with a "privileged" tag grants its root capabilities to all devices on the host system that will give access to the container to mount API filesystems and solve the issue.
in order to fix that you will need to
docker run -ti -d --privileged ubuntu:20.04 "/sbin/init"

docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]

I saw similar treads but they are different because I am using WSL2 and docker and GPU aware docker.
I have windows 10 version 2004 (build 20161.1000)
I have installed WSL 2 and have Docker Desktop 2.3.0.3 on my Windows System running.
I have Ubuntu 18.04 LTS installed in WSL 2 too.
I have installed the NVIDIA driver
The linux version is 4.19.121-microsoft-standard.
The NVIDIA driver version is 455.41 for my Laptop GPU QUADRO M2000M.
Actually I followed all the steps described in https://ubuntu.com/blog/getting-started-with-cuda-on-ubuntu-on-wsl-2 until the step where I have to run "sudo service docker stop" in an Ubuntu terminal.
This results in a message docker: unrecognized service.
I have to restart docker desktop in WIndows 10 in order to get the deamon running.
I test then in the Ubuntu terminal : docker run hello-world ==> this runs fine
Also the command docker run -it ubuntu bash ==> runs file in the Ubuntu terminal os WSL 2.
BUT when I run :
docker run -u $(id -u):$(id -g) -it --gpus all -p 8888:8888 tensorflow/tensorflow:latest-gpu-py3-jupyter
then I get the error : docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]]
This invoves microsoft,Ubuntu,NVIDIA. I have search the support sites but could not find anything that solves my prblem.
Can anyone help me here?
There is this strange answer mentioned here and here:
sudo service docker start
sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
This worked for me on WSL (Ubuntu 20.04), so I added it to the ~/.bashrc script.
Note, the first part may need to be restarting docker!

JProfiler inside Docker container: The JVM you are trying to attach to is running with a different user account

I am trying to run JProfiler inside my Docker container which is deploying my Java/Springboot application. By following the instructions provided here, I added this to my Dockerfile:
RUN wget http://download-keycdn.ej-technologies.com/jprofiler/jprofiler_linux_11_0.tar.gz -P /tmp/ &&\
tar -xzf /tmp/jprofiler_linux_11_0.tar.gz -C /usr/local &&\
rm /tmp/jprofiler_linux_11_0.tar.gz
ENV JPAGENT_PATH="-agentpath:/usr/local/jprofiler11.0/bin/linux-x64/libjprofilerti.so=nowait"
EXPOSE 8849
And then I enter the container to run the following inside /usr/local/jprofiler11.0:
bin/jpenable --gui --port=8849
which responds with the following error:
ERROR: The agent could not be loaded:
The JVM you are trying to attach to is running with a different user account.
Please run this tool with
sudo -u app jpenable
I am finding this error hard to understand because if I do a ps I get
PID USER TIME COMMAND
16 app 6:57 java -jar myRunningApp
And whoami confirms that I am user app. I also tried entering the container as root and the result is the same. Anyway, I am unable to run sudo -u app jpenable because I get bash: sudo: command not found, not sure if relevant. Running uname -a:
Linux 9cdef7df689d 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019 x86_64 Linux
Does anybody know what I am missing? Thank you for your help

dial unix /var/run/docker.sock: no such file or directory after upgrading to lxc-docker

when I installed docker initially, it shows to be of version 1.0.1
Being, that the current version is 1.4.1, I found and executed the following instructions:
$ sudo apt-get update
$ sudo apt-get install docker.io
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main \
> /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker
Now, when I run docker version I get 1.4.1, but docker no longer works - it gives me this error:
root#8dedd2fff58e:/# docker version
Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): linux/amd64
FATA[0000] Get http:///var/run/docker.sock/v1.16/version: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?
What can I do to fox this, but retail the most current docker verion 1.4.1?
/var/run/docker will be created when you start the docker service:
systemd:
sudo systemctl start docker
upstart:
sudo service docker start
init.d:
sudo /etc/init.d/docker start
You might also need this if you get this error:
FATA[0000] Cannot connect to the Docker daemon. Is 'docker -d' running on this host?
I had the same issue on Mac OS X. Leaving my fix here in case it helps somebody:
Run the "Docker Quick Start Terminal"
In the target-directory, run eval "$(docker-machine env default)"
This fixes the issue for me
I was experiencing the same problem and I was able to find the solution here: https://docs.docker.com/articles/basics/.
It's always good to go back to foundations.
The problem is that you might be running on a different port instead of default socket (unix:///var/run/docker.sock).
If you run "ps aux | grep docker" you should see the daemon running. At the end of the line of the docker process you should also see a parameter -H={IpAddress}:{Port}. You should also see the path were the certificates are stored (--tls parameters)
You have to instruct docker to connect to the tcp address specified in the -H parameter.
For example:
`docker --tls -H tcp://{IpAddress}:{Port} version`
Notice the --tls parameter, this is necessary if you instructed docker to run in a secure mode.
You could avoid the verbosity of the command by setting environment variables.
export DOCKER_HOST="tcp://{IpAddress}:{Port}"
export DOCKER_TLS_VERIFY="1"
Hope this helps..
Is docker initiated as a daemon?
use service docker.io status or service docker status
if not then start it and play with it
On a fresh M1 MacBook I ran into this. Amazingly the solution was to simply log in to the app using my docker account details. Once I did that I re-ran the failed command and it worked.

Resources