2016-01-12 13:08:43 +01:00
|
|
|
#!/usr/bin/env bash
|
2016-11-22 07:00:12 +01:00
|
|
|
set -eux
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [--py3] <ZULIP_VERSION>" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
args="$(getopt -o '' -l 'py3' -n "$0" -- "$@")"
|
|
|
|
eval "set -- $args"
|
|
|
|
|
|
|
|
py3=
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--py3) py3=t; shift;;
|
|
|
|
--) shift; break;;
|
|
|
|
*) usage;;
|
|
|
|
esac
|
|
|
|
done
|
2013-10-29 20:04:55 +01:00
|
|
|
|
2013-11-01 20:54:41 +01:00
|
|
|
GITID=$(git rev-parse HEAD)
|
|
|
|
|
2016-11-22 07:00:12 +01:00
|
|
|
if [ -z "${1:-}" ]; then
|
|
|
|
usage
|
2013-11-13 22:50:40 +01:00
|
|
|
fi
|
|
|
|
version="$1"
|
|
|
|
prefix="zulip-server-$version"
|
|
|
|
|
2013-11-06 19:15:04 +01:00
|
|
|
if [ "$(uname)" = "Darwin" ]; then
|
2015-08-21 11:48:43 +02:00
|
|
|
TMPDIR=/tmp/voyager-build
|
2015-09-26 03:47:30 +02:00
|
|
|
rm -Rf "$TMPDIR"
|
|
|
|
mkdir -p "$TMPDIR"
|
2013-11-06 19:15:04 +01:00
|
|
|
else
|
|
|
|
TMPDIR=$(mktemp -d)
|
|
|
|
fi
|
|
|
|
|
2015-09-21 00:09:51 +02:00
|
|
|
if ! git diff --exit-code >/dev/null; then
|
|
|
|
set +x
|
|
|
|
echo; echo "\033[31mWARNING: tarballs builds are based on a commit hash so your changes will not be included\033[0m"; echo
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2013-11-13 22:50:40 +01:00
|
|
|
TMP_CHECKOUT=$TMPDIR/$prefix/
|
|
|
|
TARBALL=$TMPDIR/$prefix.tar
|
2013-11-01 20:54:41 +01:00
|
|
|
|
2013-11-12 17:13:19 +01:00
|
|
|
# .gitattributes lists the files that are not exported
|
2015-09-26 03:47:30 +02:00
|
|
|
git archive -o "$TARBALL" "--prefix=$prefix/" HEAD
|
2013-11-01 20:54:41 +01:00
|
|
|
|
2013-11-13 00:46:35 +01:00
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
if tar -tf "$TARBALL" | grep -q -e zilencer -e zproject/local_settings.py -e puppet/zulip_internal; then
|
2013-11-13 00:46:35 +01:00
|
|
|
echo "Excluded files remain in tarball!";
|
|
|
|
echo "Versions of git 1.8.1.1 - 1.8.1.6 have broken .gitattributes syntax";
|
|
|
|
exit 1;
|
|
|
|
else
|
|
|
|
echo "Check for excluded files passed";
|
|
|
|
fi
|
|
|
|
|
2016-11-22 07:00:12 +01:00
|
|
|
if [ "$py3" ]; then
|
|
|
|
tools/replace-tarball-shebang \
|
|
|
|
'#!/usr/bin/env python' '#!/usr/bin/env python3' \
|
|
|
|
< "$TARBALL" > "$TARBALL.new"
|
|
|
|
mv "$TARBALL.new" "$TARBALL"
|
|
|
|
fi
|
|
|
|
|
2013-11-12 17:13:19 +01:00
|
|
|
# Check out a temporary full copy of the index to generate static files
|
2015-09-26 03:47:30 +02:00
|
|
|
git checkout-index -f -a --prefix "$TMP_CHECKOUT"
|
|
|
|
cd "$TMP_CHECKOUT"
|
2013-11-01 20:54:41 +01:00
|
|
|
|
2016-07-09 09:08:41 +02:00
|
|
|
# create var/log directory in the new temporary checkout
|
|
|
|
mkdir -p "var/log"
|
|
|
|
|
2015-08-21 01:27:35 +02:00
|
|
|
# Some settings need to be updated for update-prod-static to work
|
|
|
|
#
|
|
|
|
# TODO: Would be much better to instead run the below tools with some
|
2015-08-21 11:24:18 +02:00
|
|
|
# sort of environment hack to make settings.VOYAGER=True so that we
|
2015-08-21 01:27:35 +02:00
|
|
|
# don't need to create this dummy secrets file.
|
2016-07-20 05:45:50 +02:00
|
|
|
cat >> zproject/prod_settings_template.py <<EOF
|
2013-11-12 20:37:23 +01:00
|
|
|
DEBUG = False
|
2015-08-21 01:27:35 +02:00
|
|
|
EOF
|
|
|
|
cat >> zproject/dev-secrets.conf <<EOF
|
|
|
|
[secrets]
|
|
|
|
local_database_password = ''
|
|
|
|
secret_key = 'not_used_here'
|
|
|
|
shared_secret = 'not_used_here'
|
|
|
|
avatar_salt = 'not_used_here'
|
|
|
|
rabbitmq_password = 'not_used_here'
|
|
|
|
initial_password_salt = 'not_used_here'
|
2013-11-12 20:37:23 +01:00
|
|
|
EOF
|
|
|
|
|
2013-11-01 20:54:41 +01:00
|
|
|
# update-prod-static generates the prod-static directory.
|
|
|
|
# See COLLECTSTATIC in settings.py
|
2015-09-21 00:09:51 +02:00
|
|
|
set +x
|
2016-08-23 01:35:46 +02:00
|
|
|
# We do a bit of gymnastics to have update-prod-static.log be easily
|
|
|
|
# visible to the user and end up in the same directory as the final
|
|
|
|
# release tarball.
|
|
|
|
USER_PROD_STATIC_LOGPATH="${TMPDIR}/update-prod-static.log"
|
|
|
|
BUILD_PROD_STATIC_LOGPATH="${TMP_CHECKOUT}/var/log/update-prod-static.log"
|
|
|
|
ln -nfs "$BUILD_PROD_STATIC_LOGPATH" "$USER_PROD_STATIC_LOGPATH"
|
2016-08-23 01:38:23 +02:00
|
|
|
echo; echo -e "\033[33mRunning update-prod-static; check ${TMPDIR}/update-prod-static.log if it fails\033[0m"; echo
|
2015-09-21 00:09:51 +02:00
|
|
|
set -x
|
|
|
|
|
2013-11-01 20:54:41 +01:00
|
|
|
./tools/update-prod-static
|
2015-09-26 03:47:30 +02:00
|
|
|
echo "$GITID" > build_id
|
|
|
|
echo "$version" > version
|
2016-08-23 01:35:46 +02:00
|
|
|
rm -f "$USER_PROD_STATIC_LOGPATH"
|
|
|
|
mv "$BUILD_PROD_STATIC_LOGPATH" "$USER_PROD_STATIC_LOGPATH"
|
2013-11-01 20:54:41 +01:00
|
|
|
|
2015-08-21 01:27:35 +02:00
|
|
|
rm -f zproject/dev-secrets.conf
|
|
|
|
|
2013-11-14 16:36:29 +01:00
|
|
|
# We don't need duplicate copies of emoji with hashed paths, and they would break bugdown
|
|
|
|
find prod-static/serve/third/gemoji/images/emoji/ -regex '.*\.[0-9a-f]+\.png' -delete
|
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
cd "$TMPDIR"
|
2013-11-12 17:13:19 +01:00
|
|
|
|
2016-07-14 12:00:26 +02:00
|
|
|
tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version"
|
2013-11-01 20:54:41 +01:00
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
rm -rf "$prefix"
|
2013-11-12 17:13:19 +01:00
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
gzip "$TARBALL"
|
2013-11-12 17:13:19 +01:00
|
|
|
echo "Generated $TARBALL.gz"
|