]> git.proxmox.com Git - ceph.git/blame - ceph/src/script/ceph-debug-docker.sh
import quincy beta 17.1.0
[ceph.git] / ceph / src / script / ceph-debug-docker.sh
CommitLineData
11fdf7f2 1#!/usr/bin/env bash
c07f9fc5
FG
2
3# This can be run from e.g. the senta machines which have docker available. You
4# may need to run this script with sudo.
5#
6# Once you have booted into the image, you should be able to debug the core file:
7# $ gdb -q /ceph/teuthology-archive/.../coredump/1500013578.8678.core
8#
9# You may want to install other packages (yum) as desired.
10#
11# Once you're finished, please delete old images in a timely fashion.
12
13set -e
14
15CACHE=""
f67539c2 16FLAVOR="default"
20effc67
TL
17SUDO=""
18PRIVILEGED=""
c07f9fc5
FG
19
20function run {
21 printf "%s\n" "$*"
22 "$@"
23}
24
25function main {
20effc67 26 eval set -- $(getopt --name "$0" --options 'h' --longoptions 'help,no-cache,flavor:,sudo,privileged' -- "$@")
c07f9fc5
FG
27
28 while [ "$#" -gt 0 ]; do
29 case "$1" in
30 -h|--help)
11fdf7f2 31 printf '%s: [--no-cache] <branch>[:sha1] <environment>\n' "$0"
c07f9fc5
FG
32 exit 0
33 ;;
34 --no-cache)
35 CACHE="--no-cache"
36 shift
37 ;;
f67539c2
TL
38 --flavor)
39 FLAVOR=$2
40 shift 2
41 ;;
20effc67
TL
42 --privileged)
43 PRIVILEGED=--privileged
44 shift 1
45 ;;
46 --sudo)
47 SUDO=sudo
48 shift 1
49 ;;
c07f9fc5
FG
50 --)
51 shift
52 break
53 ;;
54 esac
55 done
56
57 if [ -z "$1" ]; then
11fdf7f2 58 printf "specify the branch [default \"master:latest\"]: "
20effc67
TL
59 read branch
60 if [ -z "$branch" ]; then
61 branch=master:latest
c07f9fc5
FG
62 fi
63 else
64 branch="$1"
65 fi
11fdf7f2
TL
66 if [ "${branch%%:*}" != "${branch}" ]; then
67 sha=${branch##*:}
68 else
69 sha=latest
70 fi
71 branch=${branch%%:*}
72 printf "branch: %s\nsha1: %s\n" "$branch" "$sha"
c07f9fc5
FG
73
74 if [ -z "$2" ]; then
f67539c2 75 printf "specify the build environment [default \"centos:8\"]: "
c07f9fc5
FG
76 read env
77 if [ -z "$env" ]; then
f67539c2 78 env=centos:8
c07f9fc5
FG
79 fi
80 else
81 env="$2"
82 fi
83 printf "env: %s\n" "$env"
84
85 if [ -n "$SUDO_USER" ]; then
86 user="$SUDO_USER"
87 elif [ -n "$USER" ]; then
88 user="$USER"
89 else
90 user="$(whoami)"
91 fi
92
11fdf7f2 93 tag="${user}:ceph-ci-${branch}-${sha}-${env/:/-}"
c07f9fc5
FG
94
95 T=$(mktemp -d)
96 pushd "$T"
20effc67
TL
97 case "$env" in
98 centos:stream)
99 distro="centos/8"
100 ;;
101 *)
102 distro="${env/://}"
103 esac
104 api_url="https://shaman.ceph.com/api/search/?status=ready&project=ceph&flavor=${FLAVOR}&distros=${distro}/$(arch)&ref=${branch}&sha1=${sha}"
105 repo_url="$(wget -O - "$api_url" | jq -r '.[0].chacra_url')repo"
106 # validate url:
107 wget -O /dev/null "$repo_url"
c07f9fc5
FG
108 if grep ubuntu <<<"$env" > /dev/null 2>&1; then
109 # Docker makes it impossible to access anything outside the CWD : /
20effc67 110 wget -O cephdev.asc 'https://download.ceph.com/keys/autobuild.asc'
c07f9fc5
FG
111 cat > Dockerfile <<EOF
112FROM ${env}
113
114WORKDIR /root
115RUN apt-get update --yes --quiet && \
11fdf7f2 116 apt-get install --yes --quiet screen gdb software-properties-common apt-transport-https curl
c07f9fc5 117COPY cephdev.asc cephdev.asc
11fdf7f2 118RUN apt-key add cephdev.asc && \
f67539c2 119 curl -L $repo_url | tee /etc/apt/sources.list.d/ceph_dev.list && \
c07f9fc5 120 apt-get update --yes && \
11fdf7f2 121 DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt-get --assume-yes -q --no-install-recommends install -o Dpkg::Options::=--force-confnew --allow-unauthenticated ceph ceph-osd-dbg ceph-mds-dbg ceph-mgr-dbg ceph-mon-dbg ceph-common-dbg ceph-fuse-dbg ceph-test-dbg radosgw-dbg python3-cephfs python3-rados
c07f9fc5 122EOF
20effc67 123 time run $SUDO docker build $CACHE --tag "$tag" .
c07f9fc5 124 else # try RHEL flavor
f67539c2
TL
125 case "$env" in
126 centos:7)
127 python_bindings="python36-rados python36-cephfs"
20effc67 128 base_debuginfo=""
f67539c2 129 ceph_debuginfo="ceph-debuginfo"
20effc67 130 debuginfo=/etc/yum.repos.d/CentOS-Linux-Debuginfo.repo
f67539c2
TL
131 ;;
132 centos:8)
133 python_bindings="python3-rados python3-cephfs"
20effc67
TL
134 base_debuginfo="glibc-debuginfo"
135 ceph_debuginfo="ceph-base-debuginfo"
136 debuginfo=/etc/yum.repos.d/CentOS-Linux-Debuginfo.repo
137 ;;
138 centos:stream)
139 python_bindings="python3-rados python3-cephfs"
140 base_debuginfo="glibc-debuginfo"
f67539c2 141 ceph_debuginfo="ceph-base-debuginfo"
20effc67 142 debuginfo=/etc/yum.repos.d/CentOS-Stream-Debuginfo.repo
f67539c2
TL
143 ;;
144 esac
145 if [ "${FLAVOR}" = "crimson" ]; then
146 ceph_debuginfo+=" ceph-crimson-osd-debuginfo ceph-crimson-osd"
147 fi
20effc67 148 cat > Dockerfile <<EOF
c07f9fc5
FG
149FROM ${env}
150
151WORKDIR /root
152RUN yum update -y && \
20effc67
TL
153 sed -i 's/enabled=0/enabled=1/' ${debuginfo} && \
154 yum update -y && \
f67539c2
TL
155 yum install -y tmux epel-release wget psmisc ca-certificates gdb
156RUN wget -O /etc/yum.repos.d/ceph-dev.repo $repo_url && \
c07f9fc5
FG
157 yum clean all && \
158 yum upgrade -y && \
20effc67 159 yum install -y ceph ${base_debuginfo} ${ceph_debuginfo} ${python_bindings}
c07f9fc5 160EOF
20effc67 161 time run $SUDO docker build $CACHE --tag "$tag" .
c07f9fc5
FG
162 fi
163 popd
164 rm -rf -- "$T"
165
11fdf7f2 166 printf "built image %s\n" "$tag"
c07f9fc5 167
20effc67 168 run $SUDO docker run $PRIVILEGED -ti -v /ceph:/ceph:ro -v /cephfs:/cephfs:ro -v /teuthology:/teuthology:ro "$tag"
c07f9fc5
FG
169 return 0
170}
171
172main "$@"