]> git.proxmox.com Git - ceph.git/blob - ceph/src/script/cpatch
import quincy beta 17.1.0
[ceph.git] / ceph / src / script / cpatch
1 #!/bin/bash -e
2
3 SCRIPT=$(readlink -f "$0")
4 SCRIPTPATH=$(dirname "$SCRIPT")
5 BUILDPATH=$(pwd)
6
7 if [ ! -e Makefile ] && [ ! -e build.ninja ] || [ ! -e ../do_cmake.sh ]; then
8 echo "must run from cmake build dir"
9 exit 1
10 fi
11
12 base="quay.ceph.io/ceph-ci/ceph:master"
13 target=""
14 push=0
15 strip=1
16
17 py=0
18 dashboard=0
19 core=0
20 cephfs=0
21 rgw=0
22 rbd=0
23 all=1
24 asroot=""
25
26 usage() {
27 echo "usage: $SCRIPT [options]"
28 echo " --base <image> base container image [$base]"
29 echo " --target <image> target image (required)"
30 echo " --push push when done"
31 echo " --strip strip binaries"
32 echo " --root-build build image as root"
33 echo
34 echo " --py python components (python-common, mgr)"
35 echo " --dashboard dashboard"
36 echo " --core mon, mgr, osd, mds, bins and libraries"
37 echo " --rgw radosgw, radosgw-admin"
38 }
39
40 while [ -n "$1" ]; do
41 case $1 in
42 --base)
43 shift
44 base="$1"
45 ;;
46 --target | -t)
47 shift
48 target="$1"
49 ;;
50 --nostrip)
51 strip=0
52 ;;
53 --root-build)
54 asroot="sudo"
55 ;;
56 -h | --help)
57 usage
58 exit 0
59 ;;
60 --push)
61 push=1
62 ;;
63
64 --py)
65 py=1
66 all=0
67 ;;
68 --dashboard)
69 py=1
70 dashboard=1
71 all=0
72 ;;
73 --core)
74 core=1
75 all=0
76 rbd=1
77 cephfs=1
78 ;;
79 --rgw)
80 rgw=1
81 all=0
82 ;;
83
84 *)
85 echo "unrecognized option $1"
86 exit 1
87 ;;
88 esac
89 shift
90 done
91
92 if [ -z "$target" ]; then
93 echo "must specify --target <image>"
94 exit 1
95 fi
96
97 if [ -x /usr/bin/podman ]; then
98 runtime="podman"
99 elif [ -x /usr/bin/docker ]; then
100 runtime="docker"
101 else
102 echo "cannot find podman or docker in PATH"
103 exit 1
104 fi
105
106 TMP="$BUILDPATH/tmp.cpatch"
107 if [ -d $TMP ]; then rm -rf $TMP ; fi
108 mkdir -p $TMP
109
110 if [ $all -eq 1 ]; then
111 echo "consider --py, --core, and/or --rgw for an abbreviated (faster) build."
112 fi
113
114 dockerfile="FROM $base"$'\n'
115
116 if [ $py -eq 1 ] || [ $all -eq 1 ]; then
117 pushd ../src/pybind/mgr > /dev/null
118 find ./ -name "*.pyc" -exec rm -f {} \;
119 if [ $dashboard -eq 1 ] || [ $all -eq 1 ]; then
120 echo "py + dashboard"
121 exclude=""
122 else
123 echo "py"
124 # Exclude node_modules because it's the huge sources in
125 # dashboard/frontend
126 exclude="--exclude=node_modules"
127 fi
128 tar $exclude --exclude=tests --exclude-backups -cf $TMP/mgr_plugins.tar *
129 popd > /dev/null
130 dockerfile+=$'ADD mgr_plugins.tar /usr/share/ceph/mgr\n'
131
132 pushd ../src/python-common > /dev/null
133 find ./ -name "*.pyc" -exec rm -f {} \;
134 # Exclude node_modules because it's the huge sources in dashboard/frontend
135 tar --exclude=node_modules --exclude=tests --exclude-backups -cf $TMP/python_common.tar *
136 popd > /dev/null
137 dockerfile+=$'ADD python_common.tar /usr/lib/python3.8/site-packages\n'
138
139 pushd lib/cython_modules/lib.3
140 CYTHONLIBS="*.cpython-3*.so"
141 mkdir -p $TMP/cythonlib
142 for f in $CYTHONLIBS; do cp $f $TMP/cythonlib ; done
143 [ $strip -eq 1 ] && strip $TMP/cythonlib/*
144 popd > /dev/null
145 dockerfile+=$'ADD cythonlib /usr/lib64/python3.8/site-packages\n'
146
147 # cephadm
148 pushd ../src/cephadm > /dev/null
149 cp cephadm $TMP/cephadm
150 dockerfile+=$'ADD cephadm /usr/sbin/cephadm\n'
151 popd > /dev/null
152 fi
153
154 if [ $core -eq 1 ] || [ $all -eq 1 ]; then
155 # binaries are annoying because the ceph version is embedded all over
156 # the place, so we have to include everything but the kitchen sink.
157 echo "core"
158
159 BINS="ceph-mgr ceph-mon ceph-osd rados"
160 mkdir -p $TMP/bin
161 for f in $BINS; do cp bin/$f $TMP/bin ; done
162 [ $strip -eq 1 ] && strip $TMP/bin/*
163 dockerfile+=$'ADD bin /usr/bin\n'
164
165 # We need ceph-common to support the binaries
166 # We need librados/rbd to support mgr modules
167 # that import the python bindings
168 LIBS="libceph-common.so.2 libceph-common.so librados.so.2 librados.so librados.so.2.0.0"
169 mkdir -p $TMP/lib
170 for f in $LIBS; do cp lib/$f $TMP/lib ; done
171 [ $strip -eq 1 ] && strip $TMP/lib/*
172 dockerfile+=$'ADD lib /usr/lib64\n'
173
174 ECLIBS="libec_*.so*"
175 mkdir -p $TMP/eclib
176 for f in lib/$ECLIBS; do cp $f $TMP/eclib ; done
177 [ $strip -eq 1 ] && strip $TMP/eclib/*
178 dockerfile+=$'ADD eclib /usr/lib64/ceph/erasure-code\n'
179
180 CLSLIBS="libcls_*.so*"
181 mkdir -p $TMP/clslib
182 for f in lib/$CLSLIBS; do cp $f $TMP/clslib ; done
183 [ $strip -eq 1 ] && strip $TMP/clslib/*
184 dockerfile+=$'ADD clslib /usr/lib64/rados-classes\n'
185
186 # by default locally built binaries assume /usr/local
187 dockerfile+=$'RUN rm -rf /usr/local/lib64 ; ln -s /usr/lib64 /usr/local ; ln -s /usr/share/ceph /usr/local/share\n'
188 fi
189
190 if [ $rgw -eq 1 ] || [ $all -eq 1 ]; then
191 echo "rgw"
192 RGW="radosgw radosgw-admin"
193 mkdir -p $TMP/rgw
194 for f in $RGW; do cp bin/$f $TMP/rgw ; done
195 [ $strip -eq 1 ] && strip $TMP/rgw/*
196 dockerfile+=$'ADD rgw /usr/bin\n'
197
198 RGWLIBS="libradosgw.so*"
199 mkdir -p $TMP/rgwlib
200 for f in lib/$RGWLIBS; do cp $f $TMP/rgwlib ; done
201 [ $strip -eq 1 ] && strip $TMP/rgwlib/*
202 dockerfile+=$'ADD rgwlib /usr/lib64\n'
203 fi
204
205 if [ $cephfs -eq 1 ] || [ $all -eq 1 ]; then
206 echo "cephfs"
207 FS="ceph-mds"
208 mkdir -p $TMP/fs
209 for f in $FS; do cp bin/$f $TMP/fs ; done
210 [ $strip -eq 1 ] && strip $TMP/fs/*
211 dockerfile+=$'ADD fs /usr/bin\n'
212
213 FSLIBS="libcephfs.so*"
214 mkdir -p $TMP/fslib
215 for f in lib/$FSLIBS; do cp $f $TMP/fslib ; done
216 [ $strip -eq 1 ] && strip $TMP/fslib/*
217 dockerfile+=$'ADD fslib /usr/lib64\n'
218 fi
219
220 if [ $rbd -eq 1 ] || [ $all -eq 1 ]; then
221 echo "rbd"
222 RBD="rbd rbd-mirror"
223 mkdir -p $TMP/rbd
224 for f in $RBD; do cp bin/$f $TMP/rbd ; done
225 [ $strip -eq 1 ] && strip $TMP/rbd/*
226 dockerfile+=$'ADD rbd /usr/bin\n'
227
228 RBDLIBS="librbd.so*"
229 mkdir -p $TMP/rbdlib
230 for f in lib/$RBDLIBS; do cp $f $TMP/rbdlib ; done
231 [ $strip -eq 1 ] && strip $TMP/rbdlib/*
232 dockerfile+=$'ADD rbdlib /usr/lib64\n'
233 fi
234
235 echo "build"
236 pushd $TMP > /dev/null
237 echo "$dockerfile" > Dockerfile
238 $asroot $runtime build -t $target .
239 popd > /dev/null
240
241 if [ $push -eq 1 ]; then
242 echo "push"
243 $asroot $runtime push $target
244 fi
245
246 rm -r $TMP