Skip to content

Commit 3a6986e

Browse files
committed
kci-deploy using docker in docker, refactor and clean
Signed-off-by: Simone Tollardo <[email protected]>
1 parent 86f1935 commit 3a6986e

File tree

14 files changed

+153
-68
lines changed

14 files changed

+153
-68
lines changed

localinstall/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kernelci
2+
config/out/*
3+
.sudo_as_admin_successful
4+
.cache
5+
.local
6+
.docker
7+
.bash_history

localinstall/Containerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM kernelci/kernelci:latest
2+
3+
ARG USER_ID=1000
4+
ARG GROUP_ID=1000
5+
6+
USER root
7+
8+
# Install dependencies for Docker installation
9+
RUN apt-get update && \
10+
apt-get install -y --no-install-recommends \
11+
sudo \
12+
ca-certificates \
13+
curl \
14+
gnupg \
15+
lsb-release
16+
17+
# Add Docker's official GPG key
18+
RUN mkdir -p /etc/apt/keyrings && \
19+
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
20+
chmod a+r /etc/apt/keyrings/docker.gpg
21+
22+
# Set up Docker repository (assuming Debian-based image)
23+
RUN echo \
24+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
25+
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
26+
27+
# Install Docker Engine, CLI, and Compose plugin
28+
RUN apt-get update && \
29+
apt-get install -y --no-install-recommends \
30+
docker-ce \
31+
docker-ce-cli \
32+
containerd.io \
33+
docker-compose-plugin \
34+
expect
35+
36+
# Make sure a user exists with the same USER_ID/GROUP_ID as the host user
37+
# to allow access to the host docker socket
38+
RUN groupadd -g ${GROUP_ID} kernelci || true && \
39+
useradd -u ${USER_ID} -g ${GROUP_ID} -m -s /bin/bash kernelci || true
40+
41+
# Add the user to the sudoers
42+
RUN usermod -aG sudo kernelci && \
43+
echo "kernelci ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
44+
45+
USER kernelci
46+
WORKDIR /home/kernelci
47+
48+
CMD ["/bin/bash", "./scripts/run.sh"]

localinstall/README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
# kci-easy
2-
1+
# kci-deploy
32
Get your own KernelCI instance up and running in no time.
43

5-
## Getting started
6-
7-
### Prerequisites
8-
9-
- git
10-
- Docker (with `compose` plugin, set up for a regular user)
11-
- Python environment with [KernelCI core dependencies](https://github.com/kernelci/kernelci-core/blob/main/requirements.txt) installed
12-
- expect
4+
## Prerequisites
5+
- Docker
136

14-
### Running
7+
## Configure
8+
Configure and setup credentials in config files located in `config` folder.
159

16-
Change `ADMIN_PASSWORD` in the `main.cfg`, then run shell scripts from the root directory in their order.
10+
## Run
11+
```bash
12+
./kci-deploy.sh
13+
```

localinstall/kci-deploy.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

localinstall/kci-deploy.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
IMAGE_NAME="local/kernelci-deployer:latest"
6+
BUILD_IMAGE=false
7+
8+
function print_help() {
9+
echo "Usage: $0 [--build]"
10+
echo
11+
echo "Options:"
12+
echo " --build Force rebuild of the Docker image"
13+
echo " -h, --help Show this help message"
14+
exit 0
15+
}
16+
17+
for arg in "$@"; do
18+
case $arg in
19+
--build)
20+
BUILD_IMAGE=true
21+
;;
22+
-h|--help)
23+
print_help
24+
;;
25+
*)
26+
echo "Unknown option: $arg"
27+
print_help
28+
;;
29+
esac
30+
done
31+
32+
export USER_ID=$(id -u)
33+
export GROUP_ID=$(id -g)
34+
35+
if [[ "$BUILD_IMAGE" = true || -z $(docker images -q $IMAGE_NAME) ]]; then
36+
echo "Building $IMAGE_NAME"
37+
docker build \
38+
--build-arg USER_ID=$USER_ID \
39+
--build-arg GROUP_ID=$GROUP_ID \
40+
-f Containerfile \
41+
-t $IMAGE_NAME \
42+
.
43+
else
44+
echo "$IMAGE_NAME image already existing"
45+
fi
46+
47+
echo "Running $IMAGE_NAME"
48+
docker run --rm \
49+
--name kernelci-deployer \
50+
-v /var/run/docker.sock:/var/run/docker.sock \
51+
-v "$(pwd)":"$(pwd)" \
52+
--workdir "$(pwd)" \
53+
--group-add $(stat -c '%g' /var/run/docker.sock) \
54+
--network host \
55+
$IMAGE_NAME
56+
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/bin/bash
2-
. ./main.cfg
32

4-
function fail_with_error() {
5-
echo "ERROR: $1"
6-
exit 1
7-
}
3+
cd ..
4+
5+
. ./config/main.cfg
86

97
set -e
10-
trap 'fail_with_error "Command failed at line $LINENO"' ERR
118

129
# i am groot?
1310
if [ $(id -u) -ne 0 ]; then
@@ -98,4 +95,3 @@ echo Build docker images: gcc-12+kselftest+kernelci for x86
9895
echo Build docker images: gcc-12+kselftest+kernelci for arm64
9996
./kci docker $args gcc-12 kselftest kernelci --arch arm64
10097

101-

0 commit comments

Comments
 (0)