diff --git a/docker/base/Dockerfile.j2 b/docker/base/Dockerfile.j2 index b2c19198a5..3e8d6abdf1 100755 --- a/docker/base/Dockerfile.j2 +++ b/docker/base/Dockerfile.j2 @@ -183,6 +183,7 @@ RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com 199369E5404BD && apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com F78372A06FF50C80464FC1B4F7B8CEA6056E8E56 \ && apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com 430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A \ && apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com 7D5C473EB80C00FC133071068A6844A29F68104E \ + && apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com 7F6C9F236D170493FCF404F27EBFDD5D17ED316D \ && apt-get update \ && apt-get upgrade -y \ && apt-get dist-upgrade -y \ diff --git a/docker/base/sources.list b/docker/base/sources.list index ccb6f8d257..e6b6a85038 100644 --- a/docker/base/sources.list +++ b/docker/base/sources.list @@ -20,3 +20,6 @@ deb http://repo.percona.com/apt trusty main # RabbitMQ repo. Despite the name, the 'testing' repo is the stable repo. deb http://www.rabbitmq.com/debian/ testing main + +# Ceph repo +deb http://ceph.com/debian-hammer/ trusty main diff --git a/docker/ceph/ceph-base/Dockerfile.j2 b/docker/ceph/ceph-base/Dockerfile.j2 new file mode 100644 index 0000000000..fa7ea69a6d --- /dev/null +++ b/docker/ceph/ceph-base/Dockerfile.j2 @@ -0,0 +1,17 @@ +FROM {{ namespace }}/{{ base_distro }}-{{ install_type }}-base:{{ tag }} +MAINTAINER Kolla Project (https://launchpad.net/kolla) + +{% if base_distro in ['fedora', 'centos', 'oraclelinux'] %} + +RUN yum -y install ceph \ + && yum clean all + +{% elif base_distro in ['ubuntu', 'debian'] %} + +RUN apt-get install -y --no-install-recommends \ + ceph \ + parted \ + hdparm \ + && apt-get clean + +{% endif %} diff --git a/docker/ceph/ceph-mon/Dockerfile.j2 b/docker/ceph/ceph-mon/Dockerfile.j2 new file mode 100644 index 0000000000..e9d47fc708 --- /dev/null +++ b/docker/ceph/ceph-mon/Dockerfile.j2 @@ -0,0 +1,7 @@ +FROM {{ namespace }}/{{ base_distro }}-{{ install_type }}-ceph-base:{{ tag }} +MAINTAINER Kolla Project (https://launchpad.net/kolla) + +COPY start.sh / +COPY config-external.sh /opt/kolla/ + +CMD ["/start.sh"] diff --git a/docker/ceph/ceph-mon/config-external.sh b/docker/ceph/ceph-mon/config-external.sh new file mode 100644 index 0000000000..75488239c7 --- /dev/null +++ b/docker/ceph/ceph-mon/config-external.sh @@ -0,0 +1,10 @@ +#!/bin/bash +SOURCE="/opt/kolla/ceph-mon/ceph.conf" +TARGET="/etc/ceph/ceph.conf" +OWNER="ceph" + +if [[ -f "$SOURCE" ]]; then + cp $SOURCE $TARGET + chown ${OWNER}: $TARGET + chmod 0644 $TARGET +fi diff --git a/docker/ceph/ceph-mon/start.sh b/docker/ceph/ceph-mon/start.sh new file mode 100644 index 0000000000..eb5d7f5afd --- /dev/null +++ b/docker/ceph/ceph-mon/start.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -o errexit + +CMD="/usr/bin/ceph-mon" +ARGS="-d -i ${MON_NAME} --public-addr ${MON_IP}:6789" + +# Setup common paths +KEYRING_ADMIN="/etc/ceph/ceph.admin.keyring" +KEYRING_MON="/etc/ceph/ceph.mon.keyring" +MONMAP="/etc/ceph/ceph.monmap" +MON_DIR="/var/lib/ceph/mon/ceph-$(hostname)" + +# Loading common functions. +source /opt/kolla/kolla-common.sh + +# Execute config strategy +set_configs + +# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases +# of the KOLLA_BOOTSTRAP variable being set, including empty. +if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then + # Lookup our fsid from the ceph.conf + FSID="$(awk '/^fsid/ {print $3; exit}' ${ceph_conf})" + + # Generating initial keyrings and monmap + ceph-authtool --create-keyring "${KEYRING_MON}" --gen-key -n mon. --cap mon 'allow *' + ceph-authtool --create-keyring "${KEYRING_ADMIN}" --gen-key -n client.admin --set-uid=0 --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow' + ceph-authtool "${KEYRING_MON}" --import-keyring "${KEYRING_ADMIN}" + monmaptool --create --add "$(hostname)" "${MON_IP}" --fsid "${FSID}" "${MONMAP}" + + # TODO(SamYaple): Return json parsible output to ansible + exit 0 +fi + +# This section runs on every mon that does not have a keyring already. +if [[ ! -e "${MON_DIR}/keyring" ]]; then + KEYRING_TMP="/tmp/ceph.mon.keyring" + + # Generate keyring for current monitor + ceph-authtool --create-keyring "${KEYRING_TMP}" --import-keyring "${KEYRING_ADMIN}" + ceph-authtool "${KEYRING_TMP}" --import-keyring "${KEYRING_MON}" + mkdir -p "${MON_DIR}" + ceph-mon --mkfs -i "$(hostname)" --monmap "${MONMAP}" --keyring "${KEYRING_TMP}" + rm "${KEYRING_TMP}" +fi + +exec $CMD $ARGS diff --git a/docker/ceph/ceph-osd/Dockerfile.j2 b/docker/ceph/ceph-osd/Dockerfile.j2 new file mode 100644 index 0000000000..e9d47fc708 --- /dev/null +++ b/docker/ceph/ceph-osd/Dockerfile.j2 @@ -0,0 +1,7 @@ +FROM {{ namespace }}/{{ base_distro }}-{{ install_type }}-ceph-base:{{ tag }} +MAINTAINER Kolla Project (https://launchpad.net/kolla) + +COPY start.sh / +COPY config-external.sh /opt/kolla/ + +CMD ["/start.sh"] diff --git a/docker/ceph/ceph-osd/config-external.sh b/docker/ceph/ceph-osd/config-external.sh new file mode 100644 index 0000000000..8e17487edb --- /dev/null +++ b/docker/ceph/ceph-osd/config-external.sh @@ -0,0 +1,10 @@ +#!/bin/bash +SOURCE="/opt/kolla/ceph-osd/ceph.conf" +TARGET="/etc/ceph/ceph.conf" +OWNER="ceph" + +if [[ -f "$SOURCE" ]]; then + cp $SOURCE $TARGET + chown ${OWNER}: $TARGET + chmod 0644 $TARGET +fi diff --git a/docker/ceph/ceph-osd/start.sh b/docker/ceph/ceph-osd/start.sh new file mode 100644 index 0000000000..cf9114a62e --- /dev/null +++ b/docker/ceph/ceph-osd/start.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -o errexit + +CMD="/usr/bin/ceph-osd" +ARGS="-f -d -i ${OSD_ID} --osd-journal ${OSD_DIR}/journal -k ${OSD_DIR}/keyring" + +# Loading common functions. +source /opt/kolla/kolla-common.sh + +# Execute config strategy +set_configs + +# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases +# of the KOLLA_BOOTSTRAP variable being set, including empty. +if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then + # Creating a new label for the disk + parted "${OSD_DEV}" -s -- mklabel gpt + + # Preparing the OSD for use with Ceph + ceph-disk prepare "${OSD_DEV}" + OSD_ID="$(ceph osd create)" + OSD_DIR="/var/lib/ceph/osd/ceph-${OSD_ID}" + mkdir -p "${OSD_DIR}" + mount "${OSD_DEV}1" "${OSD_DIR}" + ceph-osd -i "${OSD_ID}" --mkfs --mkkey + ceph auth add "osd.${OSD_ID}" osd 'allow *' mon 'allow proflie osd' -i "${OSD_DIR}/keyring" + + # Adding osd to crush map + ceph osd crush add-bucket "$(hostname)" host + ceph osd crush move "$(hostname)" root=default + ceph osd crush add "${OSD_ID}" "${OSD_INITIAL_WEIGHT}" host="$(hostname)" + exit 0 +fi + +exec $CMD $ARGS