2016-02-03 18:52:24 +00:00
|
|
|
readonly B9_PACKAGE_GIT_CACHE=$C9_DIR
|
|
|
|
|
|
|
|
b9_package_usage() {
|
|
|
|
echo "Usage: $B9 package TREEISH [ARG...]"
|
|
|
|
echo
|
|
|
|
echo "Package and upload a version of Cloud 9"
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo " --type=[newclient|docker] (default: newclient)"
|
|
|
|
echo " --no-cache"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
b9_package() {
|
|
|
|
[ "$1" == "--help" ] && b9_package_usage
|
|
|
|
|
|
|
|
local TREEISH=$1
|
|
|
|
local TYPE=newclient
|
2016-02-08 09:40:27 +00:00
|
|
|
local SETTINGS=$MODE
|
2016-02-03 18:52:24 +00:00
|
|
|
local STORAGE=gcs
|
|
|
|
local USE_CACHE=1
|
|
|
|
|
|
|
|
[ -z "$TREEISH" ] && b9_package_usage
|
2016-02-22 03:22:43 +00:00
|
|
|
[[ $TREEISH =~ -- ]] && b9_package_usage
|
2016-02-03 18:52:24 +00:00
|
|
|
shift
|
|
|
|
|
|
|
|
local ARG
|
|
|
|
for ARG in "$@"; do
|
|
|
|
case $ARG in
|
|
|
|
--type=*)
|
|
|
|
TYPE="${ARG#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--docker)
|
|
|
|
STORAGE=docker
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-cache)
|
|
|
|
USE_CACHE=0
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
b9_package_usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
local VERSION
|
|
|
|
local WORKDIR
|
|
|
|
|
|
|
|
[ "$TYPE" == "newclient" ] && SETTINGS=all
|
2016-02-08 09:40:27 +00:00
|
|
|
|
2016-02-03 18:52:24 +00:00
|
|
|
_b9_package_init_git_cache
|
|
|
|
|
2016-02-04 13:56:06 +00:00
|
|
|
VERSION=$(_b9_get_version $TREEISH $TYPE $SETTINGS)
|
2016-02-03 18:52:24 +00:00
|
|
|
|
|
|
|
if [ "$USE_CACHE" == "1" ] && _b9_package_is_cached $STORAGE $VERSION; then
|
|
|
|
echo $VERSION
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
WORKDIR=$(_b9_package_init_work_dir $VERSION)
|
|
|
|
_b9_package_sync_workdir $TYPE $WORKDIR $VERSION $SETTINGS
|
|
|
|
_b9_package_npm_install $WORKDIR
|
|
|
|
_b9_package_cleanup_workdir $WORKDIR
|
|
|
|
_b9_package_upload $STORAGE $WORKDIR $VERSION
|
2016-02-03 18:52:24 +00:00
|
|
|
|
|
|
|
echo $VERSION
|
|
|
|
}
|
|
|
|
|
|
|
|
_b9_package_init_git_cache() {
|
|
|
|
pushd $B9_PACKAGE_GIT_CACHE &> /dev/null
|
|
|
|
|
|
|
|
if [ ! -d .git ]; then
|
|
|
|
git clone git@github.com:c9/newclient.git .
|
|
|
|
fi
|
|
|
|
|
|
|
|
git fetch origin
|
|
|
|
|
|
|
|
popd &> /dev/null
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_init_work_dir() {
|
2016-02-03 18:52:24 +00:00
|
|
|
local VERSION=$1
|
2016-02-08 14:03:07 +00:00
|
|
|
mktemp -d b9-package-${VERSION}-XXXXXXXXXXXXX --tmpdir=$TMP
|
2016-02-03 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_b9_get_version() {
|
|
|
|
local TREEISH=$1
|
2016-02-04 13:56:06 +00:00
|
|
|
local TYPE=${2:-newclient}
|
|
|
|
local SETTINGS=${3:-all}
|
2016-02-03 18:52:24 +00:00
|
|
|
|
|
|
|
pushd $B9_PACKAGE_GIT_CACHE &> /dev/null
|
2016-02-04 13:56:06 +00:00
|
|
|
echo c9-${TYPE}-${SETTINGS}-$(git show $TREEISH:package.json | jq -r .version)-$(git rev-parse --short=8 $TREEISH)
|
2016-02-03 18:52:24 +00:00
|
|
|
popd &> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
_b9_package_is_cached() {
|
|
|
|
local STORAGE=$1
|
|
|
|
local VERSION=$2
|
|
|
|
|
2016-02-08 14:03:07 +00:00
|
|
|
if [ -d $TMP/$VERSION ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-02-03 18:52:24 +00:00
|
|
|
case $STORAGE in
|
|
|
|
gcs)
|
|
|
|
_b9_package_is_cached_gcs $VERSION
|
|
|
|
;;
|
|
|
|
docker)
|
|
|
|
_b9_package_is_cached_docker $VERSION
|
|
|
|
;;
|
|
|
|
*)
|
2016-02-08 14:03:07 +00:00
|
|
|
echo "Invalid storage type: $STORAGE" 1>&2
|
2016-02-03 18:52:24 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_upload() {
|
2016-02-03 18:52:24 +00:00
|
|
|
local STORAGE=$1
|
2016-02-08 14:03:07 +00:00
|
|
|
local WORKDIR=$2
|
|
|
|
local VERSION=$3
|
2016-02-03 18:52:24 +00:00
|
|
|
|
|
|
|
case $STORAGE in
|
|
|
|
gcs)
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_upload_gcs $WORKDIR $VERSION
|
2016-02-03 18:52:24 +00:00
|
|
|
;;
|
|
|
|
docker)
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_upload_docker $WORKDIR $VERSION
|
2016-02-03 18:52:24 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2016-02-08 14:03:07 +00:00
|
|
|
|
|
|
|
mv $WORKDIR $TMP/$VERSION
|
2016-02-03 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_sync_workdir() {
|
2016-02-03 18:52:24 +00:00
|
|
|
local TYPE=$1
|
|
|
|
local WORKDIR=$2
|
|
|
|
local VERSION=$3
|
|
|
|
local SETTINGS=$4
|
|
|
|
|
|
|
|
case $TYPE in
|
|
|
|
newclient)
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_sync_workdir_newclient $WORKDIR $VERSION $SETTINGS
|
2016-02-03 18:52:24 +00:00
|
|
|
;;
|
|
|
|
docker)
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_sync_workdir_docker $WORKDIR $VERSION $SETTINGS
|
2016-02-03 18:52:24 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_npm_install() {
|
2016-02-03 18:52:24 +00:00
|
|
|
local WORKDIR=$1
|
|
|
|
|
|
|
|
pushd $WORKDIR &> /dev/null
|
|
|
|
_b9_install_deps
|
|
|
|
popd &> /dev/null
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_cleanup_workdir() {
|
2016-02-03 18:52:24 +00:00
|
|
|
local WORKDIR=$1
|
|
|
|
local REVISION
|
|
|
|
[ -z "$WORKDIR" ] && return 1
|
|
|
|
|
|
|
|
pushd $WORKDIR &> /dev/null
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_patch_package_json
|
2016-02-03 18:52:24 +00:00
|
|
|
rm -rf .git build bin local
|
|
|
|
|
|
|
|
popd &> /dev/null
|
|
|
|
}
|
|
|
|
|
2016-02-23 06:30:37 +00:00
|
|
|
_b9_package_patch_package_json() {
|
2016-02-03 18:52:24 +00:00
|
|
|
[ ! -d .git ] && return 0
|
|
|
|
|
|
|
|
REVISION=$(git rev-parse HEAD)
|
|
|
|
mv package.json _package.json
|
|
|
|
cat _package.json | jq ".revision=\"$REVISION\"" > package.json
|
|
|
|
rm _package.json
|
|
|
|
}
|
|
|
|
|
|
|
|
_do_check_package() {
|
2016-02-08 09:40:27 +00:00
|
|
|
MODE=devel
|
2016-02-03 18:52:24 +00:00
|
|
|
b9_package origin/master --type=newclient --no-cache
|
|
|
|
b9_package origin/master --type=newclient
|
2016-02-08 09:40:27 +00:00
|
|
|
|
|
|
|
MODE=deploy
|
|
|
|
b9_package origin/master --type=docker --no-cache
|
|
|
|
|
|
|
|
MODE=devel
|
2016-02-03 18:52:24 +00:00
|
|
|
b9_package origin/master --docker --no-cache
|
2016-02-22 03:22:43 +00:00
|
|
|
}
|