2017-04-10 14:24:53 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -ex
|
2020-01-21 14:36:12 +00:00
|
|
|
|
2017-04-10 14:24:53 +00:00
|
|
|
BASE_DIR=$(dirname $(readlink -f $0))
|
2019-03-26 09:50:28 +00:00
|
|
|
BUILD_DIR="${BASE_DIR}/../build"
|
2020-01-28 18:51:44 +00:00
|
|
|
PUBLISH_DIR="${BASE_DIR}/../publish"
|
2020-03-15 10:53:00 +00:00
|
|
|
BASE_DOMAIN="${BASE_DOMAIN:-clickhouse.tech}"
|
2020-02-21 20:24:31 +00:00
|
|
|
GIT_TEST_URI="${GIT_TEST_URI:-git@github.com:ClickHouse/clickhouse.github.io.git}"
|
2020-01-29 14:56:52 +00:00
|
|
|
GIT_PROD_URI="git@github.com:ClickHouse/clickhouse.github.io.git"
|
2020-03-30 08:25:29 +00:00
|
|
|
EXTRA_BUILD_ARGS="${EXTRA_BUILD_ARGS:---enable-stable-releases --minify}"
|
|
|
|
HISTORY_SIZE="${HISTORY_SIZE:-5}"
|
2020-01-29 14:56:52 +00:00
|
|
|
|
2017-04-10 14:24:53 +00:00
|
|
|
if [[ -z "$1" ]]
|
|
|
|
then
|
|
|
|
TAG=$(head -c 8 /dev/urandom | xxd -p)
|
|
|
|
else
|
|
|
|
TAG="$1"
|
|
|
|
fi
|
2017-05-30 14:21:04 +00:00
|
|
|
DOCKER_HASH="$2"
|
2017-04-10 14:24:53 +00:00
|
|
|
if [[ -z "$1" ]]
|
|
|
|
then
|
2019-03-26 09:50:28 +00:00
|
|
|
source "${BASE_DIR}/venv/bin/activate"
|
2020-03-21 04:56:32 +00:00
|
|
|
python3 "${BASE_DIR}/build.py" ${EXTRA_BUILD_ARGS}
|
2020-01-28 18:51:44 +00:00
|
|
|
rm -rf "${PUBLISH_DIR}" || true
|
2020-01-29 14:56:52 +00:00
|
|
|
git clone "${GIT_TEST_URI}" "${PUBLISH_DIR}"
|
2020-01-28 18:51:44 +00:00
|
|
|
cd "${PUBLISH_DIR}"
|
2020-01-29 13:36:13 +00:00
|
|
|
git config user.email "robot-clickhouse@yandex-team.ru"
|
|
|
|
git config user.name "robot-clickhouse"
|
2020-01-28 18:51:44 +00:00
|
|
|
git rm -rf *
|
|
|
|
cp -R "${BUILD_DIR}"/* .
|
2020-03-15 10:53:00 +00:00
|
|
|
echo -n "${BASE_DOMAIN}" > CNAME
|
2020-01-28 19:47:58 +00:00
|
|
|
echo -n "" > README.md
|
2020-02-03 10:00:49 +00:00
|
|
|
echo -n "" > ".nojekyll"
|
2020-01-28 19:31:35 +00:00
|
|
|
cp "${BASE_DIR}/../../LICENSE" .
|
2020-01-28 18:51:44 +00:00
|
|
|
git add *
|
2020-02-03 10:00:49 +00:00
|
|
|
git add ".nojekyll"
|
2020-01-28 18:51:44 +00:00
|
|
|
git commit -a -m "add new release at $(date)"
|
2020-03-13 19:35:03 +00:00
|
|
|
NEW_ROOT_COMMIT=$(git rev-parse "HEAD~${HISTORY_SIZE}")
|
|
|
|
git checkout --orphan temp "${NEW_ROOT_COMMIT}"
|
|
|
|
git commit -m "root commit"
|
|
|
|
git rebase --onto temp "${NEW_ROOT_COMMIT}" master
|
|
|
|
git branch -D temp
|
|
|
|
git push -f origin master
|
|
|
|
if [[ ! -z "${CLOUDFLARE_TOKEN}" ]]
|
|
|
|
then
|
|
|
|
sleep 1m
|
2020-03-18 13:02:32 +00:00
|
|
|
git diff --stat="9999,9999" --diff-filter=M HEAD~1 | grep '|' | awk '$1 ~ /\.html$/ { if ($3>4) { url="https://'${BASE_DOMAIN}'/"$1; sub(/\/index.html/, "/", url); print "\""url"\""; }}' | split -l 25 /dev/stdin PURGE
|
2020-03-15 10:53:00 +00:00
|
|
|
for FILENAME in $(ls PURGE*)
|
|
|
|
do
|
|
|
|
POST_DATA=$(cat "${FILENAME}" | sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' | awk '{print "{\"files\":["$0"]}";}')
|
|
|
|
sleep 3s
|
|
|
|
set +x
|
|
|
|
curl -X POST "https://api.cloudflare.com/client/v4/zones/4fc6fb1d46e87851605aa7fa69ca6fe0/purge_cache" -H "Authorization: Bearer ${CLOUDFLARE_TOKEN}" -H "Content-Type:application/json" --data "${POST_DATA}"
|
|
|
|
set -x
|
|
|
|
rm "${FILENAME}"
|
|
|
|
done
|
2020-03-13 19:35:03 +00:00
|
|
|
fi
|
2019-03-26 09:50:28 +00:00
|
|
|
cd "${BUILD_DIR}"
|
2020-02-14 10:28:19 +00:00
|
|
|
DOCKER_HASH=$(head -c 16 < /dev/urandom | xxd -p)
|
2017-04-10 14:24:53 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
QLOUD_ENDPOINT="https://platform.yandex-team.ru/api/v1"
|
|
|
|
QLOUD_PROJECT="clickhouse.clickhouse-website"
|
|
|
|
if [[ -z "$1" ]]
|
|
|
|
then
|
|
|
|
QLOUD_ENV="${QLOUD_PROJECT}.test"
|
|
|
|
else
|
|
|
|
QLOUD_ENV="${QLOUD_PROJECT}.prod"
|
|
|
|
fi
|
2017-05-30 14:21:04 +00:00
|
|
|
echo ">>> Successfully deployed ${TAG} ${DOCKER_HASH} to ${QLOUD_ENV} <<<"
|