fixed pip install to 20.3.4 bc latest one (21.0.0) breaks python build Change-Id: I0266509ad07d0d28c509b446f40cabc7ca7ab8ef Signed-off-by: smarcet <smarcet@gmail.com>
		
			
				
	
	
		
			294 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			294 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
function print_help {
 | 
						|
    echo "Usage: `basename $0` command [options]"
 | 
						|
    echo ""
 | 
						|
    echo "Commands:"
 | 
						|
    echo "  status [site]    return status information about site configurations"
 | 
						|
    echo "  init <site>      initialize site structure"
 | 
						|
    echo "  update <site>    update to new version"
 | 
						|
    echo ""
 | 
						|
}
 | 
						|
 | 
						|
function clear_redis_cache {
 | 
						|
    echo "running redis FLUSHDB ..."
 | 
						|
    echo "FLUSHDB" | redis-cli -h 127.0.0.1 -p $REDIS_PORT -a "$REDIS_PASSWORD"
 | 
						|
    echo "running redis FLUSHALL ..."
 | 
						|
    echo "FLUSHALL" | redis-cli -h 127.0.0.1 -p $REDIS_PORT -a "$REDIS_PASSWORD"
 | 
						|
}
 | 
						|
 | 
						|
function clear_orm_cache {
 | 
						|
    echo "clearing doctrine metadata"
 | 
						|
    php artisan doctrine:clear:metadata:cache
 | 
						|
    echo "clearing doctrine query cache"
 | 
						|
    php artisan doctrine:clear:query:cache
 | 
						|
    echo "clearing doctrine result cache"
 | 
						|
    php artisan doctrine:clear:result:cache
 | 
						|
    echo "generating doctrine proxies"
 | 
						|
    php artisan doctrine:generate:proxies
 | 
						|
}
 | 
						|
 | 
						|
function clear_laravel_cache {
 | 
						|
    php artisan route:clear
 | 
						|
    php artisan route:cache
 | 
						|
    php artisan config:cache
 | 
						|
    php artisan view:clear
 | 
						|
    php artisan view:cache
 | 
						|
}
 | 
						|
 | 
						|
function check_laravel_storage_structure {
 | 
						|
    # check for new storage structure ( LV 5.x)
 | 
						|
    if [[ ! -d $SITE_ROOT/storage/framework ]]; then
 | 
						|
        mkdir -p $SITE_ROOT/storage/framework
 | 
						|
        mkdir -p $SITE_ROOT/storage/framework/cache
 | 
						|
        mkdir -p $SITE_ROOT/storage/framework/views
 | 
						|
        mkdir -p $SITE_ROOT/storage/framework/sessions
 | 
						|
    fi
 | 
						|
    if [[ ! -d $SITE_ROOT/storage/app ]]; then
 | 
						|
        mkdir -p $SITE_ROOT/storage/app
 | 
						|
        mkdir -p $SITE_ROOT/storage/app/public
 | 
						|
    fi
 | 
						|
    if [[ ! -d $SITE_ROOT/storage/logs ]]; then
 | 
						|
        mkdir -p $SITE_ROOT/storage/logs
 | 
						|
    fi
 | 
						|
}
 | 
						|
 | 
						|
function set_laravel_storage_permissions {
 | 
						|
    chown -R $FILE_OWNER:$FILE_GROUP $SITE_ROOT/storage
 | 
						|
    chmod 02770 $SITE_ROOT/storage;
 | 
						|
    find $SITE_ROOT/storage/ -type d -exec chmod 0775 {} \;
 | 
						|
    find $SITE_ROOT/storage/ -type f -exec chmod 0664 {} \;
 | 
						|
    # set html purifier cache permission
 | 
						|
    chmod 0770 vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer
 | 
						|
}
 | 
						|
 | 
						|
function set_python_venv {
 | 
						|
    chmod 0775 $target_dir/app/Console/Commands/SpammerProcess
 | 
						|
    chown :www-data $target_dir/app/Console/Commands/SpammerProcess
 | 
						|
    cd $target_dir/app/Console/Commands/SpammerProcess
 | 
						|
    python3 -m venv env
 | 
						|
    source env/bin/activate
 | 
						|
    pip install  "pip==20.3.4"
 | 
						|
    pip install --upgrade setuptools
 | 
						|
    pip install wheel
 | 
						|
    pip install -r requirements.txt
 | 
						|
    deactivate
 | 
						|
    cd $target_dir
 | 
						|
}
 | 
						|
 | 
						|
function site_init {
 | 
						|
    if [ ! $1 ]; then
 | 
						|
        echo "ERROR: site parameter mandatory"
 | 
						|
        exit 1
 | 
						|
    fi
 | 
						|
    CONF_PATH="$CONF_DIR/conf.d/$1.conf"
 | 
						|
    if [ ! -f $CONF_PATH ]; then
 | 
						|
        echo "Site configuration not found: " $1
 | 
						|
        exit 1
 | 
						|
    fi
 | 
						|
    source $CONF_PATH
 | 
						|
    if [ -f "$SITE_ROOT/w/public/index.php" ]; then
 | 
						|
        echo "Cannot override an existing deployment: $SITE_ROOT/w"
 | 
						|
        exit 1
 | 
						|
    fi
 | 
						|
    # cleanup previous broken deployment
 | 
						|
    rm -rf $SITE_ROOT/slot0
 | 
						|
    # create directory structure
 | 
						|
    for dir in slot0 slot1; do
 | 
						|
        mkdir -p $SITE_ROOT/$dir
 | 
						|
        chown $FILE_OWNER:$FILE_GROUP $SITE_ROOT/$dir
 | 
						|
    done
 | 
						|
    target_dir="$SITE_ROOT/slot0"
 | 
						|
    # fetch catalog and write actual version
 | 
						|
    fetch_catalog
 | 
						|
    RELEASE_VERSION=`catalog_get_version`
 | 
						|
    echo $RELEASE_VERSION > $SITE_ROOT/slot0/release
 | 
						|
    # fetch and extract release tarball
 | 
						|
    umask 0027
 | 
						|
    if [[ $SOURCE_TARBALL == http* ]]; then
 | 
						|
        echo "Download from http!"
 | 
						|
        curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions
 | 
						|
    else
 | 
						|
        echo "extract from local file system"
 | 
						|
        if [ ! -f $SOURCE_TARBALL ]; then
 | 
						|
            echo "Source tarball not found: $SOURCE_TARBALL"
 | 
						|
            exit 1
 | 
						|
        fi
 | 
						|
        tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions
 | 
						|
    fi
 | 
						|
    chown -R $FILE_OWNER:$FILE_GROUP $target_dir
 | 
						|
    umask 0022
 | 
						|
    # link configuration files managed by puppet
 | 
						|
 | 
						|
    ln -sf /etc/openstackid/.env $target_dir/.env
 | 
						|
 | 
						|
    # convert app/storage into symlink and set permissions
 | 
						|
    mv $target_dir/storage $SITE_ROOT/
 | 
						|
 | 
						|
    # link shared app/storage directory
 | 
						|
    rm -rf $target_dir/storage
 | 
						|
    ln -s $SITE_ROOT/storage $target_dir
 | 
						|
    check_laravel_storage_structure
 | 
						|
 | 
						|
    # set artisan execution permissions
 | 
						|
    cd $target_dir && chmod 0770 artisan
 | 
						|
 | 
						|
    clear_redis_cache
 | 
						|
 | 
						|
    clear_orm_cache
 | 
						|
 | 
						|
    clear_laravel_cache
 | 
						|
 | 
						|
    echo "running db migrations";
 | 
						|
    php artisan doctrine:migrations:migrate --connection=model --force --env=$LARAVEL_ENV
 | 
						|
 | 
						|
    if [[ $USE_DB_SEEDING -eq 1 ]]; then
 | 
						|
        php artisan db:seed --env=$LARAVEL_ENV --force
 | 
						|
    fi
 | 
						|
 | 
						|
    sudo npm install
 | 
						|
    sudo npm run build
 | 
						|
 | 
						|
    set_laravel_storage_permissions
 | 
						|
 | 
						|
    set_python_venv
 | 
						|
 | 
						|
    # activate site
 | 
						|
    rm -rf $SITE_ROOT/w
 | 
						|
    ln -s $SITE_ROOT/slot0 $SITE_ROOT/w
 | 
						|
 | 
						|
    echo "Restarting laravel queue worker ..."
 | 
						|
    php artisan queue:restart
 | 
						|
 | 
						|
    echo "supervisorctl reload"
 | 
						|
    supervisorctl reload
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
function site_status {
 | 
						|
    if [ ! $1 ]; then
 | 
						|
        echo "ERROR: site parameter mandatory"
 | 
						|
        exit 1
 | 
						|
    fi
 | 
						|
    CONF_PATH="$CONF_DIR/conf.d/$1.conf"
 | 
						|
    if [ ! -f $CONF_PATH ]; then
 | 
						|
        echo "Site configuration not found: $1"
 | 
						|
        exit 0
 | 
						|
    fi
 | 
						|
    source $CONF_PATH
 | 
						|
    if [ ! -f "$SITE_ROOT/w/public/index.php" ]; then
 | 
						|
        if [ -d "$SITE_ROOT/slot0" ]; then
 | 
						|
            echo "PENDING"
 | 
						|
        else
 | 
						|
            echo "N/A"
 | 
						|
            exit 1
 | 
						|
        fi
 | 
						|
    else
 | 
						|
        fetch_catalog
 | 
						|
        REMOTE_VERSION=`catalog_get_version`
 | 
						|
        RELEASE_VERSION=$(head -n 1 $SITE_ROOT/w/release)
 | 
						|
        if [ "$REMOTE_VERSION" == "$RELEASE_VERSION" ]; then
 | 
						|
            echo "INSTALLED [$RELEASE_VERSION]"
 | 
						|
        else
 | 
						|
            echo "UPDATE AVAILABLE [$RELEASE_VERSION-$REMOTE_VERSION]"
 | 
						|
        fi
 | 
						|
    fi
 | 
						|
}
 | 
						|
 | 
						|
function fetch_catalog {
 | 
						|
    curl --silent $SOURCE_ROOT > $SITE_ROOT/releases.lst
 | 
						|
    grep -q "^<!DOCTYPE HTML PUBLIC" $SITE_ROOT/releases.lst
 | 
						|
}
 | 
						|
 | 
						|
function catalog_get_version {
 | 
						|
    RAW_LINE=`cat $SITE_ROOT/releases.lst | grep "$RELEASE_NAME" | sed "s/<[^>]\+>//g" | sed -r "s/^$RELEASE_NAME//"`
 | 
						|
    RELEASE_DATE=`echo $RAW_LINE | awk '{ print $1 " " $2}'`
 | 
						|
    echo $RELEASE_DATE
 | 
						|
}
 | 
						|
 | 
						|
function site_update {
 | 
						|
    if [ ! $1 ]; then
 | 
						|
        echo "ERROR: missing site parameter"
 | 
						|
        exit 1
 | 
						|
    fi
 | 
						|
    CONF_PATH="$CONF_DIR/conf.d/$1.conf"
 | 
						|
    if [ ! -f $CONF_PATH ]; then
 | 
						|
        echo "Site configuration not found: $1"
 | 
						|
        exit 0
 | 
						|
    fi
 | 
						|
    source $CONF_PATH
 | 
						|
    SITE_LINK=`readlink -f $SITE_ROOT/w`
 | 
						|
    ACTIVE_SLOT=`basename $SITE_LINK`
 | 
						|
    case $ACTIVE_SLOT in
 | 
						|
        slot0)
 | 
						|
            TARGET_SLOT='slot1'
 | 
						|
            ;;
 | 
						|
        slot1)
 | 
						|
            TARGET_SLOT='slot0'
 | 
						|
            ;;
 | 
						|
        *)
 | 
						|
            echo "Invalid active slot"
 | 
						|
            exit 1
 | 
						|
    esac
 | 
						|
    echo "Target slot: $TARGET_SLOT"
 | 
						|
    target_dir="$SITE_ROOT/$TARGET_SLOT"
 | 
						|
    rm -rf $target_dir
 | 
						|
    mkdir $target_dir
 | 
						|
    # fetch catalog and write actual version
 | 
						|
    fetch_catalog
 | 
						|
    RELEASE_VERSION=`catalog_get_version`
 | 
						|
    echo $RELEASE_VERSION > $target_dir/release
 | 
						|
    # fetch and extract release tarball
 | 
						|
    umask 0027
 | 
						|
    if [[ $SOURCE_TARBALL == http* ]]; then
 | 
						|
        echo "Download from http!"
 | 
						|
        curl $SOURCE_TARBALL | tar -xzv -C $target_dir --strip-components 1 --no-same-permissions
 | 
						|
    else
 | 
						|
        echo "extract from local file system"
 | 
						|
        if [ ! -f $SOURCE_TARBALL ]; then
 | 
						|
            echo "Source tarball not found: $SOURCE_TARBALL"
 | 
						|
            exit 1
 | 
						|
        fi
 | 
						|
        tar -xzvf $SOURCE_TARBALL -C $target_dir --strip-components 1 --no-same-permissions
 | 
						|
    fi
 | 
						|
 | 
						|
    chown -R $FILE_OWNER:$FILE_GROUP $target_dir
 | 
						|
    umask 0022
 | 
						|
 | 
						|
    # link configuration files managed by puppet
 | 
						|
    ln -sf /etc/openstackid/.env $target_dir/.env
 | 
						|
    # link shared app/storage directory
 | 
						|
    rm -rf $target_dir/storage
 | 
						|
    ln -s $SITE_ROOT/storage $target_dir
 | 
						|
    check_laravel_storage_structure
 | 
						|
    # set artisan exec permissions
 | 
						|
    cd $target_dir
 | 
						|
    chmod 0770 artisan
 | 
						|
 | 
						|
    clear_redis_cache
 | 
						|
 | 
						|
    clear_orm_cache
 | 
						|
 | 
						|
    clear_laravel_cache
 | 
						|
 | 
						|
    echo "running db migrations"
 | 
						|
    php artisan doctrine:migrations:migrate --connection=model --force --env=$LARAVEL_ENV
 | 
						|
 | 
						|
    sudo npm install
 | 
						|
    sudo npm run build
 | 
						|
 | 
						|
    set_laravel_storage_permissions
 | 
						|
 | 
						|
    set_python_venv
 | 
						|
 | 
						|
    # activate site
 | 
						|
    rm -rf $SITE_ROOT/w
 | 
						|
    ln -s $target_dir $SITE_ROOT/w
 | 
						|
    # to reset op cache
 | 
						|
    /usr/sbin/service $PHP_SERVICE_NAME restart
 | 
						|
 | 
						|
    echo "Restarting laravel queue worker ..."
 | 
						|
    php artisan queue:restart
 | 
						|
 | 
						|
    echo "supervisorctl reload"
 | 
						|
    supervisorctl reload
 | 
						|
}
 |