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

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.

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-

localinstall/2-install_api.sh renamed to localinstall/scripts/2-install_api.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/bin/sh
2-
. ./main.cfg
1+
#!/bin/bash
32

43
# is docker-compose exists? if not use docker compose
54
if [ -z "$(which docker-compose)" ]; then
@@ -9,13 +8,9 @@ else
98
DOCKER_COMPOSE="docker-compose"
109
fi
1110

12-
function fail_with_error() {
13-
echo "ERROR: $1"
14-
exit 1
15-
}
11+
. ./config/main.cfg
1612

1713
set -e
18-
trap 'fail_with_error "Command failed at line $LINENO"' ERR
1914

2015
# i am groot?
2116
if [ $(id -u) -ne 0 ]; then
@@ -24,24 +19,25 @@ else
2419
SUDO=
2520
fi
2621

27-
cp .env-api kernelci/kernelci-api/.env
28-
cp api-configs.yaml kernelci/kernelci-core/config/core/
29-
cp kernelci-cli.toml kernelci/kernelci-core/kernelci.toml
22+
cp config/.env-api kernelci/kernelci-api/.env
23+
cp config/api-configs.yaml kernelci/kernelci-core/config/core/
24+
cp config/kernelci-cli.toml kernelci/kernelci-core/kernelci.toml
3025

3126
cd kernelci/kernelci-api
3227
mkdir -p docker/redis/data
3328
${SUDO} chmod -R 0777 docker/storage/data
3429
${SUDO} chmod -R 0777 docker/redis/data
3530
# enable ssh and storage nginx
31+
mkdir -p ../../config/out
3632
sed -i 's/^# / /' docker-compose.yaml
37-
if [ -f ../../ssh.key ]; then
33+
if [ -f ../../config/out/ssh.key ]; then
3834
echo "ssh.key already exists"
3935
else
4036
# generate non-interactively ssh key to ssh.key
41-
ssh-keygen -t rsa -b 4096 -N "" -f ../../ssh.key
37+
ssh-keygen -t rsa -b 4096 -N "" -f ../../config/out/ssh.key
4238
fi
4339
# get public key and add to docker/ssh/user-data/authorized_keys
44-
cat ../../ssh.key.pub > docker/ssh/user-data/authorized_keys
40+
cat ../../config/out/ssh.key.pub > docker/ssh/user-data/authorized_keys
4541

4642
# down, just in case old containers are running
4743
${DOCKER_COMPOSE} down
@@ -75,8 +71,8 @@ expect ../../helpers/scripts_setup_admin_user.exp "${YOUR_EMAIL}" "${ADMIN_PASSW
7571

7672
cd ../kernelci-core
7773
echo "Issuing token for admin user"
78-
expect ../../helpers/kci_user_token_admin.exp "${ADMIN_PASSWORD}" > ../../admin-token.txt
79-
ADMIN_TOKEN=$(cat ../../admin-token.txt)
74+
expect ../../helpers/kci_user_token_admin.exp "${ADMIN_PASSWORD}" > ../../config/out/admin-token.txt
75+
ADMIN_TOKEN=$(cat ../../config/out/admin-token.txt)
8076

8177
echo "[kci.secrets]
8278
api.\"docker-host\".token = \"$ADMIN_TOKEN\"

localinstall/3-install_pipeline.sh renamed to localinstall/scripts/3-install_pipeline.sh

Lines changed: 3 additions & 8 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
## This is hacky way of inserting things that probably will outlive trivial patch after changes
138
# find line number with storage:
@@ -62,7 +57,7 @@ sed -i "s|- '/data/kernelci-deploy-checkout/kernelci-pipeline/data/output/|- '$P
6257
# set 777 to data/output and data/ssh (TODO: or set proper uid, kernelci is 1000?)
6358
chmod -R 777 data
6459
chmod 777 data/ssh
65-
cp ../../ssh.key data/ssh/id_rsa_tarball
60+
cp ../../config/out/ssh.key data/ssh/id_rsa_tarball
6661
chown 1000:1000 data/ssh/id_rsa_tarball
6762
chmod 600 data/ssh/id_rsa_tarball
6863
cd ../..
@@ -95,7 +90,7 @@ EOF
9590
#KCI_STORAGE_CREDENTIALS=L0CALT0KEN
9691
#KCI_API_TOKEN=
9792
#API_TOKEN=
98-
API_TOKEN=$(cat admin-token.txt)
93+
API_TOKEN=$(cat config/out/admin-token.txt)
9994
echo "KCI_STORAGE_CREDENTIALS=/home/kernelci/data/ssh/id_rsa_tarball" > .env
10095
echo "KCI_API_TOKEN=${API_TOKEN}" >> .env
10196
echo "API_TOKEN=${API_TOKEN}" >> .env

localinstall/4-start-cycle.sh renamed to localinstall/scripts/4-start_cycle.sh

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

43
# is docker-compose exists? if not use docker compose
54
if [ -z "$(which docker-compose)" ]; then
@@ -9,13 +8,9 @@ else
98
DOCKER_COMPOSE="docker-compose"
109
fi
1110

12-
function fail_with_error() {
13-
echo "ERROR: $1"
14-
exit 1
15-
}
11+
. ./config/main.cfg
1612

1713
set -e
18-
trap 'fail_with_error "Command failed at line $LINENO"' ERR
1914

2015
cd kernelci/kernelci-pipeline
2116
${DOCKER_COMPOSE} down

localinstall/scripts/run.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
ACTION=$1
6+
7+
function print_help() {
8+
echo "Usage: $0 (run|stop)"
9+
echo
10+
echo " run Execute deployment sequence"
11+
echo " stop Stop and remove deployment"
12+
exit 1
13+
}
14+
15+
if [[ -z "$ACTION" ]]; then
16+
echo "Error: Missing required action (run or stop)"
17+
print_help
18+
fi
19+
20+
case "$ACTION" in
21+
run)
22+
echo "Starting deployment sequence, this may take a while..."
23+
./scripts/1-rebuild_all.sh
24+
./scripts/2-install_api.sh
25+
./scripts/3-install_pipeline.sh
26+
./scripts/4-start_cycle.sh
27+
;;
28+
stop)
29+
echo "Stopping deployment"
30+
cd kernelci/kernelci-api
31+
docker compose down
32+
cd ../kernelci-pipeline
33+
docker compose down
34+
;;
35+
*)
36+
echo "Error: Invalid action '$ACTION'"
37+
print_help
38+
;;
39+
esac

0 commit comments

Comments
 (0)