cephadm/box: Wrap ceph docker and add some util scripts

Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
This commit is contained in:
Pere Diaz Bou 2021-09-23 13:12:09 +02:00
parent b787fa4c75
commit 6f87be64f1
6 changed files with 81 additions and 4 deletions

View File

@ -21,6 +21,10 @@ RUN dnf -y install docker-ce && \
dnf clean all && systemctl enable docker
EXPOSE 8443
RUN dnf install sudo which -y
FROM centos-systemd-docker
WORKDIR /root
COPY start /usr/local/bin

View File

@ -18,10 +18,16 @@ services:
- "/sys/fs/cgroup:/sys/fs/cgroup:ro"
networks:
- public
mem_limit: "20g"
devices:
- /dev/loop0:/dev/ttt:rwm
scale: -1
seed:
extends:
service: cephadm-host-base
volumes:
- ../../../:/ceph
- ..:/cephadm
ports:
- "3000:3000"
- "8443:8443"

View File

@ -0,0 +1,4 @@
FROM quay.ceph.io/ceph-ci/ceph:master
RUN dnf install which sudo -y
EXPOSE 8443

33
src/cephadm/box/setup_loop.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
set -x
# This script works best outside docker right now.
# TODO: remove this file in the future or extend with something more extensible.
# For now let's just use this.
# look for an available loop device
avail_loop=$(sudo losetup -f)
loop_name=$(basename -- $avail_loop)
# in case we have to create the loop, find the minor device number.
num_loops=$(lsmod | grep loop | awk '{print $3}')
num_loops=$((num_loops + 1))
echo creating loop $avail_loop minor: $num_loops
mknod $avail_loop b 7 $num_loops
sudo umount $avail_loop
sudo losetup -d $avail_loop
mkdir -p loop-images
sudo fallocate -l 10G "loop-images/disk${loop_name}.img"
sudo losetup $avail_loop "loop-images/disk${loop_name}.img"
sudo wipefs -a $avail_loop
# TODO: We will need more than one LVs
sudo lvm lvremove /dev/vg1/lv1
sudo lvm vgremove vg1
sudo pvcreate $avail_loop
sudo vgcreate vg1 $avail_loop
# 6G is arbitrary, osds need 5 I think. Just in case.
sudo lvcreate --size 6G --name lv1 vg1

19
src/cephadm/box/setup_ssh.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# SSH
if [[ ! -f "/root/.ssh/id_rsa" ]]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""
fi
cat ~/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
if [[ ! -f "/root/.ssh/known_hosts" ]]; then
ssh-keygen -A
fi
dnf install -y openssh-server
/usr/sbin/sshd
# no password
echo "root:" | chpasswd
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

View File

@ -2,10 +2,10 @@
set -euxo pipefail
CEPHADM_PATH=/usr/local/sbin/cephadm
curl --silent \
--location "https://github.com/ceph/ceph/raw/${CEPH_BRANCH:-master}/src/cephadm/cephadm" \
--output $CEPHADM_PATH \
&& chmod +x $CEPHADM_PATH
dnf install which sudo -y
cp /cephadm/cephadm $CEPHADM_PATH
chmod +x $CEPHADM_PATH
tail -f /var/log/ceph/cephadm.log 1>&2 &
@ -14,9 +14,20 @@ if [[ -n "${SHARED_CEPH_FOLDER-}" ]]; then
EXTRA_ARGS+=(--shared_ceph_folder "$SHARED_CEPH_FOLDER")
fi
# TODO: remove docker build image and skill pull when cephadm's dependencies
# use which or it is removed.
# If we use a ceph image cephadm won't skip pulling the image. If it's a
# local image, it will fail.
docker build -t quay.ceph.io/ceph-ci/ceph:master /cephadm/box/docker/ceph
CEPHADM_IMAGE=quay.ceph.io/ceph-ci/ceph:master
if [[ -n "$CEPHADM_IMAGE" ]]; then
EXTRA_ARGS+=--skip-pull
fi
$CEPHADM_PATH bootstrap \
--mon-ip "$(hostname -i)" \
--allow-fqdn-hostname \
--initial-dashboard-password admin \
--dashboard-password-noupdate \
--allow-overwrite \
"${EXTRA_ARGS[@]}"