Skip to content

Commit fd67670

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

File tree

14 files changed

+202
-68
lines changed

14 files changed

+202
-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+
ENTRYPOINT ["/bin/bash", "./scripts/run.sh"]

localinstall/README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
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+
You can start your KernelCI deployment by simply executing:
12+
```bash
13+
./kci-deploy.sh run
14+
```
15+
and
16+
```bash
17+
./kci-deploy.sh stop
18+
```
19+
to terminate it.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

localinstall/kci-deploy.py

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

localinstall/kci-deploy.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
IMAGE_NAME="local/kernelci-deployer:latest"
6+
BUILD_IMAGE=false
7+
ACTION=""
8+
CONTAINER_ARGS=()
9+
10+
function print_help() {
11+
echo "Usage: $0 [--build] (run|stop) [args...]"
12+
echo
13+
echo "Options:"
14+
echo " --build Force rebuild of the Deployer image (optional)"
15+
echo " run Run kernelci deployment (default if no action specified)"
16+
echo " stop Stop and remove kernelci deployment"
17+
echo " -h, --help Show this help message"
18+
echo
19+
echo "Arguments after 'run' or 'stop' are passed to the container entrypoint"
20+
exit 0
21+
}
22+
23+
# Parse args
24+
while [[ $# -gt 0 ]]; do
25+
case "$1" in
26+
--build)
27+
BUILD_IMAGE=true
28+
shift
29+
;;
30+
run|stop)
31+
if [[ -n "$ACTION" ]]; then
32+
echo "Error: Cannot use both 'run' and 'stop'"
33+
exit 1
34+
fi
35+
ACTION=$1
36+
shift
37+
CONTAINER_ARGS=("$@")
38+
break
39+
;;
40+
-h|--help)
41+
print_help
42+
;;
43+
*)
44+
echo "Unknown option: $1"
45+
print_help
46+
;;
47+
esac
48+
done
49+
50+
# Default
51+
if [[ -z "$ACTION" ]]; then
52+
ACTION="run"
53+
fi
54+
55+
USER_ID=$(id -u)
56+
GROUP_ID=$(id -g)
57+
58+
if [[ "$BUILD_IMAGE" = true || -z $(docker images -q "$IMAGE_NAME") ]]; then
59+
echo "Building $IMAGE_NAME"
60+
docker build \
61+
--build-arg USER_ID=$USER_ID \
62+
--build-arg GROUP_ID=$GROUP_ID \
63+
-f Containerfile \
64+
-t "$IMAGE_NAME" \
65+
.
66+
fi
67+
68+
echo "Running $IMAGE_NAME with action '$ACTION' and args: ${CONTAINER_ARGS[*]}"
69+
docker run --rm \
70+
--name kernelci-deployer \
71+
-v /var/run/docker.sock:/var/run/docker.sock \
72+
-v "$(pwd)":"$(pwd)" \
73+
--workdir "$(pwd)" \
74+
--group-add "$(stat -c '%g' /var/run/docker.sock)" \
75+
--network host \
76+
"$IMAGE_NAME" \
77+
"$ACTION" "${CONTAINER_ARGS[@]}"

localinstall/1-rebuild_all.sh renamed to localinstall/scripts/1-rebuild_all.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#!/bin/bash
2-
. ./main.cfg
32

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

95
set -e
10-
trap 'fail_with_error "Command failed at line $LINENO"' ERR
116

127
# i am groot?
138
if [ $(id -u) -ne 0 ]; then
@@ -98,4 +93,3 @@ echo Build docker images: gcc-12+kselftest+kernelci for x86
9893
echo Build docker images: gcc-12+kselftest+kernelci for arm64
9994
./kci docker $args gcc-12 kselftest kernelci --arch arm64
10095

101-

0 commit comments

Comments
 (0)