64280dd7eb8e29faf02b342ccab48b704ce66406
[ceph.git] / make-dist
1 #!/bin/bash -e
2
3 if [ ! -d .git ]; then
4     echo "no .git present.  run this from the base dir of the git checkout."
5     exit 1
6 fi
7
8 version=$1
9 [ -z "$version" ] && version=$(git describe --long --match 'v*' | sed 's/^v//')
10 if expr index $version '-' > /dev/null; then
11     rpm_version=$(echo $version | cut -d - -f 1-1)
12     rpm_release=$(echo $version | cut -d - -f 2- | sed 's/-/./')
13 else
14     rpm_version=$version
15     rpm_release=0
16 fi
17
18 outfile="ceph-$version"
19 echo "version $version"
20
21 # update submodules
22 echo "updating submodules..."
23 force=$(if git submodule usage 2>&1 | grep --quiet 'update.*--force'; then echo --force ; fi)
24 if ! git submodule sync || ! git submodule update $force --init --recursive; then
25     echo "Error: could not initialize submodule projects"
26     echo "  Network connectivity might be required."
27     exit 1
28 fi
29
30 download_boost() {
31     boost_version=$1
32     shift
33     boost_sha256=$1
34     shift
35     boost_version_underscore=$(echo $boost_version | sed 's/\./_/g')
36     boost_fname=boost_${boost_version_underscore}.tar.bz2
37     set +e
38     while true; do
39         url_base=$1
40         shift
41         if [ -z $url_base ]; then
42             echo "Error: failed to download boost."
43             exit
44         fi
45         url=$url_base/$boost_fname
46         wget -c --no-verbose -O $boost_fname $url
47         if [ $? != 0 -o ! -e $boost_fname ]; then
48             echo "Download of $url failed"
49         elif [ $(sha256sum $boost_fname | awk '{print $1}') != $boost_sha256 ]; then
50             echo "Error: failed to download boost: SHA256 mismatch."
51         else
52             break
53         fi
54     done
55     set -e
56     tar xjf $boost_fname -C src \
57         --exclude="$boost_version_underscore/libs/*/doc" \
58         --exclude="$boost_version_underscore/libs/*/example" \
59         --exclude="$boost_version_underscore/libs/*/examples" \
60         --exclude="$boost_version_underscore/libs/*/meta" \
61         --exclude="$boost_version_underscore/libs/*/test" \
62         --exclude="$boost_version_underscore/tools/boostbook" \
63         --exclude="$boost_version_underscore/tools/quickbook" \
64         --exclude="$boost_version_underscore/tools/auto_index" \
65         --exclude='doc' --exclude='more' --exclude='status'
66     mv src/boost_${boost_version_underscore} src/boost
67     tar cf ${outfile}.boost.tar ${outfile}/src/boost
68     rm -rf src/boost
69 }
70
71 _python_autoselect() {
72   python_command=
73   for interpreter in python2.7 python3 ; do
74     type $interpreter > /dev/null 2>&1 || continue
75     python_command=$interpreter
76     break
77   done
78   if [ -z "$python_command" ] ; then
79     echo "Could not find a suitable python interpreter! Bailing out."
80     exit 1
81   fi
82   echo $python_command
83 }
84
85 build_dashboard_frontend() {
86   CURR_DIR=`pwd`
87   TEMP_DIR=`mktemp -d`
88   $CURR_DIR/src/tools/setup-virtualenv.sh --python=$(_python_autoselect) $TEMP_DIR
89   $TEMP_DIR/bin/pip install nodeenv
90   $TEMP_DIR/bin/nodeenv -p --node=10.13.0
91   cd src/pybind/mgr/dashboard/frontend
92   . $TEMP_DIR/bin/activate
93   npm ci
94   npm run build -- --prod --progress=false
95   deactivate
96   cd $CURR_DIR
97   rm -rf $TEMP_DIR
98   tar cf dashboard_frontend.tar $outfile/src/pybind/mgr/dashboard/frontend/dist
99 }
100
101 # clean out old cruft...
102 echo "cleanup..."
103 rm -f $outfile*
104
105 # build new tarball
106 echo "building tarball..."
107 bin/git-archive-all.sh --prefix ceph-$version/ \
108                        --verbose \
109                        --ignore corpus \
110                        $outfile.tar
111
112 # populate files with version strings
113 echo "including src/.git_version, ceph.spec"
114
115 (git rev-parse HEAD ; echo $version) 2> /dev/null > src/.git_version
116
117 for spec in ceph.spec.in alpine/APKBUILD.in; do
118     cat $spec |
119         sed "s/@VERSION@/$rpm_version/g" |
120         sed "s/@RPM_RELEASE@/$rpm_release/g" |
121         sed "s/@TARBALL_BASENAME@/ceph-$version/g" > `echo $spec | sed 's/.in$//'`
122 done
123 ln -s . $outfile
124 tar cvf $outfile.version.tar $outfile/src/.git_version $outfile/ceph.spec $outfile/alpine/APKBUILD
125 # NOTE: If you change this version number make sure the package is available
126 # at the three URLs referenced below (may involve uploading to download.ceph.com)
127 boost_version=1.67.0
128 download_boost $boost_version 2684c972994ee57fc5632e03bf044746f6eb45d4920c343937a465fd67a5adba \
129                https://dl.bintray.com/boostorg/release/$boost_version/source \
130                https://downloads.sourceforge.net/project/boost/boost/$boost_version \
131                https://download.ceph.com/qa
132 build_dashboard_frontend
133 tar --concatenate -f $outfile.all.tar $outfile.version.tar
134 tar --concatenate -f $outfile.all.tar $outfile.boost.tar
135 tar --concatenate -f $outfile.all.tar $outfile.tar
136 tar --concatenate -f $outfile.all.tar dashboard_frontend.tar
137 mv $outfile.all.tar $outfile.tar
138 rm $outfile
139 rm -f $outfile.version.tar
140 rm -f $outfile.boost.tar
141
142 echo "compressing..."
143 bzip2 -9 $outfile.tar
144
145 echo "done."